oracle中创建存储过程,以及存储过程中调用游标
admin
2023-05-11 09:22:04
0

CREATE OR REPLACE PROCEDURE aa

 is

   CURSOR prodCombind_cur IS SELECT * FROM proddata.product_combind_info pci;

   prodCombindInfo prodCombind_cur%ROWTYPE;

   id_marketproduct_info varchar2(32);


   CURSOR combindPackage_cur IS SELECT * FROM proddata.combind_package_info;

   combindPackageInfo combindPackage_cur%ROWTYPE;

   id_package_info varchar2(32);


   tmpid_marketproduct_info varchar2(32);

   

   --查询包含有要删除的子产品的产品组合

    CURSOR delete_combind_cur(id_sub_product VARCHAR2) IS 

       select * from proddata.product_combind_rel pcr where pcr.id_product=id_sub_product;

    delCombindInfo delete_combind_cur%ROWTYPE;


begin

    begin

--marketproduct_info表中已经存在的a57,和a72先删除

     select m.id_marketproduct_info into tmpid_marketproduct_info from  proddata.marketproduct_info m where m.marketproduct_code='MP02000057' and m.is_combined='1';

     --删除市场产品对应的产品组合

     OPEN delete_combind_cur(tmpid_marketproduct_info); --打开游标;

     loop   

         FETCH delete_combind_cur INTO delCombindInfo; --从游标中取值要删除的产品组合的id

                 --首先删除套餐下所有的子产品

                 delete from proddata.combind_package_rel cpr where cpr.id_combind_package_info in (

                     select cpi.id_combind_package_info from proddata.combind_package_info cpi 

                     where cpi.id_product_combind_info=delCombindInfo.id_product_combind_info);

                 --在删除套餐

                 delete from proddata.combind_package_info cpi 

                     where cpi.id_product_combind_info=delCombindInfo.id_product_combind_info;


                --删除产品组合下的子产品

                delete from proddata.product_combind_rel pcr where pcr.id_product_combind_info=delCombindInfo.id_product_combind_info;

                delete from proddata.marketproduct_rule_param mrp where mrp.id_marketproduct_info= delCombindInfo.id_product_combind_info; 

                delete from proddata.marketproduct_department md where md.id_marketproduct_info=delCombindInfo.id_product_combind_info;

                delete from proddata.product_combind_info pci where pci.id_product_combind_info=delCombindInfo.id_product_combind_info;

         exit when delete_combind_cur%notfound;  

     end loop;

     close delete_combind_cur; --关闭游标

     delete from proddata.marketproduct_rule_param mr where mr.id_marketproduct_info= tmpid_marketproduct_info;

     delete from proddata.marketproduct_department md where md.id_marketproduct_info=tmpid_marketproduct_info;

     delete from proddata.marketproduct_plan_duty_rel mpdr where mpdr.id_marketproduct_info=tmpid_marketproduct_info;

     delete from proddata.marketproduct_info m where m.id_marketproduct_info=tmpid_marketproduct_info;  

     --

     select m.id_marketproduct_info into tmpid_marketproduct_info from  proddata.marketproduct_info m  where m.marketproduct_code='MP02000072' and m.is_combined='1';

     --删除市场产品对应的产品组合

     OPEN delete_combind_cur(tmpid_marketproduct_info); --打开游标;

     loop   

         FETCH delete_combind_cur INTO delCombindInfo; --从游标中取值

                  --首先删除套餐下所有的子产品

                 delete from proddata.combind_package_rel cpr where cpr.id_combind_package_info in (

                     select cpi.id_combind_package_info from proddata.combind_package_info cpi 

                     where cpi.id_product_combind_info=delCombindInfo.id_product_combind_info);

                 --在删除套餐

                 delete from proddata.combind_package_info cpi 

                     where cpi.id_product_combind_info=delCombindInfo.id_product_combind_info;

                --删除产品组合下的子产品

                delete from proddata.product_combind_rel pcr where pcr.id_product_combind_info=delCombindInfo.id_product_combind_info;

                delete from proddata.marketproduct_rule_param mrp where mrp.id_marketproduct_info= delCombindInfo.id_product_combind_info; 

                delete from proddata.marketproduct_department md where md.id_marketproduct_info=delCombindInfo.id_product_combind_info;

                delete from proddata.product_combind_info pci where pci.id_product_combind_info=delCombindInfo.id_product_combind_info;

         exit when delete_combind_cur%notfound;  

     end loop;

     close delete_combind_cur; --关闭游标

     delete from proddata.marketproduct_rule_param mr where mr.id_marketproduct_info= tmpid_marketproduct_info;

     delete from proddata.marketproduct_department md where md.id_marketproduct_info=tmpid_marketproduct_info;

     delete from proddata.marketproduct_plan_duty_rel mpdr where mpdr.id_marketproduct_info=tmpid_marketproduct_info;

     delete from proddata.marketproduct_info m where m.id_marketproduct_info=tmpid_marketproduct_info;

     --

     commit;

     exception

        when others then

           dbms_output.put_line('删除a57和a72产品时,出现异常');

     end;

     

--需要处理的表:将表product_combind_info中的数据,copy到表marketproduct_info中;

 for prodCombindInfo in prodCombind_cur loop

    begin

       select m.id_marketproduct_info into id_marketproduct_info from proddata.marketproduct_info m

         where m.id_marketproduct_info = prodCombindInfo.id_product_combind_info;

       dbms_output.put_line('product已经存在的:'|| prodCombindInfo.marketproduct_code ||'-'|| prodCombindInfo.MARKETPRODUCT_NAME);

    exception

         --这里抛出异常,是表示上面的select没有查询到记录引起的

         when others then

           dbms_output.put_line('product不存在的:'|| prodCombindInfo.marketproduct_code||'-'||prodCombindInfo.marketproduct_name);

           insert into proddata.marketproduct_info

             (CREATED_BY,

              CREATED_DATE,

              UPDATED_BY,

              UPDATED_DATE,

              marketproduct_code,

              marketproduct_name,

              product_class,

              status,

              is_combined,

              id_marketproduct_info,

              department_code,

              version,

              policy_type)

           values

             (prodCombindInfo.CREATED_BY,

              prodCombindInfo.CREATED_DATE,

              prodCombindInfo.UPDATED_BY,

              prodCombindInfo.UPDATED_DATE,

              prodCombindInfo.marketproduct_code,

              prodCombindInfo.marketproduct_name,

              prodCombindInfo.MAIN_PRODUCT_CLASS,

              prodCombindInfo.status,

              '1',

              prodCombindInfo.ID_PRODUCT_COMBIND_INFO,

              prodCombindInfo.DEPARTMENT_CODE,

              prodCombindInfo.version,

              prodCombindInfo.POLICY_TYPE);

    end;

 end loop;

 commit;

--需要处理的表:将表combind_package_info中的数据,copy到表package_info中

 for combindPackageInfo in combindPackage_cur loop

    begin

        select p.id_package_info into id_package_info from  proddata.package_info p where p.id_package_info=combindPackageInfo.ID_COMBIND_PACKAGE_INFO;

         dbms_output.put_line('package已经存在的:'|| combindPackageInfo.PACKAGE_CODE||'-'||combindPackageInfo.PACKAGE_NAME);

    exception

         --这里抛出异常,是表示上面的select没有查询到记录引起的

         when others then

            insert into  proddata.package_info

               (ID_PACKAGE_INFO,

                ID_MARKETPRODUCT_INFO,

                PACKAGE_CODE,

                PACKAGE_NAME,

                CREATED_BY,

                CREATED_DATE,

                UPDATED_BY,

                UPDATED_DATE,

                status)

             values

               (combindPackageInfo.ID_COMBIND_PACKAGE_INFO,

                combindPackageInfo.ID_PRODUCT_COMBIND_INFO,

                combindPackageInfo.PACKAGE_CODE,

                combindPackageInfo.PACKAGE_NAME,

                combindPackageInfo.CREATED_BY,

                combindPackageInfo.CREATED_DATE,

                combindPackageInfo.UPDATED_BY,

                combindPackageInfo.UPDATED_DATE,

                '1');

            dbms_output.put_line('package不存在的:'|| combindPackageInfo.PACKAGE_CODE||'-'||combindPackageInfo.PACKAGE_NAME);

    end;

 end loop;

  commit;

end;


相关内容

热门资讯

以军士兵集体丢掉武器抗命,大喊... 据凤凰卫视报道,以色列国防军一军事基地7月30日发生士兵抗命事件,约120名士兵抗议指挥官做法,将武...
蒋成华任商务部副部长 国务院任免国家工作人员。任命蒋成华为商务部副部长。免去蒋成华的商务部国际贸易谈判副代表职务。
伊朗驻华大使:在军事威胁下,不... 新华社北京7月31日电(记者刁慧琳) 伊朗驻华大使法兹里7月28日表示,伊美回到谈判桌的前提是美国必...
伊朗革命卫队在霍尔木兹海峡击中... 当地时间31日,伊朗伊斯兰革命卫队发布声明称,革命卫队海军当天在霍尔木兹海峡击中并扣留了两艘违反禁令...
美媒:特朗普,遇到了一个更强硬... 据《纽约时报》7月29日报道,就在特朗普总统看似放弃战事升级计划几天后,美国再次与伊朗交火。上周末,...
女子做气管镜时不幸身亡,丈夫称... 7月29日,西安刘先生反映妻子在当地医院做支气管镜检查时死亡,看监控时发现医生疑有违规操作。刘先生表...
全网“帮卖西瓜”,然后呢? 近日,河南部分地区西瓜滞销的消息在网上热度很高。很多地方也伸出援手:有景区收购千斤西瓜、免费赠予游客...
美媒:乌克兰袭击伊朗船只,险引... 据《纽约时报》7月28日报道,据伊朗和西方官员称,伊朗曾考虑攻击乌克兰的一个港口,以报复乌克兰对一艘...
20年里,他只画美女,用东方风... 迈进KIM在上海的工作室,迎面是一整墙的美女们。她们像是刚从一场时髦的沙龙里退场,或倚或立,眉宇间是...
Google在港推出AI代理G... 观点网讯:7月29日,Google在香港推出AI代理Gemini Spark,该代理可全天候在后台运...