Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Format Timestamp

Tags:

sql

oracle

plsql

I have col1 in myTable which is varchar, and I have to insert here timestamp eg:- 09-MAY-11 10.23.12.0000 AM.

Now please tell me:

  • How to insert into myTable with taking sysdate in above format...
  • How to retrieve data from col1 in tha same timestamp format..
like image 274
Avi Avatar asked Feb 25 '23 06:02

Avi


1 Answers

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 the data directly as a timestamp. Then you can compare the values ​​or modify them directly.

create table myTable1( col1 timestamp default systimestamp);
like image 190
schurik Avatar answered Mar 08 '23 03:03

schurik