declare
myex exception;
no account.ano %type;
b account.bal%type;
branch account.Bname%type;
begin
no:=:no;
b:=:b;
branch:=:branch;
if branch <> 'surat' then
raise myex;
end if;
insert into account values(no,b,branch);
commit;
dbms_output.put_line('record inserted successfully...');
exception
when myex then
dbms_output.put_line('invalid branch name ');
end;
此代碼按預期正常作業,但是當我嘗試在 if 條件中使用 or 添加更多分支名稱時。它不作業。所有條目都會引發例外,即使是像 surat 或 vadodra 這樣的有效分支名稱。
declare
myex exception;
no account.ano %type;
b account.bal%type;
branch account.Bname%type;
begin
no:=:no;
b:=:b;
branch:=:branch;
if branch <> 'surat' or branch <>'vadodra' or branch <>'ahmedabad' then
raise myex;
end if;
insert into account values(no,b,branch);
commit;
dbms_output.put_line('record inserted successfully...');
exception
when myex then
dbms_output.put_line('invalid branch name ');
end;
uj5u.com熱心網友回復:
那是因為您很可能想要AND,而不是OR:
if branch <> 'surat' and branch <>'vadodra' and branch <>'ahmedabad' then
或者,使用IN:
if branch not in ('surat', 'vadodra', 'ahmedabad') then
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/488375.html
