pl\sql中流程控制方式

-------转载请注明出处,同时欢迎大家转载--------



declare
username varchar2(20);
begin
  select t.ename into username from emp t where rownum=1;
  dbms_output.put_line(username);
end;



2 oracle 中case when 用法
declare
  age number(6,2); ----这里的六代表总长度,2代表小数点后面的长度
begin
  age:=&myage;
     
      case age
        when 10 then
          dbms_output.put_line('you have 10 year');
        when 20 then
          dbms_output.put_line('you have 20 year');
        when 30 then
          dbms_output.put_line('you have 3o year');
       else
         dbms_output.put_line('I donot know you age');
        end case;  
end;


3 oracle 中loop循环的用法
declare
        q number :=0;
begin
        loop
            q:=q+1;
            dbms_output.put_line('q='||q);
                 exit when q=10;
        end loop;
end;


4.loop循环中另外的一种退出方法

declare
        q number :=0 ;
begin
        loop
            q:=q+ 1;
            dbms_output.put_line( 'q='||q);
            if q=10
              then
                 exit;
             end if ;
        end loop ;
               dbms_output.put_line('hello i barek');  ---exit跳出后这句号会执行
end;

5.loop循环中另外的一种
declare
  q number := 8;
begin
  while q < 100 loop
    q := q + 1;
    dbms_output.put_line( 'hello world good ');
  end loop;
end;


6.loop 的for用法
declare
  q number := 8;
begin
   for c in 1..10   loop  --- 要想从10到1 要在 in 的后面加上 reverse
    dbms_output.put_line('c is '||c);
    dbms_output.put_line('hello world good ');
  end loop;
end;

7.goto语句的用法

declare
  sal number ;
begin
  select  t.sal into sal from emp t where rownum=1  ;
  if sal<20000
    then
    goto a;
    else
      goto b; 
    end if; 
    <<a>>
      dbms_output.put_line('this is a');
      <<b>>
      dbms_output.put_line('this is b');

end;


猜你喜欢

转载自xiongpan0807.iteye.com/blog/1783064
今日推荐