我收到这个错误ORA-06502,我已经正确定义了每件事

时间:2016-05-12 14:03:49

标签: oracle plsql

我创建了一个存储过程,我在这个过程中遇到了相同的问题并且创建成功并且我收到了错误。我在哪里创建了一个记录并使用了开放光标。

我这样执行

declare

DUP_FILE_NAME varchar2(100) := 'T_MCL_051270_20160314_001.039_duplicates_20160510155707';

begin

IRE_DE_DUP_PROC5('T_MCL_051270_20160314_00121914',DUP_FILE_NAME ,'DE_DUP_OUTPUT','DE_DUP_DUPLICATES');

end;

Error
    Error at line 1
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-06512: at "PS_ADMIN.IRE_DE_DUP_PROC5", line 70
    ORA-06512: at line 9 

存储过程

CREATE OR REPLACE PROCEDURE IRE_DE_DUP_PROC5(Dy_File_Name    IN     VARCHAR2,
                                             DUP_FILE_NAME  IN OUT    VARCHAR2,
                                             DE_DUP_OUTPUT_NAME IN VARCHAR2,
                                             DE_DUP_DUPLICATES_NAME IN VARCHAR2)

AS

        CLREF  SYS_REFCURSOR;    
        OUT_FILE         UTL_FILE.FILE_TYPE;
        DE_DUP_FILE      UTL_FILE.FILE_TYPE;
        OUT_DIR          VARCHAR2 (200) := DE_DUP_OUTPUT_NAME;
        OUT_DE_DUP_DIR   VARCHAR2 (300) := DE_DUP_DUPLICATES_NAME;
        INPUT_FILE_NAME  VARCHAR2(200) := REGEXP_REPLACE(DUP_FILE_NAME,'_duplicates_[0-9]+','');
        EXT_PHARMA_ID1   VARCHAR2(80);
        L_REC_COUNT NUMBER :=0;
        L_DUP_COUNT NUMBER :=0;
        L_UPD_COUNT NUMBER :=0;
        L_DEL_COUNT NUMBER :=0;
        VSLQ_TEXT VARCHAR2(2000);

TYPE REC_TYP IS RECORD

   (

        TRANS_GUID        VARCHAR2(60),
        PREV_TRANS_GUID  VARCHAR2(255), 
        TRN_STAT    NUMBER(1),
        INT_PHARMACY_ID VARCHAR2(20),
        EXT_PHARMACY_ID VARCHAR2(80),
        PHARMACY_NAME   VARCHAR2(50),
        PHARMACY_ADDRESS VARCHAR2(512),
        SP_PSCR_DRUG_CD VARCHAR2(800),
        PS_DRUG_IPU_CD VARCHAR2(20),    
        IPU_Value VARCHAR2(4),
        PS_DRUG_DESC VARCHAR2(150),
        DS_DRUG_PACK_SIZE VARCHAR2(400),
        R_ID  VARCHAR2(40),
        R_ITEM_SEQ NUMBER(38),
        R_REPEAT_STATUS VARCHAR2(10),
        R_TYPE   VARCHAR2(10),
        EX_STATUS VARCHAR2(800),
        PS_QTY VARCHAR2(400),
        NR_HM_IND  NUMBER(38),
        R_DSPNSD_DT DATE,
        R_DSPNSD_TM VARCHAR2(20),
        SP_DSPNSD_DRUG_CD VARCHAR2(20),
        DS_DRUG_IPU_CD VARCHAR2(20),
        IPU_Value2 VARCHAR2(4),
        DS_DRUG_DESC VARCHAR2(150), 
        GC_USE_MARKER NUMBER(38),
        DS_UNIT_OF_QTY VARCHAR2(800), 
        DS_QTY VARCHAR2(400),
        EUR_Value1 VARCHAR2(4),    
        CT_OF_DSPNSD_QTY NUMBER(38),
        VER_DOSAGE VARCHAR2(2048)          
   );

    REC   REC_TYP;    

BEGIN 

      VSLQ_TEXT := ' SELECT
          /*+ use_hash(s,H) leading(s h) */

         S.TRANS_GUID AS TRANS_GUID,
          H.TRANS_GUID AS PREV_TRANS_GUID,
          CASE
            WHEN S.DEL_IND = 1 AND H.DEL_IND = 0 THEN 2
            WHEN H.TRANS_GUID IS NULL
            THEN 0
            ELSE 1
          END                             AS TRN_STAT,
          P.INTR_PHARMACY_ID              AS INT_PHARMACY_ID ,
          SUBSTR(S.EXTRNL_PHARMACY_ID,-6) AS EXT_PHARMACY_ID ,
          S.PHARMACY_NM                   AS PHARMACY_NAME ,
          S.PHARMACY_ADDR                 AS PHARMACY_ADDRESS,
          S.SUPPLIERS_PSCR_DRUG_CD        AS SP_PSCR_DRUG_CD,
          S.PSCR_DRUG_IPU_CD              AS PS_DRUG_IPU_CD,
          ''IPU''                           AS IPU_Value,
          S.PSCR_DRUG_DESC                AS PS_DRUG_DESC,
          S.DSPNSD_DRUG_PACK_SIZE         AS DS_DRUG_PACK_SIZE,
          S.RX_ID                         AS R_ID,
          S.RX_ITEM_SEQ                   AS R_ITEM_SEQ,
          S.RX_REPEAT_STATUS              AS R_REPEAT_STATUS,
          S.RX_TYP                        AS R_TYPE,
          S.EXMT_STATUS                   AS EX_STATUS,
          S.PSCR_QTY                      AS PS_QTY,
          S.NRSG_HM_IND                   AS NR_HM_IND,
          S.RX_DSPNSD_DT                  AS R_DSPNSD_DT,
          S.RX_DSPNSD_TM                  AS R_DSPNSD_TM,
          S.SUPPLIERS_DSPNSD_DRUG_CD      AS SP_DSPNSD_DRUG_CD,
          S.DSPNSD_DRUG_IPU_CD            AS DS_DRUG_IPU_CD,
          ''IPU''                           AS IPU_Value2,
          S.DSPNSD_DRUG_DESC              AS DS_DRUG_DESC,
          S.GENERIC_USE_MARKER            AS GC_USE_MARKER,
          S.DSPNSD_UNIT_OF_QTY            AS DS_UNIT_OF_QTY,
          S.DSPNSD_QTY                    AS DS_QTY,
          ''EUR''                           AS EUR_Value1,
          S.COST_OF_DSPNSD_QTY            AS CT_OF_DSPNSD_QTY ,
          S.VERBOSE_DOSAGE                AS VER_DOSAGE,
          CASE WHEN S.DEL_IND = 1 AND H.DEL_IND = 0 THEN ''DEL''
               WHEN S.DEL_IND = 1 AND H.DEL_IND IS NULL THEN ''DEL_IGNR''
               WHEN S.DETL_CLMNS_HASH <> H.DETL_CLMNS_HASH THEN ''UPDT''
               WHEN S.DETL_CLMNS_HASH = H.DETL_CLMNS_HASH THEN ''DUPL''
               WHEN H.DETL_CLMNS_HASH IS NULL THEN ''NEW''
               ELSE ''ERR''
           END AS REC_STAT    
        FROM
          (SELECT stg.*,
            row_number() over ( partition BY key_clmns_hash, rx_dspnsd_dt, del_ind ORDER BY 1) AS RN
          FROM  '   || Dy_File_Name || '   stg
          ) s
        LEFT JOIN ps_pharmacy p ON s.extrnl_pharmacy_id = p.extrnl_pharmacy_id  
        LEFT JOIN ps_rx_hist H
        ON h.key_clmns_hash        = s.key_clmnS_hash
        AND h.rx_dspnsd_dt         = s.rx_dspnsd_dt
        AND s.supplier_pharmacy_cd = h.SUPPLIER_PHARMACY_CD
        WHERE s.RN                 = 1';   

      OPEN CLREF  FOR VSLQ_TEXT;
      LOOP

      FETCH CLREF  INTO REC;
      EXIT WHEN CLREF%NOTFOUND;

      /*FOR REC IN (') 

        LOOP*/


            DBMS_OUTPUT.PUT_LINE('"'|| REC.TRANS_GUID || '"'||REC.PREV_TRANS_GUID || '"|"' || REC.TRN_STAT || '"|'  || REC.INT_PHARMACY_ID || '|' || substr(REC.EXT_PHARMACY_ID,-6) || '|"' ||
                         REC.PHARMACY_NAME || '"|"' || REC.PHARMACY_ADDRESS || '"|' || REC.SP_PSCR_DRUG_CD || '|' || REC.PS_DRUG_IPU_CD || '|"' || REC.IPU_Value || '"|"' || REC.PS_DRUG_DESC || 
                         '"|' || REC.DS_DRUG_PACK_SIZE || '|"' || REC.R_ID || '"|' || REC.R_ITEM_SEQ || '|' || REC.R_REPEAT_STATUS || '|"'|| REC.R_TYPE || '"|"'    
                        || REC.EX_STATUS || '"|' || REC.PS_QTY || '|' || REC.NR_HM_IND || '|'|| to_char(to_date(REC.R_DSPNSD_DT,'dd-mon-yy' ),'yyyymmdd')    
                        || '|'|| REC.R_DSPNSD_TM || '|' || REC.SP_DSPNSD_DRUG_CD || '|' || REC.DS_DRUG_IPU_CD || '|"' || REC.IPU_Value2 || '"|"'    
                        || REC.DS_DRUG_DESC  || '"|' || REC.GC_USE_MARKER || '|"' || REC.DS_UNIT_OF_QTY || '"|' || REC.DS_QTY || '|"' || REC.EUR_Value1    
                        || '"|' || REC.CT_OF_DSPNSD_QTY || '|"' || REC.VER_DOSAGE || '"');

        END LOOP;
        CLOSE CLREF;
 END;

1 个答案:

答案 0 :(得分:0)

您应该将此更改为:VSLQ_TEXT VARCHAR2(2000);

VSLQ_TEXT VARCHAR2(4000);

当您指定VSLQ_TEXT := ' SELECT.....时,字符串的长度为〜 2963 &gt; 2000 作为VSLQ_TEXT

的原始声明