存储过程作用
1. 简化复杂的操作
2. 增加数据的独立性
3. 提高安全性
4. 提高性能
create procedure test
as
begin
dbms_output.put_line('我的第一个存储过程');
end;
/
show serveroutput 让dbms显示成功
set serveroutput on 提示让其打开
存储过程一点被创建就会被存储到数据库服务器上,可以通过视图User_source查看。
select * from user_source where name = ' ' order by line ;
显示存储过程的错误
SHOW ERRRORS procedure produre_name ;
有参数的存储过程
create procedure product_intype_prc (parm_ctgyname in varchar2 ) --输入类型及名称
as
cur_ctgyid categroyinfo.categroyid%type; --存放产品类型编码 输出类型及名称
cur_prtinfo productinfo%rowtype; --存放表productinfo
begin
select catefroyinfo.categroyid into cur_ctgyid
from categroyinfo
where categoryinfo.categroyname = parm_ctgyname ;
if SQL%found then
dbms_output.put_line('-------------------------------------------------------');
dbms_output.put_line(parm_ctgyname || ':');
end if;
for my_prdinfo_rec in
(
select * from PRODUCTINFO where category = cur_ctgyid
)
loop
dbms_output.putline(
'产品名称' || my_prdinfo_rec.productname
|| '产品价格' || my_prdinfo_rec.productprice
|| '产品数量 '|| my_prdinfo_rec.quantity
);
end loop;
end;
执行存储过程, exec product_clouttype_prc('洗衣机', 3000);
使用PL/SQL创建存储过程
1.启动工具,然后点击File|new | program window 菜单,找到produce选项
2. 点击该选项,填写必要选项
3. 点击OK ,弹出格式化数据
4.手工填写具体的业务逻辑
5.格式化脚本
6.修改存储过程的错误
7.创建存储过程
8. 执行存储过程
修改存储过程
直接EIDT
删除 drop produce produce_name ;