views:

74

answers:

1

Hi,

I have created a table in oracle XE, and I have a field with type date. I would like if possible when I insert a row, that it automatically fills that field with the current date from the system.

I am inserting the rows from the SQL prompt.

Thanks

+3  A: 

Here is how, you need to format your table properly:

create table test (first number
                   , second timestamp default systimestamp
                   , third varchar2(12));

And your default value is always current system time formatted as timestamp.

c0mrade
great answer. ty
Adnan
If the column has datatype of `timestamp` why not default to `systimestamp` rather than `sysdate`?
APC
what is the difference? I use sysdate, if you can explain that would be great for me as well for Andan who asked the question
c0mrade
date (which is what `sysdate` returns) is only accurate to the nearest second, timestamp (returned by `systimestamp`) has greater precision (e.g. 1000'th of a second or better)
Jeffrey Kemp