oracle格納プロセスと関数の例


作者:peace.zhao游標ifについて、forの例create or replace procedue peace ace_if is cursor var_c is select*from grade;begin for temp in var_c loop if temp.co urse_name='OS'then dbms_out put.put_ラインname='𞓜temp.stu_name;elsif temp.co urse_name='DB'then dbms_out put.put_ライン('DB')else dbms_out put.put_line('feng la feng la')end if;end loop;end;---游标forについては、caseの例1 create or replace procedure peace_case 1 is cursor var_c is select*from test_case;begin for temp in var_c loop case temp.vol when 1 then dbms_out put.put_line('hahaha 1')when 2 then dbms_out put.put_ラインwhen 3 then dbms_out put.put_ラインwhen 4 then dbms_out put.put_ラインelse dbms_out put.put_ラインend case;end loop;end;---游标forについては、caseの例2 create or replace procedure peace_case 2 is cursor var_c is select*from test_case;begin for temp in var_c loop case when temp.vol=1 then dbms_out put.put_line('hahaha 1')when temp.vol=2 then dbms_out put.put_ラインwhen temp.vol=3 then dbms_out put.put_ラインwhen temp.vol=4 then dbms_out put.put_ラインelse dbms_out put.put_ラインend case;end loop;end;---forサイクルの例についてcreate or replace procedue peace aufor is sum 1 number:=0;temp varrchar 2(500)begin for i in 1.9 loop temp:=';for j in 1.i loop sum 1:=i*j;temp:=temp𞓜to_char(i)𞓜𞓜𞓜to_char(j)𞓜𞓜='124124; to_char(sum 1)124';end loop;dbms_out put.put_ラインend loop;end;---loopサイクルの例についてcreate or replace procedue peace auloop is sum 1 number:=0;temp number:=0;begin loop exit when temp>=10;sum 1:=sum 1+temptemp:=temp+1end loop;dbms_out put.put_ライン(sum 1)end;---遊覧標識とloop循環の例についてcreate or replace procedure loop_cur is stu_name varrhar 2(100)coursename varrhar 2(100)cursor var_cur is select*from grade;begin open var_cur;loop fetch var_cur into stu_name、coursenameexit when var_cur%notfound;dbms_out put.put_ラインname 124グルスname;end loop;close var_cur;end;---異常処理の例についてcreate or replace procedue peace_exp(in 1 in varrhar 2)is c_n varrchar 2(100)begin select course_name into c_n from grade where stu u uname=in 1;dbms_out put.put_ラインn)exception when no_data_found then dbms_out put.put_ラインwhen TOO_MANNY.ROWS then dbms_out put.put_ラインend;---異常処理の例について2 create or replace procedue peace auinsert(c_n in varrrhar 2)is error EXCEPTION;begin if c_n='OK'then insert into coursename)values(c_n)elsif c_n='NG'then insert into coursename)values(c_n)ライセerror;else Dbms_Output.put_ラインn𞓜c_n)end if;comitexception when error then rollback;Dbms_Output.put_line('ERRO')end;---カバンの例について定義します。パッケージcreate or replace package peace(u)pkg as function test 1(in 1 in varrhar 2)return number;procedure test 2(in 2 in varhar 2)end peace_pkg;---カバンの例についてパッケージcreate or replace package body peaceを定義します。pkg as function test 1(in 1 in varrhar 2)return number as temp number;begin temp:=0;return temp;end;procedure test 2(in varhar 2)is begin dbms_out put.put_ライン(in 2)end;end peace_pkg;