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;
  • 相关阅读:
    特殊类
    Statement和PrepareStatement有什么区别?
    关于${pageContext.request.contextPath }对于工程中的那个目录
    IDEA JSP中报错cannot resolve method println的解决方案
    关于${pageContext.request.contextPath}的理解
    IDEA中引用不到HttpServlet的解决方案
    Serializable接口的意义和用法
    idea Cannot resolve method (最新2020解决办法)
    IDEA Artifacts:Error during artifact deployment问题解决(狂神SSM整合里,报404错误方案)
    IDEA设置自动导入包方法
  • 原文地址:https://www.cnblogs.com/liupeipei/p/7833697.html
Copyright © 2011-2022 走看看