Re: SYSDATE for a default value
Date: Mon, 12 Jul 1999 15:27:17 -0500
Message-ID: <378A4FA5.B2D06655_at_ac.com>
You can use SYSDATE as a default column value as follows:
CREATE TABLE temp_table (col1 number, col2 data default sysdate);
Table created.
/* if you insert NULL, it won't assign the default value */ insert into temp_table values (1, null);
1 row created.
commit;
select * from temp_table;
COL1 COL2
--------- ---------
1
/* but if you don't put anything in that column... */ insert into temp_table (col1) values (2);
1 row created.
commit;
select * from temp_table;
COL1 COL2
--------- ---------
1 2 12-JUL-99
You can also add a default value for the column using:
alter table temp_table modify (col2 default sysdate);
David Rabsch wrote:
>
> Hi, I'm a newbie, so please excuse this if it's an elementary
> question.....
>
> I want to have the default value in a table be the current date and
> time, and found the function SYSDATE. Seems like the right thing to
> do. My question is, how do I put the result of SYSDATE into the field?
> What's the correct syntax? Do I use a trigger on the table, and if so,
> when? I've already got one trigger to automatically increase a value in
> an ID field by one every time a new field is inserted and it works
> great, but I tried to do the same thing with the SYSDATE function with
> no luck. I'm coming over from Access, so my sql (and esp. PL/SQL) is
> horrible. Thx for the help.
Received on Mon Jul 12 1999 - 22:27:17 CEST