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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值