oracle学习--存储过程.sql

create or replace procedure test
as
begin
dbms_output.put_line('hello world!');
end;
show serveroutput;
set serveroutput on;

begin
test;
end;

select * from user_source where name='TEST' order by line;
select * from user_source where name='TEST2' order by line;
create or replace procedure product_update_prc
as
begin
update productinfo set description='促销产品'
where productid in (
select productid from (select * from productinfo order by productprice asc) where rownum<4
);
commit;
end;
/
declare
cursor mycursor is select * from productinfo;
myrow productinfo%rowtype;
begin
product_update_prc;
/*
for r in mycursor loop
dbms_output.put_line(r.description);
end loop;*/
open mycursor;
loop
fetch mycursor into myrow;
exit when mycursor%notfound;
dbms_output.put_line(myrow.description);
end loop;
close mycursor;
end;
show errors procedure product_update_prc;


create or replace procedure test2
as
v_categoryid categoryinfo.categoryid%type;
v_categoryname categoryinfo.categoryname%type;

cursor cursor_categoryid is select category from productinfo group by category;

begin
open cursor_categoryid;
loop
fetch cursor_categoryid into v_categoryid;
exit when cursor_categoryid%notfound;
select categoryname into v_categoryname from categoryinfo where categoryid=v_categoryid;
dbms_output.put_line(v_categoryname);

for product in (
select * from productinfo where category=v_categoryid
)
loop
dbms_output.put_line(product.productid||' '||product.productname||' '||product.productprice);
end loop;
end loop;
close cursor_categoryid;
end;
show errors procedure test2;

begin
test2;
end;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值