Timestamp literal in Oracle SQL Developer - sql

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.

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.

You can use CAST
select to_char(cast(sysdate as timestamp),'DD-MON-YYYY HH24:MI:SS.FF') from dual

See the answer of : How to convert date to timestamp(DD-MON-YYYY HH24:MI:SS.FF format) in oracle?
The "{ts xxx}" syntax is specific to ODBC or OLEDB driver...

Related

How to do simple sql requests on sql developer linux?

I installed sqldelevoper on linux and try to do some simple sql requests.
When i try to get current date:
select date(now());
I got an error:
"ORA-00936: missing expression."
I have no idea what am i doing wrong, i can't normal work with DATE type.
You seem to be running a MySQL query (or the like) in Oracle. The equivalent would be:
select trunc(sysdate) from dual
Note that in MySQL, you could phrase this simply as:
select current_date

How to use GLDATE and GL_DATE with Toad for Oracle

I am executing simple SQL queries with Toad for Oracle version 13.1.1.5.
I have been reading the Oracle documentations and still struggle with understanding the differences between GLDATE and GL_DATE.
At the moment I know how to use GLDATE to change the date format implicitly by casting the GLDATE to text (without tampering with the computer datetime settings), example:
SELECT * FROM table WHERE to_char(GLDATE,'YYYYMMDD') = '20190105'
But what is GL_DATE (with the "_" character) then used for and why is the above code not working with GL_DATE (it throws the error ORA-00904 GL_DATE: invalid identifier)?
Moreover, how do environment variables connect with the GLDATE/GL_DATE commands?

SQL: to_char alternative for Oracle AND SQL-Server

I have some sql statements, which i am using for Oracle. This sql statements are used by a programm from me.
I want to support Oracle and SQL-Server with my program without having different sql statements for Oracle and SQL-Server.
Which alternative can i use for the specific Oracle SQL-Statements:
to_char(FIELDNAME, 'YYYY')
to_char(FIELDNAME, 'YYYYMMDD')
to_char(FIELDNAME, 'DD.MM.YYYY')
The sql statements have to work for Oracle and SQL-Server.
Even if at a first glance the SQL implementation from two different vendors looks similar, when working with real life enterprise applications you will stumble upon a large number of differences, and I am only talking about SQL, when comparing PL/SQL with T-SQL there is hardly any resemblance left.
When trying to reduce the usage of two databases to only common functionality, you will loose a lot of their power, you could as well use a txt file on the file system.
One elegant solution, as someone already suggested, would be to leave the columns in the database as DATE data type and extract your data in the application code that stands above the database, if any. For example, in Java, you will map your database DATE columns to java.sql.Date no matter if that date comes from Oracle or from SQL Server.
Still, if you want to get your formatted data from the database, you could create separate columns that hold the formatted date, for example :
FIELDNAME | FIELDNAME_YYYY | FIELDNAME_YYYYMMDD | FIELDNAME_DDMMYYYY
I don't think there are common functions to do what you want. Oracle supports the ANSI standard extract() function for extracting date parts. SQL Server has separate functions for YEAR(), MONTH(), and DAY(). Oracle uses TO_CHAR(); SQL Server uses CONVERT().
One option is to define the functions YEAR(), MONTH(), and DAY() in Oracle and then use string concatenation (via the CONCAT()) function to combine the data. Or, write specific functions in each database for what you want to do. Or, perhaps, someone has implemented TO_CHAR() in SQL Server and you can grab the code from the web.
Finally i found a solution. Maybe its useful some other people too.
You can set the input format for a date...
Oracle: ALTER SESSION SET NLS_DATE_FORMAT = 'DD.MM.YYYY'
SQL-Server: SET DATEFORMAT dmy

Is There a Way to Convert 'datetime' Format to 'timestamp' in Sql Server CE?

I know there's a way to do this in regular Sql Server, and if I'm not mistaken, it looks something like this:
SELECT UNIX_TIMESTAMP(ba_trans_entered) * 1000 AS 'dateUTC'
I do admit, however, that I don't get the * 1000 part, but that's beside the point.
When I try to perform this query in SQL Server CE it just tells me (i.e., WebMatrix tells me):
'UNIX_TIMESTAMP' is not a recognized built-in function name.
I'm assuming UNIX_TIMESTAMP is not supported in Sql Server Compact.
Also, I tried Googling and searching here on SE but no data relevant to SQL Server CE shows up, so there may not be a way in the given environment.
Is there any way to convert 'datetime' (example: 7/13/2007 12:00:00 AM) to timestamp (example: 1184302800000)? I know I can do this in JavaScript, but I was told it might be faster to do this in the query itself, and since I am pulling a ton of data...
The UNIX_TIMESTAMP function does not exist in SQL Server on SQL Server Compact, but you can use DATEDIFF:
DATEDIFF(SECOND,{d '1970-01-01'}, ba_trans_entered)

How can I convert a SQL Server date format to Oracle?

I am working on migration of data from an old system to a new system. As part of migration, the data from the legacy system, (stored in files) is pumped into MS SQL Server. Now my app runs on Oracle. I'm having a problem with the date/timestamp.
The timestamp format in MS SQL Server data is:
2008.12.23 00:00:00
Oracle expects:
23/12/2008 00:00:00
or
23-DEC-2008 00:00:00
What would be the best way to import the data? Oracle's to_date() function didn't work as I thought it would.
I assume you're using insert statements?
Convert your dates using:
TO\_DATE(sql\_server\_value,'YYYY.MM.DD HH24:MI:SS')
You can put a second parameter on the to_date function to specify in what format the incoming data is. You will likely have to make SQL server pump the data out as a string.
http://www.techonthenet.com/oracle/functions/to_date.php
Use CONVERT to convert your internal datetime columns to text in whatever format you wish on the SQL Server side.