0

I am trying to create a table in my Oracle Database with the following structure:

CREATE TABLE orderlines(collectionTime TIMESTAMP NOT NULL);

An example of a timestamp that will be going in a row is:

20-01-2015 11:33:48-04:00

What would be the best datatype to use to store this timestamp? TIMESTAMP, or DATE?

Also, what would the format be?

When I tried to import my CSV file containing all of the timestamps, SQL Developer Import Wizard didnt like the formatting. I tried

DD-MM-YYYY HH24:SS:MM-TZ

2 Answers 2

1

What would be the best datatype to use to store this timestamp? TIMESTAMP, or DATE?

The TIMESTAMP datatype is an extension to the DATE datatype. In addition to the datetime elements, the TIMESTAMP datatype holds fractions of a second. It comes in two forms, TIMESTAMP WITH TIME ZONE and TIMESTAMP WITH LOCAL TIME ZONE. So, if you want the precision till fraction of seconds along with the timezone elements, go for TIMESTAMP. Else, a DATE data type will give you datetime elements.

Also, what would the format be?

Format is only for DISPLAY. So use the format model which you would like to display. You need to use TO_CHAR and a proper format model. For example,

SQL> select to_char(sysdate, 'mm/dd/yyyy hh24:mi:ss') from dual;

TO_CHAR(SYSDATE,'MM
-------------------
01/21/2015 11:02:27

SQL> select to_char(sysdate, 'mm/dd/yyyy hh:mi:ss am') from dual;

TO_CHAR(SYSDATE,'MM/DD
----------------------
01/21/2015 11:03:04 am

SQL>

When I tried to import my CSV file containing all of the timestamps, SQL Developer Import Wizard didnt like the formatting.

That is the issue with your locale-specific NLS_DATE_FORMAT.

Sign up to request clarification or add additional context in comments.

Comments

0

Try 'DD-MM-YYYY HH24:MI:SS-TZH:TZM'. This is the mask that would be recognized by to_timestamp_tz. Notice that MM is for months and MI is for minutes. Also, you had hours:seconds:minutes in your mask, but that would result in a wrong value not an error.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.