This question already has answers here:
ORA - 00933 confusion with inner join and "as"
(2 answers)
Using Alias in query resulting in "command not properly ended"
(1 answer)
How to use the 'as' keyword to alias a table in Oracle?
(2 answers)
Closed 4 years ago.
I'm trying to execute the next:
SELECT l.id AS id
FROM s.process AS l
JOIN s.item AS r ON l.id = r.id;
But I'm getting:
Query execution failed
Reason:
SQL Error [933] [42000]: ORA-00933: SQL command not properly ended
Using:
DBeaver
ojdbc7.jar as driver
You have to remove AS when defining alias of table/view:
SELECT l.id AS id
FROM s.process l
JOIN s.item r ON l.id = r.id;
Oracle supports table aliases but It supports AS in the SELECT list but not in the FROM list:
SELECT l.id AS id
FROM s.process l
JOIN s.item r ON l.id = r.id;
Related
This question already has answers here:
SQL Oracle LEFT JOIN and SUBQUERY error: ORA-00905: missing keyword
(2 answers)
Closed 5 years ago.
select buses.bus_no,
buses.bus_name
from buses
join
(
select sc1.bus_no
from schedule as sc1
join schedule as sc2 on sc1.source = sc2.destination
and sc1.destination = sc2.source
) as s1 on buses.bus_no = s1.bus_no;
Oracle does not support as for table aliases. So, you can write this as:
select b.bus_no, b.bus_name
from buses b join
(select sc1.bus_no
from schedule sc1 join
schedule sc2
on sc1.source = sc2.destination and sc1.destination = sc2.source
) s1
on b.bus_no = s1.bus_no;
Trying to run a simple inner join in a query on a 5.1 Oracle Database.
SELECT
W.ID,
WE.CLASS
FROM
W
INNER JOIN
WE
ON (W.ID=WO.ID)
WHERE
WO.ID='688158'
It results in the Command not properly ended.
I can do
Select
W.ID, WE.CLASS from W, WE
WHERE
W.ID=WO.ID and WO.ID='688158'
and it doesn't error out but doesn't return the results I want because of the lack of join.
Thanks!
Your table name is used incorrectly. Should be:
SELECT
W.ID,
WE.CLASS
FROM
W
INNER JOIN
WE
ON (W.ID = WE.ID)
WHERE
WE.ID='688158';
WE instead of WO
This question already has answers here:
ORA-00979 not a group by expression
(10 answers)
Closed 5 years ago.
Here is my query:
select
A.school_dim_id,
A.platform_dim_id,
A.month_dim_id,
CASE WHEN B.SCHOOLTYPE NOT IN ('International') THEN B.ROLLSIZE
WHEN B.SCHOOLTYPE IN ('International') THEN MAX(D.ROLE_SIZE)
END ROLL_SIZE
from
rag_raw_event_detail_fact A inner join rag_school_dim B on (A.school_dim_id = B.school_dim_id)
inner join rag_subscription_detail_fact C on (A.school_dim_id = C.school_dim_id)
inner join rag_intl_school_roll_static D on (D.isbn = c.isbn)
inner join rag_platform_dim E on (E.platform_dim_id = A.platform_dim_id)
where
E.PLATFORM_EVENT = 'alp_wordsmith_resources_opened'
and C.service in ('PriHubsWordsmith','PriHubsWordsmithGlobal')
and C.enddate > sysdate
group by
A.school_dim_id,
A.platform_dim_id,
A.month_dim_id
While running the above SQL, I'm getting the error as mentioned below:
ORA-00979: not a GROUP BY expression
00979. 00000 - "not a GROUP BY expression"
*Cause:
*Action:
Error at Line: 5 Column: 13
I need help to overcome the above error.
You must place all columns from SELECT which is not in group function in GROUP BY section. So it will be:
select
A.school_dim_id,
A.platform_dim_id,
A.month_dim_id,
CASE WHEN B.SCHOOLTYPE NOT IN ('International') THEN B.ROLLSIZE
WHEN B.SCHOOLTYPE IN ('International') THEN MAX(D.ROLE_SIZE)
END ROLL_SIZE
from
rag_raw_event_detail_fact A inner join rag_school_dim B on (A.school_dim_id = B.school_dim_id)
inner join rag_subscription_detail_fact C on (A.school_dim_id = C.school_dim_id)
inner join rag_intl_school_roll_static D on (D.isbn = c.isbn)
inner join rag_platform_dim E on (E.platform_dim_id = A.platform_dim_id)
where
E.PLATFORM_EVENT = 'alp_wordsmith_resources_opened'
and C.service in ('PriHubsWordsmith','PriHubsWordsmithGlobal')
and C.enddate > sysdate
group by
A.school_dim_id,
A.platform_dim_id,
A.month_dim_id,
B.SCHOOLTYPE,
B.ROLLSIZE
But after that you may get not expected result. In that case you will have to rewrite your query.
This question already has answers here:
Oracle "(+)" Operator
(4 answers)
Closed 9 years ago.
We tried to migrate from Oracle to Postgres. We use ora2pg , but we have an error with this code:
SELECT DISTINCT UPU.USUA_C_USUARIO
FROM GN_USUARIOS U,TR_USUARIOS_X_PERFILES_USUARIO UPU,TR_V_PERFILES_USUARIOS PU
WHERE (U.C_USUARIO = UPU.USUA_C_USUARIO(+))
AND (UPU.PEUS_X_PEUS = PU.X_PEUS)
AND U.C_USUARIO = USU.C_USUARIO))
OR NOT EXISTS (
SELECT UPU2.USUA_C_USUARIO
FROM TR_USUARIOS_X_PERFILES_USUARIO UPU2
WHERE UPU2.USUA_C_USUARIO = USU.C_USUARIO)
OR USER = (
SELECT V_CONSTANTE
FROM GN_CONSTANTES
WHERE C_CONSTANTE = 'TRUSUPROP')
We have an error with PU.USUA_C_USUARIO(+). We dont have enough experience in this kind of conversions. How can we transform the code with LEFT OUTER JOIN ?
Thanks!
Probably like so:
FROM GN_USUARIOS U
LEFT JOIN TR_USUARIOS_X_PERFILES_USUARIO UPU ON U.C_USUARIO = UPU.USUA_C_USUARIO
LEFT JOIN TR_V_PERFILES_USUARIOS PU ON UPU.PEUS_X_PEUS = PU.X_PEUS
WHERE U.C_USUARIO = USU.C_USUARIO)
Or possibly:
FROM GN_USUARIOS U
LEFT JOIN ( SELECT UPU.USUA_C_USUARIO, ...
FROM TTR_USUARIOS_X_PERFILES_USUARIO UPU
JOIN TR_V_PERFILES_USUARIOS PU ON UPU.PEUS_X_PEUS = PU.X_PEUS
) UPU_PU ON U.C_USUARIO = UPU_PU.USUA_C_USUARIO
WHERE U.C_USUARIO = USU.C_USUARIO)
In either case, be wary that there's a USU table that is defined nowhere and mismatched parenthesis in your query.
This question already has answers here:
ORA-00918: column ambiguously defined in SELECT *
(4 answers)
Closed 8 years ago.
Here is the SQL:
SELECT alloc.oa_id
FROM qdod.qtran_owner_allocation alloc
INNER JOIN
(SELECT h.oa_id, h.div_ord_no, h.process_queue_id, h.from_ba_no,
h.from_ba_suf, h.from_interest_type_cd, h.from_interest_type_cd, h.from_div_ord_grp,
h.transfer_percent, h2.original_net_amount, h2.new_net_amount
FROM qdod.qtran_fund_transfer_hist h
INNER JOIN
(SELECT DISTINCT h0.oa_id, h0.original_net_amount, h1.new_net_amount
FROM qdod.qtran_fund_transfer_hist h0
INNER JOIN
(SELECT h4.oa_id, SUM (h4.new_net_amount) AS new_net_amount
FROM qdod.qtran_fund_transfer_hist h4
GROUP BY h4.oa_id) h1
ON h0.oa_id = h1.oa_id
WHERE h0.original_net_amount <> h1.new_net_amount AND h0.oa_id >= 100000000) h2
ON h.oa_id = h2.oa_id) h3
ON alloc.oa_id = h3.oa_id;
Every column has it's table defined. The main inner join (the one after the alloc table) runs fine when ran by itself. Any ideas why this is not working? This is being executed against an Oracle 10.2.0.4 database (I have also tried it against an 11.2.0.1 database thinking if it was an Oracle bug it would be resolved in 11.2, but it failed there as well).
Field duplicated in the statement, might have something to do with it
h.from_interest_type_cd, h.from_interest_type_cd,
You seem to be selecting a lot of columns you don't really need as you're not using them anywhere. The query could probably be simplified to:
SELECT alloc.oa_id
FROM qdod.qtran_owner_allocation alloc
INNER JOIN
(SELECT h.oa_id
FROM qdod.qtran_fund_transfer_hist h
INNER JOIN
(SELECT DISTINCT h0.oa_id
FROM qdod.qtran_fund_transfer_hist h0
INNER JOIN
(SELECT h4.oa_id, SUM (h4.new_net_amount) AS new_net_amount
FROM qdod.qtran_fund_transfer_hist h4
GROUP BY h4.oa_id) h1
ON h0.oa_id = h1.oa_id
WHERE h0.original_net_amount <> h1.new_net_amount AND h0.oa_id >= 100000000) h2
ON h.oa_id = h2.oa_id) h3
ON alloc.oa_id = h3.oa_id;