I have some knowledge about SQL but a complete novice in Oracle. The following sql statement will execute properly in SQL Server. But this doesn't execute in Oracle and throws an error.
select Field1, * from Table1 where SomeField = 0
Please let know how to execute a similar statement in Oracle. The error recieved is as follows:
ORA-00936: missing expression
00936. 00000 - "missing expression"
Try,
select Field1, a.* from Table1 a where SomeField = 0;
Simply try:
select Field1, Table1.* from Table1 where SomeField = 0
Related
Ques : How do I will select full table with "NVL()" Oracle SQL function
Code :
SELECT NVL(ORDERNO, 'AAA') * FROM GNGRB.PRBOOK;
Error :
ORA-00936: missing expression
00936. 00000 - "missing expression"
*Cause:
*Action:
Error at Line: 11 Column: 30
Is this what you want?
SELECT NVL(ORDERNO, 'AAA') as NEWORDERNO, p.* FROM GNGRB.PRBOOK p;
This selects all rows and columns of the table, and adds another column, called ORDERNO, that replaces null values in ORDERNO with 'AAA'.
Note that this only works as long as ORDERNO is of a string-like datatype: both arguments of NVL() must have the same datatype.
I need to update few columns in one table with the very convoluted calculation.
I'm not good enough in SQL so I tried to use "with" clause in combination with update, but It threw error.
Then I found a post online which suggested to use MERGE so I came up with Merge query. But that one was also throwing an error.
So I removed all other column and updating only one column to remove complexity, but no avail still errors
Below is my query, select query inside working perfectly fine.
Please suggest.
MERGE INTO TABLE_1 AS O
USING (
SELECT ((TO_NUMBER(TABLE_3.Total_Whsle_Price)-TO_NUMBER(TABLE_2.OPT_BASE_WHSLE)) - ((TO_NUMBER(TABLE_3.Total_Whsle_Price)-TO_NUMBER(TABLE_2.OPT_BASE_WHSLE))*TO_NUMBER(TABLE_1.AUC_MILEAGE))/100000 ) as CORRECT_FLOOR_PRICE
FROM TABLE_1, TABLE_2,TABLE_3
WHERE TABLE_2.Primary_ID= TABLE_1.Primary_ID
AND TABLE_2.option_code = 'FSDS'
AND TABLE_1.FLOOR_PRICE <> '0.00'
and TABLE_3.Primary_ID=TABLE_1.Primary_ID
and TABLE_3.Primary_ID=TABLE_2.Primary_ID
) AS CORRECT
ON(
O.Primary_ID = CORRECT.Primary_ID
)
WHEN MATCHED THEN
UPDATE
set O.FLOOR_PRICE =CORRECT.CORRECT_FLOOR_PRICE
Error is
An error occurred when executing the SQL command:
MERGE INTO ........
DB2 SQL Error: SQLCODE=-199, SQLSTATE=42601, SQLERRMC=SELECT;VALUES, DRIVER=3.61.75 [SQL State=42601, DB Errorcode=-199]
Try this instead, I think you forgot your identifier in your select statement because after the "ON" statement "CORRECT.Primary_ID" doesn't associate to anything.
MERGE INTO TABLE_1 as O
USING (
SELECT ((TO_NUMBER(TABLE_3.Total_Whsle_Price)-TO_NUMBER
(TABLE_2.OPT_BASE_WHSLE)) - ((TO_NUMBER(TABLE_3.Total_Whsle_Price)
-TO_NUMBER(TABLE_2.OPT_BASE_WHSLE))*TO_NUMBER
(TABLE_1.AUC_MILEAGE))/100000 ) as CORRECT_FLOOR_PRICE,
TABLE_1.Primary_ID AS Primary_ID
FROM
TABLE_1, TABLE_2,TABLE_3
WHERE TABLE_2.Primary_ID = TABLE_1.Primary_ID
AND TABLE_2.option_code = 'FSDS'
AND TABLE_1.FLOOR_PRICE <> '0.00'
AND TABLE_3.Primary_ID=TABLE_1.Primary_ID
AND TABLE_3.Primary_ID=TABLE_2.Primary_ID
) AS CORRECT
ON(
O.Primary_ID = CORRECT.Primary_ID
)
WHEN MATCHED THEN
UPDATE
set O.FLOOR_PRICE = CORRECT.CORRECT_FLOOR_PRICE
I am running a query on ORACLE DB 11g and am having an issue:
select ORDER as "_id", * from orderlines;
I have this error:
ORA-00936: missing expression
00936. 00000 - "missing expression"
*Cause:
*Action:
Error at Line: 7 Column: 41
I tried it with and without the ; and still gives the error.
Thanks in advance!
As ORDER is a reserved word in many RDBMSs including Oracle, you should escape it with " :
SELECT t."ORDER" AS "_id"
, t.*
FROM "orderlines" t
I am executing a SQL statement through Servicestack.ORMLite. The statement is of the following format:
with rowdata as (
select t1.v1, t1.v2 datakey, t2.v1 datavalue from t1
left join t2 on t2.rowid = t1.rowid
)
select * from rowdata
PIVOT
(
SUM(datavalue)
FOR datakey IN ([1],[2],[3],[4],[5])
)AS PivtTable
This executes correctly in SQL Server, and in Oracle (with a few small changes). However, when executing through Servicestack.ORMLite using the 'db.Select (sql)' command, I get the following error:
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
Terminating with a semicolon just returns the following error:
Incorrect syntax near ';'
Executing every other 'Select' statement works fine, but not if it begins with a 'with' or anything else it seems. But this does not appear to be a Servicestack.ORMLite error - both are System.Data.SqlClient.SqlExceptions. If I copy the generated code generated in debug into SQL Server Management studio, it works fine, but execute the same code though ORMLite and it fails.
Any ideas?
Servicestack.ORMLite does not like CTEs. You should look at using the Custom SQL APIs, see here
Something like this:
var sql = #"with rowdata as (
select t1.v1, t1.v2 datakey, t2.v1 datavalue from t1
left join t2 on t2.rowid = t1.rowid
)
select * from rowdata
PIVOT
(
SUM(datavalue)
FOR datakey IN ([1],[2],[3],[4],[5])
)AS PivtTable"
List<MyType> results = db.SqlList<MyType>(sql);
This kind of query would work perfectly in SQL Server, but it does not work in Oracle.
select issueno, * from SOMETABLE;
The error message I'm getting is:
ORA-00936: missing expression
00936. 00000 - "missing expression"
*Cause:
*Action: Error at Line: 1 Column: 16
What is wrong?
Try this, when working with oracle db you need alias when you use column name along with *
select issueno, A.* from SOMETABLE A;
On Oracle you have to include the table name or an alias to use the *. Try this:
select issueno, SOMETABLE.*
from SOMETABLE;