Home > database >  Essentially the IF NOT how to use EXISTS to Oracle
Essentially the IF NOT how to use EXISTS to Oracle

Time:10-08

IF NOT the EXISTS (SELECT COUNT (*) FROM AA_TempData WHERE id=25)
INSERT INTO AA_TempData (VoucherCode, CustomerCode, nVoucherCode nCustomerCode) values (' and ', 'and', 'and', '41)
ELSE UPDATE AA_TempData SET VoucherCode='41, CustomerCode=' 41 ', nVoucherCode='41', nCustomerCode '41 WHERE id=25

Above is no problem of SQL in essentially, if there id=25 and then perform an update, if there is no insert
But now change to the Oracle, grammar is different, is not, ask the great spirit

CodePudding user response:

1, you can continue to use the select count (*) statements, like this:
Select count (*) into v_cnt the from...
If v_cnt=0 then
Insert into...
The else
The update
End the if;
2, see the oracle merge into statements, very strong,

CodePudding user response:

reference 1st floor lhdz_bj response:
1, you can continue to use the select count (*) statements, like this:
Select count (*) into v_cnt the from...
If v_cnt=0 then
Insert into...
The else
The update
End the if;
2, see the oracle merge into statements, very powerful,
ok, thank you, study for a while

CodePudding user response:

reference 1st floor lhdz_bj response:
1, you can continue to use the select count (*) statements, like this:
Select count (*) into v_cnt the from...
If v_cnt=0 then
Insert into...
The else
The update
End the if;
2, see the oracle merge into statements, very powerful,
ok, thank you, study for a while
  • Related