How to do simple sql requests on sql developer linux? - sql

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

Related

Unable to run two separate select statements Oracle / Toad ORA-00933

I'm coming from a MS SQL background using SSMS. I just recently started using Oracle / Toad at a new company and I'm finding it to be a bit finicky.
One of the things that I use to do in SSMS was select 2 queries, and then execute the statement and see the results for both.
When I attempt to run the following queries
select count(*) from table1;
select count(*) from table2;
I get the following error message back: ORA-00933: SQL Command not properly ended
Is there something in particular that I'm not doing correct?
In your tool, hit F5, you'll get your results as a script for both queries.
In the free, official GUI for Oracle Database, you can do this:
As Barbaros Özhan notes, you'll need to fix your queries first. You need to do a count() on SOMETHING - * will work.
You need to include some literal like 'x', or a symbol like * or a number 1 inside count function like count(1) or count(*) or count('x').
In your case, one of these missing operators causes ORA-00933.
The answer apparently was the button that I was selecting in Toad for Oracle / slightly incorrect SQL statement.
I was hitting the "Execute / compile statement at caret" button instead of the "Execute Script As" button.
Selecting the wrong button in Toad

missing SELECT keyword error from INSERT statement

Alright, I've got this command:
INSERT INTO PHOTOS_HEADER (TC_CLOCK, DC_SCANDATE, TC_PO, DC_DATE, NC_PACKAGES)
VALUES (:TC_CLOCK, TO_DATE(:DC_SCANDATE, :DATE_FORMAT), :TC_PO, TO_DATE(:DC_DATE, :DATE_FORMAT), :NC_PACKAGES)
RETURNING NC_AUTOID into :OUTPUT
I'm running it in .NET through an OracleCommand object, and it runs find on our local 11g server. When this same code runs on a client site, we get this error:
ORA-00928: missing SELECT keyword
Could it be the returning statement? Could it be to_date? I'm working on finding out what version of the Oracle server the client is using, but any suggestions in the mean time?
Edit: Client is running Oracle 11, same as us. Removed the returning into clause, but still receiving the same error.
I was asked in a comment what to do if you need to work with a version of Oracle without returning. I think that's different enough from the spirit of an answer about whether returning exists to place in its own answer.
One approach is to use the nextval function from a sequence and get the ID before the insert.
select sequence.nextval into :id from dual;
Then perform the insert.
See http://www.dba-oracle.com/t_oracle_nextval_function.htm for more examples.
It is very likely their version of oracle does not support the returning clause. to_date in values has worked since I started playing with Oracle around Oracle 7 in 1998.
According to http://www.dba-oracle.com/plsql/t_plsql_dml.htm the returning clause was added in Oracle 9I release 2.

Query to get datetime for every database

My friend asking me if there a way to use 1 query to select datetime and use it for any database.
Atm he using this query for Oracle :
SELECT vt_sysdate() FROM dual;
I know dual table is for Oracle only. But he want to use this same query for other database, for example PostgreSQL, as well.
So is there a way to make this query run on every database (Maybe by create a dual table for every database). Or is there a query to get system datetime that work on any database ?
Thank you for you help.
No, I don't think so, because Oracle insists on being weird, and MS SQL doesn't seem to support the standard current_date at all.
MySQL accepts SELECT current_date;, doesn't understand VALUES.
PostgreSQL accepts SELECT current_date; or VALUES.
MS SQL doesn't seem to understand current_date at all.
Oracle understands current_date but not scalar queries without FROM.
From wikipedia:
Firebird has a one-row system table RDB$DATABASE that is used in the same way as Oracle's DUAL, although it also has a meaning of its own.
IBM DB2 has a view that resolves DUAL when using Oracle Compatibility 1
Microsoft Access: A table named DUAL may be created and the single-row constraint enforced via ADO 2
MySQL allows DUAL to be specified as a table in queries that do not need data from any tables.3
PostgreSQL: A DUAL-view can be added to ease porting from Oracle.4
SQLite: A VIEW named "dual" that works the same as the Oracle "dual" table can be created as follows: "CREATE VIEW dual AS SELECT 'x' AS dummy;"
SAP HANA has a table called DUMMY that works the same as the Oracle "dual" table.
You might try current_timestamp instead of current_date, as this appears to be the best-supported option. As an aside, writing vendor-neutral SQL seems to be basically impossible without some kind of translation layer.
Thank everyone for your support.
After looking at everyone answer, after a while discuss with my friend, we came to a conclusion that it won't be possible to use one query for all database. So we create a function, check database, use correct function to get time and return it.
We will have to create a dummy table dual on any database we use like in this blog suggest. A dummy table with 1 column and 1 record.
Thank you all.

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)

SELECT without a TABLE (JDBC)

In most sql databases I have seen you can do something like:
SELECT ABS(-2.4)
and I get back 2.4. Notice there is no FROM clause.
When I try to do this in OpenEdge via Squirrel and the JDBC driver I get a syntax error. Is there a way to run SELECT statements like this (sans FROM clause) via JDBC?
Single row/column Dual equivalent; SYSPROGRESS.SYSCALCTABLE