zoukankan      html  css  js  c++  java
  • oracle存储过程中循环插入数据

    //oracle 循环插入数据
    
    procedure Insert_WData(  p_CODE1 ao_model.code1%type, 
                                        p_BRANDID    ao_model.brandid%type,
                                        p_CODE  varchar2, 
                                        p_CONF_VAL   varchar2,
                                        p_DESC  varchar2, 
                                        p_CODE2 varchar2, 
                                        p_DESC  varchar2,
                                        ErrOut             in out varchar2) is
      begin
        --参数
        declare
          startposition1 number(10);
          len1           number(10);
          startposition2 number(10);
          len2           number(10);
          startposition3 number(10);
          len3           number(10);
          output1        varchar2(1024);
          output2        varchar2(1024);
          output3        varchar2(1024);
          num            number(1);
        begin
          startposition1 := 1;
          startposition2 := 1;
          startposition3 := 1;
          loop
            select instr(p_CODE, '|', startposition1)
              into len1
              from dual;
            select instr(p_CONF_VAL, '|', startposition2)
              into len2
              from dual;
            select instr(p_DESC, '|', startposition3)
              into len3
              from dual;
            if len1 != 0 then
              begin
                select substr(p_CODE,
                              startposition1,
                              len1 - startposition1)
                  into output1
                  from dual;
                select substr(p_CONF_VAL,
                              startposition2,
                              len2 - startposition2)
                  into output2
                  from dual;
                select substr(p_DESC,
                              startposition3,
                              len3 - startposition3)
                  into output3
                  from dual;
                num := 0;
                select count(*)
                  into num
                  from ao_model a
                 where a.c0084_brandid = p_BRANDID
                   and a.c0001_code1 = p_CODE1
                   and a.c0001_code = output1;
                if num >= 1 then
                  update ao_model b
                     set b.conf_val = output2
                   where b.c0084_brandid = p_BRANDID
                     and b.c0001_code1 = p_CODE1
                     and b.c0001_code = output1;
    
                else
                  insert into ao_model
                    (C0001_CODE1,
                     C0084_BRANDID,
                     C0001_CODE,
                     CONF_VAL,
                     DESC)
                  values
                    (p_CODE1,
                     p_BRANDID,
                     output1 || '',
                     output2 || '',
                     output3 || '');
                end if;
                commit;
              end;
            else
              begin
                select substr(p_CODE, startposition1)
                  into output1
                  from dual;
                select substr(p_CONF_VAL, startposition2)
                  into output2
                  from dual;
                select substr(p_DESC, startposition3)
                  into output3
                  from dual;
                num := 0;
                select count(*)
                  into num
                  from ao_model a
                 where a.c0084_brandid = p_BRANDID
                   and a.c0001_code1 = p_CODE1
                   and a.c0001_code = output1;
                if num >= 1 then
                  update ao_model b
                     set b.conf_val = output2
                   where b.c0084_brandid = p_BRANDID
                     and b.c0001_code1 = p_CODE1
                     and b.c0001_code = output1;
    
                else
                  insert into ao_model
                    (C0001_CODE1,
                     C0084_BRANDID,
                     C0001_CODE,
                     CONF_VAL,
                     DESC)
                  values
                    (p_CODE1,
                     p_BRANDID,
                     output1 || '',
                     output2 || '',
                     output3 || '');
                end if;
                commit;
              end;
              exit;
            end if;
            startposition1 := len1 + 1;
            startposition2 := len2 + 1;
            startposition3 := len3 + 1;
          end loop;
        end;
      EXCEPTION
        WHEN OTHERS THEN
          ErrOut := SQLERRM;
          rollback;
    
      end Insert_WParamStatusData;
  • 相关阅读:
    支付方法及注意事项
    网站负载均衡策略
    工作成长
    java内存机制
    关于前途的一些思考
    git记录
    关于博客
    如何为公司创造价值?
    遍历集合方法总结
    二叉树和红黑二叉树
  • 原文地址:https://www.cnblogs.com/liupeipei/p/7833697.html
Copyright © 2011-2022 走看看