忑珜 | 蛁聊 | 腎翻
忑珜 >> 撮扲蚳戲 >> 杅擂踱 >> Oracle價插 

PL/SQL霜最諷秶


釬氪乾陑 懂埭乾陑 樓?輮掉?ㄩ2006爛01堎26??
晡猁ㄩ


    PL/SQL最唗笢腔霜最諷秶逄曆質牖賸勍嗣詢撰逄晟腔霜最諷秶佷砑ㄛ筍衱衄赻撩腔杻萸﹝

沭璃諷秶

&nbs;#


蛌婥ㄩ蛌婥③悵隱掛陓洘ㄛ掛恅懂赻
http://www.51dibs.com
/html/2006/article/info2/a_c3b7ca9b0b96d355.htm




PL/SQL霜最諷秶


桴萸ㄩ乾陑笱赽苤痔尪 壽瑩趼ㄩPL/SQL霜最諷秶




PL/SQL霜最諷秶


    PL/SQL最唗笢腔霜最諷秶逄曆質牖賸勍嗣詢撰逄晟腔霜最諷秶佷砑ㄛ筍衱衄赻撩腔杻萸﹝

沭璃諷秶

    狟醱籵徹妗瞰賡庄沭璃諷秶逄曆腔妏蚚﹝
    1. if..then..end if沭璃諷秶
    粒蚚if..then..end if沭璃諷秶腔逄楊賦凳?褉?9.15垀尨﹝

    婓▽SQLPlus Worksheet▼笢硒俴狟蹈PL/SQL最唗ㄛ蜆最唗瓚剿謗跺淕杅曹講腔湮苤﹝ 硒俴賦彆?褉?9.16垀尨﹝
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    set serveroutput on
    declare
       number1 integer:=90;
       number2 integer:=60;
    begin
       if number1>=number2 then
           dbms_output.put_line(number1湮衾脹衾number2);
       end if;
    end;
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    ▽饜杶最唗弇离▼ㄩ菴9梒\ conditioncontrol1.sql﹝

    2. if..then..else..end if沭璃諷秶
    粒蚚if..then..else..end if沭璃諷秶腔逄楊賦凳?褉?9.17垀尨﹝

    婓▽SQLPlus Worksheet▼笢硒俴狟蹈PL/SQL最唗ㄛ蜆最唗瓚剿謗跺淕杅曹講腔湮苤ㄛ怀堤祥肮腔賦彆﹝硒俴賦彆?褉?9.18垀尨﹝
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    set serveroutput on
    declare
        number1 integer:=80;
        number2 integer:=90;
    begin
        if number1>=number2 then
            dbms_output.put_line(number1湮衾脹衾number2);
        else
            dbms_output.put_line(number1苤衾number2);
        end if;
    end;
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    ▽饜杶最唗弇离▼ㄩ菴9梒\ conditioncontrol2.sql﹝

    3. ifИ杶沭璃諷秶
    粒蚚ifИ杶沭璃諷秶腔逄楊賦凳?褉?9.19垀尨﹝

    婓▽SQLPlus Worksheet▼笢硒俴狟蹈PL/SQL最唗ㄛ蜆最唗瓚剿謗跺淕杅曹講腔湮苤ㄛ怀堤祥肮腔賦彆﹝
    硒俴賦彆?褉?9.20垀尨﹝
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    set serveroutput on
    declare
        number1 integer:=80;
        number2 integer:=90;
    begin
        if number1<=number2 then
           if number1=number2 then
              dbms_output.put_line(number1脹衾number2);
           else
              dbms_output.put_line(number1苤衾number2);
           end if;
        else
              dbms_output.put_line(number1湮衾number2);
        end if;
    end;
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    ▽饜杶最唗弇离▼ㄩ菴9梒\ conditioncontrol3.sql﹝


悜遠諷秶

    悜遠賦凳岆偌桽珨隅軀憮沭璃硒俴珨郪韜鍔ㄛPL/SQL笢衄4笱價掛悜遠賦凳ㄛ婓坳蠅價插奻衱褫眕栳曹堤勍嗣И杶悜遠諷秶ㄛ涴爵賡庄郔價掛腔悜遠諷秶逄曆﹝
    1. loop..exit..end loop悜遠諷秶
    粒蚚loop..exit..end loop悜遠諷秶腔逄楊賦凳?褉?9.21垀尨﹝

    婓▽SQLPlus Worksheet▼笢硒俴狟蹈PL/SQL最唗ㄛ蜆最唗蔚number1曹講藩棒樓1ㄛ珨眻善脹衾number2峈砦ㄛ苀數怀堤悜遠棒杅﹝
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    set serveroutput on
    declare
        number1 integer:=80;
        number2 integer:=90;
        i integer:=0;
    begin
       loop
          number1:=number1+1;
          if number1=number2 then
             exit;
          else
             i:=i+1;
          end if;
      end loop;
     dbms_output.put_line(僕悜遠棒杅:||to_char(i));
    end;
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    硒俴賦彆?褉?9.22垀尨﹝

    ▽饜杶最唗弇离▼ㄩ菴9梒\loopcontrol1.sql﹝
    2. loop..exit..when..end loop悜遠諷秶
    粒蚚loop..exit..when..end loop悜遠諷秶腔逄楊賦凳迵芞9.21垀尨賦凳濬侔﹝
    exit when妗暱奻憩眈絞衾
        if 沭璃 then
        exit;
      end if;
    婓▽SQLPlus Worksheet▼笢硒俴狟蹈PL/SQL最唗ㄛ蜆最唗蔚number1曹講藩棒樓1ㄛ珨眻善脹衾number2峈砦ㄛ苀數怀堤悜遠棒杅﹝
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    set serveroutput on
    declare
        number1 integer:=80;
        number2 integer:=90;
        i integer:=0;
    begin
        loop
           number1:=number1+1;
           i:=i+1;
           exit when number1=number2;
        end loop;
     dbms_output.put_line(僕悜遠棒杅:||to_char(i));
    end;
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    硒俴賦彆?褉?9.23垀尨﹝

    ▽饜杶最唗弇离▼ㄩ菴9梒\loopcontrol2.sql﹝
    when悜遠諷秶賦旰沭璃掀粒蚚if腔沭璃諷秶賦旰悜遠棒杅嗣1棒﹝
    3. while..loop..end loop悜遠諷秶
    粒蚚loop..exit..when..end loop悜遠諷秶腔逄楊?覤癒?
    while 沭璃 loop
       硒俴逄曆僇;
    end loop;
    婓▽SQLPlus Worksheet▼笢硒俴狟蹈PL/SQL最唗ㄛ蜆最唗蔚number1曹講藩棒樓1ㄛ珨眻善脹衾number2峈砦ㄛ苀數怀堤悜遠棒杅﹝
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    set serveroutput on
    declare
        number1 integer:=80;
        number2 integer:=90;
        i integer:=0;
    begin
        while number1<number2 loop
          number1:=number1+1;
          i:=i+1;
       end loop;
     dbms_output.put_line(僕悜遠棒杅:||to_char(i));
    end;
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    硒俴賦彆?褉?9.24垀尨﹝

    ▽饜杶最唗弇离▼ㄩ菴9梒\whilecontrol.sql﹝
    4. for..in..loop..end悜遠諷秶
    粒蚚for..in..loop..end悜遠諷秶腔逄楊?覤癒?
    for 悜遠曹講 in [reverse] 悜遠狟賜..悜遠奻賜 loop
        悜遠揭燴逄曆僇;
    end loop;
    婓▽SQLPlus Worksheet▼笢硒俴狟蹈PL/SQL最唗ㄛ蜆最唗籵徹悜遠曹講I懂諷秶number1崝樓棒杅ㄛ怀堤賦彆﹝硒俴賦彆?褉?9.25垀尨﹝
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    set serveroutput on
    declare
       number1 integer:=80;
       number2 integer:=90;
       i integer:=0;
    begin
        for i in 1..10 loop
          number1:=number1+1;
        end loop;
      dbms_output.put_line(number1腔硉:||to_char(number1));
    end;
    求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求求
    ▽饜杶最唗弇离▼ㄩ菴9梒\forcontrol.sql﹝





楷票?芄?love
↙ 芢熱跤扂腔疑衭 ↙ 惆豢渣昫蟈諉
奻う恅梒ㄩPL/SQL價掛逄楊猁匼
狟う恅梒ㄩOracle 9i 岈昢揭燴
□恅梒湖荂■
□壽敕敦諳■
楷桶ぜ蹦
脤艘ぜ蹦
笢※PL/SQL霜最諷秶§眈壽囀?? 笢※PL/SQL霜最諷秶§眈壽囀??
笢※PL/SQL霜最諷秶§眈壽囀?? 笢※PL/SQL霜最諷秶§眈壽囀??
笢※PL/SQL霜最諷秶§眈壽囀?? 笢※PL/SQL霜最諷秶§眈壽囀??

壽衾扂蠅厙桴隱晟衭①蟈諉迵扂婓盄迵扂謐毞鍰?◇麆?奪燴TOP
諦誧督昢笢陑陓眊ㄩ[email protected] 厙桴華芞

汒隴