Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: How to update a column to its default value?

Re: How to update a column to its default value?

From: Daniel Morgan <damorgan_at_exxesolutions.com>
Date: Mon, 28 Apr 2003 16:47:11 -0700
Message-ID: <3EADBD7F.C9E48611@exxesolutions.com>


Daniel Morgan wrote:

> kielhd wrote:
>
> > Hi,
> > I am looking into this problem for a while without solving it.
> > HELP!!!!!!!!!!
> >
> > The following table is defined:
> >
> > CREATE TABLE DEFAULT_TABLE(
> > TEXT varchar2(32),
> > LAST_UPDATE date default sysdate
> > );
> >
> > After setting an initial value to the column TEXT with the command
> >
> > insert into DEFAULT_TABLE ( TEXT ) values ( 'John' )
> >
> > the table looks like:
> >
> > select text, to_char(last_update, 'dd-mon-yyyy hh24:mi:ss') from
> > DEFAULT_TABLE
> >
> > TEXT TO_CHAR(LAST_UPDATE,
> > -------------------------------- --------------------
> > John 28-apr-2003 15:53:01
> >
> > Here is my Problem:
> > -------------------
> > I need to update the row, where the column TEXT equals the value
> > 'John' to the value 'George'. I expect the value in the column
> > LAST_UPDATE to change automatically to the current value of SYSDATE.
> >
> > Here is what I did:
> >
> > update DEFAULT_TABLE set TEXT = 'George' where TEXT = 'John';
> >
> > Afterwards, the table looks like this:
> >
> > select text, to_char(last_update, 'dd-mon-yyyy hh24:mi:ss') from
> > DEFAULT_TABLE;
> >
> > TEXT TO_CHAR(LAST_UPDATE,
> > -------------------------------- --------------------
> > George 28-apr-2003 15:53:01
> >
> > The value of the column TEXT has changed as expected, but the value of
> > LAST_UPDATE remained the same.
> > I want the value of the column LAST_UPDATE to change when I update the
> > column TEXT.
> >
> > Hope there is some help to this problem!
> >
> > Regards from rainy Germany
> > Henning
>
> CREATE OR REPLACE TRIGGER bi_<table_name>
> BEFORE INSERT
> ON <table_name>
> FOR EACH ROW
>
> DECLARE
>
> BEGIN
> :NEW.last_update := SYSDATE;
>
> END bi_<table_name>;
> /
>
> --
> Daniel Morgan
> http://www.outreach.washington.edu/extinfo/certprog/oad/oad_crs.asp
> (remove one 'x' from my email address to reply)

Oops. There I go copying in a rush ... trigger should have been changed to BEFORE UPDATE. Sorry.

--
Daniel Morgan
http://www.outreach.washington.edu/extinfo/certprog/oad/oad_crs.asp
(remove one 'x' from my email address to reply)
Received on Mon Apr 28 2003 - 18:47:11 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US