I am having trouble deleting from multiple tables.
I am using the code below to delete from multiple tables:
DELETE
FROM usession,
upklist,
projshar USING usession
LEFT JOIN upklist
ON upklist.session_id = usession.session_id
LEFT JOIN Projshar
ON projshar.session_id = usession.session_id
WHERE usession.session_id =
(SELECT session_id
FROM USESSION
WHERE delete_session_id IS NULL
AND user_id =
(SELECT user_id FROM users WHERE regexp_like(USER_NAME, 'gfcashmo', 'i')
)
);
I am using sql developer connection to an oracle database and get the following error
which references the second line - FROM usession,
Error at Command Line:274 Column:13 Error report: SQL Error:
ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
*Cause:
*Action:
According to ducumentation of DELETE statement Oracle has no support for deleting from multiple tables.
Related
I have to run the following UPDATE query into an Oracle database.
UPDATE Appliance
SET Appliance.IdApplianceType =
(
SELECT AT.id
FROM Appliance A INNER JOIN ApplianceType AT
ON UPPER(A.typeName) = UPPER(AT.name)
AND Appliance.id = A.id)
The objective is to find the match between records of Appliance.typeName and ApplianceType.name and set the ApplianceType.id (primary key) in the Appliance.IdApplianceType (FK ApplianceType) (Note: In a 2nd step normalize Appliance table removing Appliance.typeName column and to use IdApplianceType like relation.)
In oracle 12c(and sqlserver 2008+) it works while in version 11g doesn't work.
I report the error below
QL Error: ORA-00904: "APPLIANCE"."ID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Any help will be appreciated :)
Thanks
The extra join seems unnecessary. Why not just use this simpler version?
UPDATE Appliance
SET Appliance.IdApplianceType =
(SELECT AT.id
FROM ApplianceType AT
WHERE UPPER(Appliance.typeName) = UPPER(AT.name)
);
Hi I try to adapt this blog post to my needs using Oracle to model a Data Vault architecture.
With the following code I try to build a link between two hubs referencing on the original source table "orders".
INSERT INTO l_customer_order (customer_id_hk, order_id_hk, load_date, record_source)
SELECT DISTINCT h_customers.customer_id_hk, h_orders.orders_id_hk, SYSDATE, 'Customer+Order'
FROM orders as src
LEFT OUTER JOIN h_orders
ON (h_orders.order_id = src.order_id)
LEFT OUTER JOIN h_customers
ON (h_customers.customer_id = src.customer_id)
LEFT OUTER JOIN l_customer_order AS dest
ON (dest.customer_id_hk = h_customers.customer_id_hk)
AND (dest.order_id_hk = h_orders.order_id_hk)
WHERE dest.order_id_hk IS NULL;
However I receive following error.
Error at Command Line : 192 Column : 17
Error report -
SQL Error: ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
*Cause:
*Action:
Any help or hint much appreciated!
There are two places where you have used the as keyword. For giving alias to the table you just need to write the name of the alias after table name. as should not be used there.
Try the following code: (changes are mentioned inline)
INSERT INTO l_customer_order (customer_id_hk, order_id_hk, load_date, record_source)
SELECT DISTINCT h_customers.customer_id_hk, h_orders.orders_id_hk, SYSDATE, 'Customer+Order'
FROM orders src -- removed AS from here
LEFT OUTER JOIN h_orders
ON (h_orders.order_id = src.order_id)
LEFT OUTER JOIN h_customers
ON (h_customers.customer_id = src.customer_id)
LEFT OUTER JOIN l_customer_order dest -- removed AS from here
ON (dest.customer_id_hk = h_customers.customer_id_hk)
AND (dest.order_id_hk = h_orders.order_id_hk)
WHERE dest.order_id_hk IS NULL;
Cheers!!
Remove the as in your query i.e. instead of
FROM orders as src
use
FROM orders src
Oracle doesn't support the as alias, unless it is/will be added in most current versions
So i am trying to delete some rows in a left joined table using the following code in sql:
DELETE gw_svd_prefix_assignment
FROM gw_svd_prefix_assignment svdp
left join assyst_view av
on upper(svdp.user_name) = upper(av.usr_sc)
where upper(av.usr_sc) IS NULL
commit;
but i am getting this error:
Error starting at line : 1 in command -
DELETE gw_svd_prefix_assignment
FROM gw_svd_prefix_assignment svdp
left join assyst_view av
on upper(svdp.user_name) = upper(av.usr_sc)
where upper(av.usr_sc) IS NULL
commit
Error at Command Line : 2 Column : 1
Error report -
SQL Error: ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
*Cause:
*Action:
Oracle does not support that syntax. UPDATE and DELETE only work on one table . . . the FROM clause cannot contain multiple tables.
Instead, put the logic in the WHERE clause:
delete from gw_svd_prefix_assignment svdp
where not exists (select 1
from assyst_view av
where upper(svdp.user_name) = upper(av.usr_sc)
);
I have following Oracle update statement
UPDATE details
SET details.ISO_BNK_TX_CODE_PRTRY_CODE = details.TX_TYP_CODE,
details.ISO_BNK_TX_CODE_PRTRY_ISSUER = 'BAI'
FROM AS_ACCT_STAT_DET details
JOIN AS_ACCT_STAT statements ON details.ACCT_STAT_ID = statements.ID
JOIN MSG_FDEF fdef ON statements.W_R_SOURCE_FORMAT_ID = fdef.ID
WHERE fdef.CODE = 'BAI2'
/
I made the original script in SQL Server. But I thought this code would work for both. But I receive following error message:
Error at Command Line : 4 Column : 1 Error report - SQL Error:
ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
*Cause:
*Action:
I think something is missing between the last set and the FROM statement.
Anyone?
Try this query
UPDATED
UPDATE (
Select
details.ISO_BNK_TX_CODE_PRTRY_CODE ,details.TX_TYP_CODE,
details.ISO_BNK_TX_CODE_PRTRY_ISSUER
FROM
AS_ACCT_STAT_DET details
INNER JOIN
AS_ACCT_STAT statements ON details.ACCT_STAT_ID = statements.ID
INNER JOIN
MSG_FDEF fdef ON statements.W_R_SOURCE_FORMAT_ID = fdef.ID
WHERE
fdef.CODE = 'BAI2'
) d
SET
d.ISO_BNK_TX_CODE_PRTRY_CODE = d.TX_TYP_CODE,
d.ISO_BNK_TX_CODE_PRTRY_ISSUER = 'BAI'
Oracle doesn't allow a join in an update statement, without a subquery anyway. You may be able to use an updatable view here, but you don't need to as you aren't getting the new values from one of the joined tables.
So it looks like you can just do:
UPDATE details
SET details.ISO_BNK_TX_CODE_PRTRY_CODE = details.TX_TYP_CODE,
details.ISO_BNK_TX_CODE_PRTRY_ISSUER = 'BAI'
WHERE EXISTS (
SELECT null
FROM AS_ACCT_STAT statements
JOIN MSG_FDEF fdef ON statements.W_R_SOURCE_FORMAT_ID = fdef.ID
WHERE statements.ID = details.ACCT_STAT_ID
AND fdef.CODE = 'BAI2'
)
/
That will only update rows where there is matching data in the other two tables, from the exists() condition; that subquery is correlated with the table being updated via its where clause.
UPDATE s
SET s.TECH_NAME = r1.TECH_NAME
FROM **ERRMSG** s INNER JOIN **RAWDATA** r1 on
s.id = r1.id;
I want to update tech_name in table ERRMSG from table RAWDATA.Joining condition is ID.Whats wrong in the above query.Im getting the following error
Error at Command Line : 62 Column : 1
Error report -
SQL Error: ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
*Cause:
*Action:
This sounds like a job for the MERGE statement documented here:
https://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm
This is more in the spirit of what you were trying to do, it avoids correlated subqueries, and it gives you more flexibility.
merge into errmsg s
using rawdata r1
on (s.id = r1.id)
when matched then update set s.tech_name = r1.tech_name
If needed, you can use the other capabilities of MERGE as well; for example, when NOT matched, the id in the errmsg table does not have a corresponding id in the rawdata table. Would you like to take an action in that case as well? You could, for example, set the tech_name to NULL or some default value or delete the row altogether - you can do all these things in one MERGE statement. See the documentation I provided.
What is wrong is that you are using syntax that Oracle does not support. Use a correlated subquery instead:
UPDATE errmsg s
SET s.TECH_NAME = (SELECT r1.TECH_NAME FROM rawdata r1 WHERE s.id = r1.id)
WHERE EXISTS (SELECT 1 FROM rawdata r1 WHERE s.id = r1.id)