Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically populate date in oracle table

Tags:

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

like image 901
Adnan Avatar asked Jan 09 '10 10:01

Adnan


People also ask

What is the default value for TIMESTAMP in Oracle?

TIMESTAMP has a default of 0 unless defined with the NULL attribute, in which case the default is NULL .

How do I change date format from YYYY-MM-DD in Oracle?

Just use: select to_date(date_value, 'yyyy-mm-dd') as date_value from table; To convert to a date. That's it!

Why we use TO_DATE function in Oracle?

TO_DATE converts char of CHAR , VARCHAR2 , NCHAR , or NVARCHAR2 datatype to a value of DATE datatype. The fmt is a datetime model format specifying the format of char . If you omit fmt , then char must be in the default date format.


1 Answers

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.

like image 172
ant Avatar answered Sep 23 '22 02:09

ant