Skip to Main Content
  • Questions
  • REGARDING TIMESTAMP ISSUE FOR DYNAMIC INSERT STATEMENTS

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, vinodha.

Asked: January 10, 2017 - 4:19 pm UTC

Last updated: January 11, 2017 - 2:00 am UTC

Version: 3.2.20.09

Viewed 1000+ times

You Asked

Hi,

I am new to oracle, i have used your create dynamic insert script for generating the insert script. But that query is taking care of only three datatypes like NUMBER, DATE and VARCHAR2(). It is not taking care about the TIMESTAMP data type since i need to check the TIMESTAMP dayta type as i am using that in my query. (I have tried the same DATE datatype script but i have changed only the date to timestamp and tested since it is not giving any error it is not giving output in timestamp). Please help me to solve the issue.

And also i did not understand CHR(39) which you used in the script.

please provide me a solution that should taking care of TIMESTAMP datatype.

and Connor said...

We have a lot of scripts :-) You need to let us know which script you are talking about. But a nice shorthand for timestamp is the format as below

select timestamp '2016-01-01 13:45:21.222' from dual;

so if you generate that string, you'll be good to go, eg

SQL> create table t ( ts timestamp );

Table created.

SQL> insert into t select systimestamp from dual;

1 row created.

SQL> insert into t select systimestamp from dual;

1 row created.

SQL> insert into t select systimestamp from dual;

1 row created.

SQL>
SQL>
SQL> select 'timestamp '||chr(39)||to_char(ts,'yyyy-mm-dd hh24:mi:ss.ff')||chr(39)
  2  from t;

'TIMESTAMP'||CHR(39)||TO_CHAR(TS,'YYYY-MM
-----------------------------------------
timestamp '2017-01-11 09:59:38.156000'
timestamp '2017-01-11 09:59:38.163000'
timestamp '2017-01-11 09:59:38.171000'


As you can see, CHR(39) is for the quote.

Is this answer out of date? If it is, please let us know via a Comment