Click here to Skip to main content
15,902,447 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
begin

Insert into  I_CONTEXT (Trade_name , Indication, Material) values ( :Trade_name,:Indication, :Material);


if (:Material exists) then

Update  I_CONTEXT set Trade_name = :Trade_name , Indication = :Indication where material = :Material;

 end if
end;
commit;


Material is not a PK
I am getting the following error

XML
ORA-06550: line 7, column 15:
PLS-00103: Encountered the symbol "EXISTS" when expecting one of the following:

   . ( ) , * @ % & = - + < / > at in is mod remainder not rem =>
   <an exponent (**)> <> or != or ~= >= <= <> and or like like2
   like4 likec as between || indicator multiset member
   submultiset
The symbol "." was substituted for "EXISTS" to continue.
Posted

The problem is the if statement. If :material is a bind variable and you want to check if the value is null then you could use:
if :Material IS NULL then

However, your code will always first insert the row and the update it if the material has a value. If you want to do an actual upsert, see Merge[^]
 
Share this answer
 
Since you mention that Material is not a PK, though there could be a UNIQUE constraint on the column, be aware that your UPDATE could change multiple rows, not just the one that was just inserted.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900