In Oracle SQL: how do you insert the current date + time into a table?

I wrote the code below, but it seems that it inserts the current date, not the current time. Does anyone know how to do this?

insert into errortable (dateupdated,table1id) values (TO_DATE(sysdate, 'dd/mm/yyyy hh24:mi:ss'),1083); 
+6
source share
2 answers

It only seems because it is what it prints. But in fact, you should not write logic this way. This is equivalent to:

 insert into errortable (dateupdated, table1id) values (sysdate, 1083); 

It seems silly to convert a system date to a string to convert it back to a date.

If you want to see the full date, you can do:

 select TO_CHAR(dateupdated, 'YYYY-MM-DD HH24:MI:SS'), table1id from errortable; 
+8
source

You can try the following query:

 INSERT INTO errortable (dateupdated,table1id) VALUES (to_date(to_char(sysdate,'dd/mon/yyyy hh24:mi:ss'), 'dd/mm/yyyy hh24:mi:ss' ),1083 ); 

To view its result:

 SELECT to_char(hire_dateupdated, 'dd/mm/yyyy hh24:mi:ss') FROM errortable WHERE table1id = 1083; 
-3
source

All Articles