oracle 存储过程学习过程 建立一个最简单的存储过程 create or replace procedure test_xg_p1 is begin dbms_output.put_line('hello world! this is the first procedure'); end; 建立一个带输入输出参数的存储过程:把输入的数据传给输出参数 create or replace procedure test_xg_p2(a in number,x out number) is begin x:=a; end test_xg_p2; 建立一个逻辑判断的存储过程,并包含输入输出参数:近似分数的登记判断 create or replace procedure test_xg_p3(a in number,x out varchar2) is begin if a>=90 then begin x := 'A'; end; end if; if a<90 then begin x:='B'; end; end if; if a<80 then begin x:='C'; end; end if; if a<70 then begin x:='D'; end; end if; if a<60 then begin x:='E'; end; end if; end test_xg_p3; 建立一个带循环逻辑的存储过程:近似累加函数 create or replace procedure test_xg_p4(a in number,x out varchar2) is tempresult number(16); begin tempresult :=0; for tempa in 0..a loop begin tempresult := tempresult + tempa; end; end loop; x:=tempresult; end test_xg_p4; 建立一个能从数据库中特定表中返回数据的存储过程: create or replace procedure test_xg_p5(x out varchar2) is tempresult varchar2(1024); begin tempresult := 'start->'; select hotelid||hotelname into tempresult from hotel where hotelid =10041764; x:=tempresult; end test_xg_p5; 建立一个能使用游标的带循环的存储过程: create or replace procedure test_xg_p6(x out varchar2) is tempresult varchar2(10240); cursor cursor1 is select * from hotel where hotelname like '浙江%'; begin tempresult := 'start->'; for cursor_result in cursor1 loop begin tempresult :=tempresult||cursor_result.hotelid||cursor_result.hotelname; end; end loop; x:=tempresult; end test_xg_p6
oracle 存储过程例子
猜你喜欢
转载自pengfeifei26.iteye.com/blog/1933458
今日推荐
周排行