Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert a timestamp in Oracle?

Tags:

sql

oracle

I have an Oracle DB with a timestamp field in it. What is the correct SQL code to insert a timestamp into this field?

like image 353
Mike Rifgin Avatar asked Mar 24 '11 14:03

Mike Rifgin


People also ask

How do I add a TIMESTAMP in Oracle?

You can use the below code: insert into tablename (timestamp_value) values (TO_TIMESTAMP(:ts_val, 'YYYY-MM-DD HH24:MI:SS')); If you need the current timestamp to be inserted then use the following code: insert into tablename (timestamp_value) values (CURRENT_TIMESTAMP);

How do I insert a TIMESTAMP in SQL?

How do I add a TIMESTAMP to a MySQL table? Here is the SQL you can use to add the column in: ALTER TABLE `table1` ADD `lastUpdated` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ; This adds a column called 'lastUpdated' with a default value of the current date/time.

How does TIMESTAMP work in Oracle?

TIMESTAMP extends DATE by fractional seconds. Internally, time zone information is also contained, but in order to work with time zones, one of the other two data types, TIMESTAMP WITH TIME ZONE or TIMESTAMP WITH LOCAL TIME ZONE must be used.

How do I add a TIMESTAMP in SQL Developer?

From Oracle SQL Developer's menu go to: Tools > Preferences. From the Preferences dialog, select Database > NLS from the left panel. From the list of NLS parameters, enter DD-MON-RR HH24:MI:SS into the Date Format field. Save and close the dialog, done!


1 Answers

insert into tablename (timestamp_value) values (TO_TIMESTAMP(:ts_val, 'YYYY-MM-DD HH24:MI:SS')); 

if you want the current time stamp to be inserted then:

insert into tablename (timestamp_value) values (CURRENT_TIMESTAMP); 
like image 123
reggie Avatar answered Oct 08 '22 02:10

reggie