oracle 存储过程(三)

create or replace procedure ecs_customdetail_0929   --创建存储过程
 is
  longerstation VARCHAR2(50);    --定义变量
  type v_cursor is ref cursor;      --变义游标
detailid v_cursor;
in_id v_cursor;
v_str varchar2(200);
in_str varchar2(200);
tab_detailid VARCHAR2(32);
in_stationname VARCHAR2(50);

begin
  v_str := 'select id from customdetail_0927';

 OPEN detailid FOR v_str ;     --打开游标

 LOOP FETCH detailid INTO tab_detailid;   --循环游标
  
        EXIT WHEN detailid%NOTFOUND;   --当找不到数据的时候退出循环
         in_str :='select stationname from bak0902_sell_customerdetail  where id = '''||tab_detailid||'''';  --变量的连接方法
        OPEN in_id FOR in_str ;
        longerstation :='a';    --给变量赋值
         loop fetch in_id into  in_stationname;


          exit when in_id%notfound;
          if length(in_stationname)>=length(longerstation)    then longerstation :=in_stationname;
          end if;
          end loop;
          DBMS_OUTPUT.PUT_LINE(longerstation);
          insert into B_BUS_SELCUSTOMERDETAILDEL1010 select * from bak0902_sell_customerdetail where id=tab_detailid and stationname=longerstation;   --把查出来的数据插入另一数据表里
        delete from bak0902_sell_customerdetail where id=tab_detailid and stationname=longerstation;--删除相应的数据
          commit;
         CLOSE in_id;
end loop;
CLOSE detailid;
END ecs_customdetail_0929;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值