Oracle PL/SQL 多重选择句

时间:2023-03-10 01:00:48
Oracle PL/SQL 多重选择句

Oracle中语句块的基本格式:
declare
--变量定义,初始化赋值。
begin
--变量的赋值,函数调用,if,while等。
end;

Oracle中的语句:关系运算符:= <>
if 条件表达式 then
  --执行代码
end if;

if 条件表达式 then
  --执行代码
else
  --执行代码
end if;

if 条件表达式 then
  --执行代码
  else
    if 条件表达式 then
    --执行代码
    else
    --执行代码
    end if;
end if;

 declare
a number:=1;
b number:=2;
c number:=3;
ans number:=3;
begin
dbms_output.put_line('选择A,B,C?');
if ans=a then
dbms_output.put_line('选择A');
else --跟java里的else if不一样,每一个if写在一个语句块中
if ans=b then
dbms_output.put_line('选择B');
else
if ans=c then
dbms_output.put_line('选择C');
else
dbms_output.put_line('没有正确选择');
end if;
end if;
end if;
end;