ITPub博客

首页 > 数据库 > Oracle > 存储过程实例

存储过程实例

Oracle 作者:郭雁 时间:2013-07-08 13:04:49 0 删除 编辑

 

 

 


oracle

 

 


存储过程学习过程

 

一直没有使用过存储过程

 

 

今天特意学习一下

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;

<!-- 正文结束 -->

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22922557/viewspace-1116956/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2009-11-24