Missing Expression when selecting all columns and one more - 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;

Related

Oracle SQL NVL() Function

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.

Sql query not executing - showing invalid identifier error

with ticket_orders AS(
select REGEXP_SUBSTR(st.ORDER_ID, '\d{3}-\d{7}-\d{7}') "new_order_id"
from
(select
REGEXP_SUBSTR(details, 'Order\s+ID(\s*\(s\))?:\s*\d{3}-\d{7}-\d{7}') AS "ORDER_ID"
from o_remedy ort
) st)
select new_t.new_order_id from ticket_orders new_t;
I'm trying to execute the following sql statement but it keeps showing error as "NEW_T"."NEW_ORDER_ID": invalid identifier
How to get this "new_order_id" because I need to join it further.
Either remove double quotes from the derived column name, or use double quotes in select clause as well.
select new_t."new_order_id" from ticket_orders new_t;
By default, Oracle convert every object name to upper case, unless you specify it in double quotes. So "new_order_id" will not be converted to upper case, but while selecting new_t.new_order_id will be converted to upper case, which doesn't exist.
To resolve it, either remove double quotes from the derived column name, or use double quotes in select clause as well.
I replicated it like this on my local machine.
This will not work.
with tbl as
(select empno "new_emp_no" from emp)
select t.new_emp_no From tbl t
And give
ORA-00904: "T"."NEW_EMP_NO": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action: Error at Line: 116 Column: 10
But this will work.
with tbl as
(select empno "new_emp_no" from emp)
select t."new_emp_no" From tbl t
WITH ticket_orders AS
(
SELECT
REGEXP_SUBSTR(st.ORDER_ID, '\d{3}-\d{7}-\d{7}') new_order_id
FROM
(
SELECT
REGEXP_SUBSTR(details, 'Order\s+ID(\s*\(s\))?:\s*\d{3}-\d{7}-\d{7}') AS ORDER_ID
FROM o_remedy ort
) st
)
SELECT new_t.new_order_id FROM ticket_orders new_t;

SQL Select Query giving MISSING EXPRESSION

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

add const value to sql query result

I have a query:
SELECT * FROM table(i#1040_inv_adj_fn('123'))
how to add const value? This example doesn't work:
SELECT *, 'John' Name FROM table(i#1040_inv_adj_fn('123'))
error:
ORA-00923: FROM keyword not found where expected
00923. 00000 - "FROM keyword not found where expected"
*Cause:
*Action:
Error at Line: 1 Column: 9
As you did not tell us what the error is we have to guess. My guess is you need an alias for the table function, otherwise the * isn't legal:
SELECT t.*,
'Name' as John
FROM table(i#1040_inv_adj_fn('123')) t

Error executing SQL query in Oracle

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