• plsql控制结构


    2010年8月31日 19:51:46

    if-then-else语句

    declare
    a number;
    b varchar2(10);
    begin
    a:=3;
    if a=1 then
    b:='A';
    elsif a=2 then
    b:='B';
    else
    b:='C';
    end if;
    dbms_output.put_line('b的值是:'||b);
    end; 

    case语句

    declare
    a number;
    b varchar2(10);
    begin
    a:=3;
    case
    when a=1 then b:='A';
    when a=2 then b:='B';
    when a=3 then b:='C';
    else b:='others';
    end case;
    dbms_output.put_line('b的值是:'||b);
    end; 

     循环

    if循环

    declare

    x number;

    begin

    x:=0;

    loop

    x:=x+1;

    if x>=3

    then exit;

    end if;

    dbms_output.put_line('循环内x的值'||x);

    end loop;

    dbms_output.put_line('循环外x的值'||x);

    end;

    when循环

    declare
    x number;
    begin
    x:=0;
    loop
    x:=x+1;
    exit when x>=3;
    dbms_output.put_line('循环内x的值'||x);
    end loop;
    dbms_output.put_line('循环外x的值'||x);
    end;

    while循环

    declare
    x number;
    begin
    x:=0;
    while x<3 loop
    x:=x+1;
    dbms_output.put_line('循环内x的值'||x);
    end loop;
    dbms_output.put_line('循环外x的值'||x);
    end;

    for循环

    begin
    for i in 1..5 loop
    dbms_output.put_line('i='||i);
    end loop;
    dbms_output.put_line('end of for loop');
    end;

    for逆循环

    begin
    for i in reverse 1..5 loop
    dbms_output.put_line('i='||i);
    end loop;
    dbms_output.put_line('end of for loop');
    end;

    goto和标号

    declare
    x number;
    begin
    x:=0;
    <<repeat_loop>>
    x:=x+1;
    dbms_output.put_line(x);
    if x<3 then
    goto repeat_loop;
    end if;
    end; 

  • 相关阅读:
    Java中的==和equals区别
    2014年06月30日
    20140625&nbsp;20:39
    20140627&nbsp;20:47
    2014年06月30日
    20140628&nbsp;16:07
    hdu 1418 抱歉 (数学)
    hdu 1302 The Snail (模拟)
    hdu 1391Number Steps
    hdu 1395 2^x mod n = 1
  • 原文地址:https://www.cnblogs.com/lanzi/p/1813995.html
Copyright © 2020-2023  润新知