Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timestamp literal in Oracle SQL Developer

I need to test sql queries on Oracle SQL Developer. These queries contain timestamp literals in the format

{ts 'yyyy-mm-dd hh:mm:ss.fff'}

Oracle SQL Developer does not seem to accept this syntax, the symbol { causes error ORA-00911: invalid character.

Is there anything I can do?

EDIT

The sql editor advises me that { is not allowed. I tried with two other tools (DbVisualizer and DBeaver), both using the Oracle Thin driver, all works fine.

However I still want to use that syntax in Oracle SQL Developer because it has interesting features. The queries I have to test are not written by me, change syntax is not an option.

like image 258
barney..gumble Avatar asked Sep 22 '17 13:09

barney..gumble


People also ask

How do I get the TIMESTAMP from a date in SQL Developer?

Use the function trunc(my_timestamp). You can use select to_date(to_char(date_field,'dd/mm/yyyy')) from table.

What is the TIMESTAMP format in Oracle?

yyyy-MM-dd HH:mm:ss. 2018-03-5 15:16:0; 2018-03-5 15:16:0 +5:30. yyyy-MM-dd HH.mm.ss. 2018-03-5 15.16.0; 2018-03-5 15.16.0 +5:30. yyyy-MM-dd HH:mm.

What are literals in Oracle SQL?

A literal is an explicit numeric, character, string, or Boolean value not represented by an identifier.


2 Answers

Use an actual SQL timestamp literal:

TIMESTAMP 'yyyy-mm-dd hh:mm:ss.fff'

What you were using is the JDBC escape syntax, which is supported by JDBC drivers, but not by the Oracle database itself.

like image 144
Lukas Eder Avatar answered Oct 10 '22 23:10

Lukas Eder


You can use CAST

select to_char(cast(sysdate as timestamp),'DD-MON-YYYY HH24:MI:SS.FF') from dual
like image 2
SriniV Avatar answered Oct 10 '22 22:10

SriniV