Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I update column with type TIMESTAMP in Oracle via sql query?

I have column:

"LASTTOUCH" TIMESTAMP(9) NOT NULL ENABLE

and I must set current date to this column.

But I have no idea how I can do it.

Could you help me, please?

like image 908
user471011 Avatar asked Oct 04 '12 15:10

user471011


People also ask

How do I add a TIMESTAMP to a column 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);

Can we insert TIMESTAMP in date column in Oracle?

insert into table x1 select to_timestamp(activity_date,'mm/dd/yyyy hh24:MI:SS') as v_date from csct.


2 Answers

Insert:

insert into tablename (LASTTOUCH) values (CURRENT_TIMESTAMP);

Update:

update tablename set LASTTOUCH=CURRENT_TIMESTAMP;
like image 78
Koerr Avatar answered Oct 28 '22 04:10

Koerr


If you want the current time (including the timestamp precision), you could use either systimestamp or current_timestamp

SQL> select systimestamp from dual;

SYSTIMESTAMP
---------------------------------------------------------------------------
04-OCT-12 11.39.37.670428 AM -04:00

SQL> select CURRENT_TIMESTAMP from dual;

CURRENT_TIMESTAMP
---------------------------------------------------------------------------
04-OCT-12 11.39.51.021937 AM -04:00

update table_name set column_name = SYSTIMESTAMP where id = 100;

If you just set the value to sysdate, the fractional seconds part of the timestamp is zeroed out as the date is implicitly converted to timestamp.

SQL> create table t1(
  2     time1 timestamp
  3  );

Table created.

SQL> insert into t1 values (sysdate);

1 row created.

SQL> commit;

SQL> select to_char(time1,'MM/DD/YYYY HH24:MI:SS.FF6') result from t1;

RESULT
-----------------------------
10/04/2012 11:43:07.000000
like image 28
Rajesh Chamarthi Avatar answered Oct 28 '22 03:10

Rajesh Chamarthi