procedure存储过程创建执行

1.创建存储过程

create or replace procedure PRO_RELATION(SY in char, DY in char) [authid current_user] as
  sql_stmt VARCHAR2(5000);
begin
  --PRO_RELATION是存储过程名称
  --SY,DY是需传值的参数
  --authid current_user解决存储过程中有权限问题
  sql_stmt := 'create table B33_PES.PE_RELATION_A
as
select t1.yhangh,num1,num2 from (
select a.yhangh,listagg(a.ygongh||a.bilifc) within
group (order by bilifc) as num1
from B33_PES.PE_RELATION_TODAY_A a
where a.nowdate=' || DY || ' 
group by a.yhangh
) t1 inner join (
select a.yhangh,listagg(a.ygongh||a.bilifc) within
group (order by bilifc) as num2
from B33_PES.PE_RELATION_TODAY_A a
where a.nowdate=' || SY || ' 
group by a.yhangh
) t2 on t1.yhangh=t2.yhangh and
num1<>num2';
  execute immediate sql_stmt;
  --immediate  表示强制执行该语句
  commit;
end PRO_RELATION;

2.执行存储过程

begin
  --Call the procedure
  pro_relation(sy => :sy, dy => :dy);
end;

变量    类型    值
sy      String    20171031
dy      String    20171130
找到存储过程,右键点击test
在这里插入图片描述
3.存储过程中sql语句用单引号引起,所以sql函数中牵扯到的单引号要用双单引号(转译)
4.打印存储过程中带传入参数的sql脚本是否与自己预想一致需要

begin
  dbms_output.put_line(sql_stmt);
end;

或者右键test中选择DBMS Output tab页查看
5.存储过程中赋给权限需要在参数后加上authid current_user

create or replace procedure pro_relation_zhgsbd(vsymd in char,
                                                vdymd in char) authid current_user is
  sql_select varchar2(8000);
begin
  --......
end pro_reation_zhgsbd;
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值