How to format a timestamp

I have col1in myTable, which is equal varchar, and I need to insert a timestamp here, for example: - 09-MAY-11 10.23.12.0000 AM.

Now tell me:

  • How to embed in myTable using sysdate in the above format ...
  • How to get data from col1 in the same timestamp format.
+3
source share
1 answer

INSERT:

insert into myTable (col1) VALUES (to_char(systimestamp, 'dd-mon-yyyy hh.mi.ss.ff4 AM') );

SELECT

select to_timestamp(col1, 'dd-mon-yyyy hh.mi.ss.ff4 AM')  from myTable ;

But it is much better to store data directly as a timestamp. Then you can compare the values ​​or change them directly.

create table myTable1( col1 timestamp default systimestamp);
+8
source

All Articles