ORA-01403:未找到数据ORA-06512:第13行

时间:2015-09-01 11:09:29

标签: sql oracle plsql

我正在收到ORA-01403:找不到数据ORA-06512:在第13行尝试执行下面的pl / sql脚本时。 temp_price表包含120行数据,但它表示不是在第二次迭代期间找到的数据。请分享您的专业知识

设置serveroutput;

DECLARE  
   v_prd   t_ctg_prd.prd_cmpnt_id%TYPE;
BEGIN
   FOR i
   IN (SELECT   TRIM (SKU) sku,
                TRIM (price1) price1,
                TRIM (price2) price2,
                TRIM (price3) price3,
                TRIM (price4) price4
         FROM   temp_price where sku not in('6728A','6727A'))         
   LOOP
      BEGIN
      SELECT   prd_cmpnt_id
        INTO   v_prd
        FROM   t_ctg_prd
       WHERE   prd_code = i.sku;  
       DBMS_OUTPUT.PUT_LINE('Prd cmpnt Id of SKU '||i.sku || ' is' || v_prd);
      end;

      IF v_prd is not null
      THEN
      --To insert price for SBA price type
      DBMS_OUTPUT.PUT_LINE('Inserting price for SBA price type to SKU '||i.sku);
          insert into t_ctg_price
                       (PRD_CMPNT_ID
                       ,PRD_PRD_CMPNT_ID
                       ,PRICE_LEVEL
                       ,price_type
                       ,PRICE_AMT
                       ,min_qty
                       ,max_qty
                       ,SALE_EFFCTV_DATE
                       ,sale_end_date
                       ,ENTITY_TYPE_NAME
                       ,CHNL_CODE
                       ,LAST_UPDT_DATE
                       ,USERID
                       ,prod_start_rls_id
                       ,prod_end_rls_id
                       ,price_id
                       ,minPriceAmount
                       ,maxPriceAmount
                       )
                values (seq01.nextval
                       ,v_prd
                       ,'EIP'
                       ,'SBA'
                       ,i.price1
                       ,0
                       ,0
                       ,TO_DATE('09/01/2015', 'mm/dd/yyyy')
                       ,TO_DATE('12/31/9999', 'mm/dd/yyyy')
                       ,'equipment BMG price table'
                       ,'BMG Catalog'
                       ,sysdate
                       ,'nc001v'
                       ,null
                       ,null
                       ,seq01.nextval
                       ,null
                       ,null
                       );  

        --To insert price for BMG price type
         DBMS_OUTPUT.PUT_LINE('Inserting price for BMG price type to SKU '||i.sku);
            insert into t_ctg_price
                       (PRD_CMPNT_ID
                       ,PRD_PRD_CMPNT_ID
                       ,PRICE_LEVEL
                       ,price_type
                       ,PRICE_AMT
                       ,min_qty
                       ,max_qty
                       ,SALE_EFFCTV_DATE
                       ,sale_end_date
                       ,ENTITY_TYPE_NAME
                       ,CHNL_CODE
                       ,LAST_UPDT_DATE
                       ,USERID
                       ,prod_start_rls_id
                       ,prod_end_rls_id
                       ,price_id
                       ,minPriceAmount
                       ,maxPriceAmount
                       )
                values (seq01.nextval
                       ,v_prd
                       ,'EIP'
                       ,'BMG'
                       ,i.price1
                       ,0
                       ,0
                       ,TO_DATE('09/01/2015', 'mm/dd/yyyy')
                       ,TO_DATE('12/31/9999', 'mm/dd/yyyy')
                       ,'equipment BMG price table'
                       ,'BMG Catalog'
                       ,sysdate
                       ,'nc001v'
                       ,null
                       ,null
                       ,seq01.nextval
                       ,null
                       ,null
                       );

            --To insert price for NatlConsumer price type
             DBMS_OUTPUT.PUT_LINE('Inserting price for NatlConsumer price type to SKU '||i.sku);
                insert into t_ctg_price
                       (PRD_CMPNT_ID
                       ,PRD_PRD_CMPNT_ID
                       ,PRICE_LEVEL
                       ,price_type
                       ,PRICE_AMT
                       ,min_qty
                       ,max_qty
                       ,SALE_EFFCTV_DATE
                       ,sale_end_date
                       ,ENTITY_TYPE_NAME
                       ,CHNL_CODE
                       ,LAST_UPDT_DATE
                       ,USERID
                       ,prod_start_rls_id
                       ,prod_end_rls_id
                       ,price_id
                       ,minPriceAmount
                       ,maxPriceAmount
                       )
                values (seq01.nextval
                       ,v_prd
                       ,'EIP'
                       ,'NatlConsumer'
                       ,i.price1
                       ,0
                       ,0
                       ,TO_DATE('09/01/2015', 'mm/dd/yyyy')
                       ,TO_DATE('12/31/9999', 'mm/dd/yyyy')
                       ,'equipment BMG price table'
                       ,'BMG Catalog'
                       ,sysdate
                       ,'nc001v'
                       ,null
                       ,null
                       ,seq01.nextval
                       ,null
                       ,null
                       );   
        --To insert price for NatlContract price type
         DBMS_OUTPUT.PUT_LINE('Inserting price for NatlContract price type to SKU '||i.sku);
                insert into t_ctg_price
                       (PRD_CMPNT_ID
                       ,PRD_PRD_CMPNT_ID
                       ,PRICE_LEVEL
                       ,price_type
                       ,PRICE_AMT
                       ,min_qty
                       ,max_qty
                       ,SALE_EFFCTV_DATE
                       ,sale_end_date
                       ,ENTITY_TYPE_NAME
                       ,CHNL_CODE
                       ,LAST_UPDT_DATE
                       ,USERID
                       ,prod_start_rls_id
                       ,prod_end_rls_id
                       ,price_id
                       ,minPriceAmount
                       ,maxPriceAmount
                       )
                values (seq01.nextval
                       ,v_prd
                       ,NULL
                       ,'NatlContract'
                       ,i.price1
                       ,0
                       ,0
                       ,TO_DATE('09/01/2015', 'mm/dd/yyyy')
                       ,TO_DATE('12/31/9999', 'mm/dd/yyyy')
                       ,'equipment BMG price table'
                       ,'BMG Catalog'
                       ,sysdate
                       ,'nc001v'
                       ,null
                       ,null
                       ,seq01.nextval
                       ,null
                       ,null
                       );

        --Capturing the change history
         DBMS_OUTPUT.PUT_LINE('Capturing the change hisstory for SKU '||i.sku);
            insert into t_ctg_audit
                  (AUDIT_ID
                  ,REASON_CODE
                  ,NOTES
                  ,CREATE_DATE
                  ,MODEL_TYPE_NAME
                  ,CTG_ID
                  ,USERID
                  ,CHNL_CODE)values
                  (seq01.nextval
                         ,'CHGPRICE'
                         ,'EIP Price Testing'
                         ,sysdate
                         ,'handset'
                         ,v_prd
                         ,'nc001v'
                         ,'BMG Catalog')
                   ;
    END IF;
   END LOOP;
END;
/

1 个答案:

答案 0 :(得分:1)

第13行是:

  SELECT   prd_cmpnt_id
        INTO   v_prd
        FROM   t_ctg_prd
       WHERE   prd_code = i.sku;

所以你有一个t_ctg_prd.prd_code中不存在的i.sku值。选择INTO需要返回一些内容。既然您检查了IF v_prd is not null,那么我们可以假设这种情况可以存在。一个选项是将查询包含在一个块中并捕获异常,如下所示:

BEGIN
      SELECT   prd_cmpnt_id
            INTO   v_prd
            FROM   t_ctg_prd
           WHERE   prd_code = i.sku;
       EXCEPTION WHEN ***other*** THEN
          v_prd := NULL;
END