pl\sql中流程控制方式
-------转载请注明出处,同时欢迎大家转载--------
块
declareusername varchar2(20);begin select t.ename into username from emp t where rownum=1; dbms_output.put_line(username);end;
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;
declare q number :=0;begin loop q:=q+1; dbms_output.put_line('q='||q); exit when q=10; end loop;end;
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;
declare q number := 8;begin while q < 100 loop q := q + 1; dbms_output.put_line( 'hello world good '); end loop;end;
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;
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;