How to convert this date to datetime in oracle?

Asked

Viewed 3,140 times

3

Correct way to convert the date '27/12/2016 16:31:39,137000000' for datetime(timestamp(6)) in the oracle?

Some unsuccessful attempts that result in error ORA-01821: formato de data não reconhecido 01821. 00000 - "date format not recognized":

  SELECT TO_CHAR(TO_DATE('27/12/2016 16:31:39,137000000', 'dd/mm/yyyy HH24:MI:SS'), 'DD/MM/YYYY') DT_C FROM DUAL;
  SELECT TO_CHAR(TO_DATE('27/12/2016 16:31:39,137000000', 'dd/mm/yyyy HH24:MI:SS.FF9'), 'DD/MM/YYYY') DT_C FROM DUAL;
  SELECT TO_CHAR(TO_DATE('27/12/2016 16:31:39,137000000', 'dd/mm/yyyy HH24:MI:SS.FF'), 'DD/MM/YYYY') DT_C FROM DUAL;

This works, but the date with the comma and the numbers after the seconds does not:

SELECT TO_CHAR(TO_DATE('27/12/2016 16:31:39', 'dd/mm/yyyy HH24:MI:SS'), 'DD/MM/YYYY') DT_C FROM DUAL;

1 answer

2


I don’t know if I understand, see if this is what you wanted:

SELECT TO_CHAR(TO_DATE('27/12/2016 16:31:39', 'dd/mm/yyyy HH24:MI:SS'), 'DD/MM/YYYY HH24:MI:SS') DT_C FROM DUAL;

To show the milliseconds:

SELECT TO_TIMESTAMP ('10-Sep-02 14:10:10.123000', 'DD-Mon-RR HH24:MI:SS.FF')

FROM dual;

Timestamp:

select to_char(systimestamp,'dd-mm-yyyy hh24:mi:ss.FF') as ts from dual;
  • the date is 12/27/2016 16:31:39,137000000

  • like, it’s literally what I get as date

  • 1

    use that code then, it is only edit the timestamp for what you want: select to_char(systimestamp,'dd-mm-yyyy hh24:mi:ss.FF') as ts from dual; OU that: SELECT TO_TIMESTAMP ('10-Sep-02 14:10:10.123000', 'DD-Mon-RR HH24:MI:SS.FF') from DUAL;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.