Skip to content
Advertisement

PL/SQL check to see if an inputted value exists in a different table

Goal: Verify storeName exists in the storeLocation table & Verify invoiceNumber does not exist In the invoiceHistory table.

With the code I have bellow, I can add to the table using insert into, but when I use a where exists and not exists, I get the following errors:

ORA-06550: line 7, column 5:

PL/SQL: ORA-00933: SQL command not properly ended

Why is this error occurring and how do I avoid it?

Advertisement

Answer

INSERT ... VALUES ... cannot have a WHERE clause. But INSERT ... SELECT ... can.

But you should make a habit of explicitly listing the targeted columns in an INSERT. That makes sure everything goes where it’s supposed to go.

(You may also check if you really want/need that trailing space in the string literals.)

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement