declare begin for i in 1..9 loop for j in 1..i loop --不換行輸出數據 dbms_output.put(j||'*'||i||'='||(j*i)); end loop; --換行輸出 dbms_output.put_line(null); end loop; end; 效果: 1*1=1 1*2=22*2=4 1*3=32*3=63*3=9 1*4=42*4=83*4=124*4=16 1*5=52*5=103*5=154*5=205*5=25 1*6=62*6=123*6=184*6=245*6=306*6=36 1*7=72*7=143*7=214*7=285*7=356*7=427*7=49 1*8=82*8=163*8=244*8=325*8=406*8=487*8=568*8=64 1*9=92*9=183*9=274*9=365*9=456*9=547*9=638*9=729*9=81
declare begin for i in 1..10 loop --循環輸出總數-行數個空格 for j in reverse i..10 loop dbms_output.put(' '); end loop; --輸出行數個*號和空格 for x in 1..i loop dbms_output.put('* '); end loop; --換行 dbms_output.put_line(null); end loop; end; 效果: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1 2 declare 3 cursor coll_cursor is select * from college; 4 begin 5 for coll_info in coll_cursor loop 6 dbms_output.put(coll_info.coll_id||' '); 7 dbms_output.put(coll_info.coll_name||' '); 8 dbms_output.put(coll_info.coll_score); 9 dbms_output.put_line(null); 10 end loop; 11 end;
1 declare 2 cursor coll_cursor is select coll_id,coll_name from college; 3 id college.coll_id%type; 4 name college.coll_name%type; 5 begin 6 open coll_cursor; 7 fetch coll_cursor into id,name; 8 while coll_cursor%found loop 9 dbms_output.put(id||' '); 10 dbms_output.put(name); 11 dbms_output.put_line(null); 12 fetch coll_cursor into id,name; 13 end loop; 14 close coll_cursor; 15 end;
begin for coll_info in (select * from college) loop dbms_output.put(coll_info.coll_id||' '); dbms_output.put(coll_info.coll_name||' '); dbms_output.put(coll_info.coll_score); dbms_output.put_line(null); end loop; end;
1 declare 2 cursor coll_cursor is select * from college; 3 coll_info college%rowtype; 4 begin 5 open coll_cursor; 6 loop 7 fetch coll_cursor into coll_info; 8 exit when coll_cursor%notfound; 9 dbms_output.put(coll_info.coll_id||' '); 10 dbms_output.put(coll_info.coll_name||' '); 11 dbms_output.put(coll_info.coll_score); 12 dbms_output.put_line(null); 13 end loop; 14 close coll_cursor; 15 end;