我收到了这个错误 ORA-06502 我已经正确定义了每一件事
Posted
技术标签:
【中文标题】我收到了这个错误 ORA-06502 我已经正确定义了每一件事【英文标题】:I'm getting this error ORA-06502 where i have define every thing properly 【发布时间】:2016-05-12 14:03:48 【问题描述】:我创建了一个存储过程,我正在努力解决它,它已成功创建,但我收到错误。我创建了一条记录并使用打开的光标。
我是这样执行的
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;
【问题讨论】:
也许变量 VSLQ_TEXT 太小了?或您类型的任何其他变量,如果您在获取时发生错误 【参考方案1】:您应该将这个:VSLQ_TEXT VARCHAR2(2000);
更改为:
VSLQ_TEXT VARCHAR2(4000);
当您分配VSLQ_TEXT := ' SELECT.....
时,字符串的长度为~ 2963 > 2000 作为您对VSLQ_TEXT
的原始声明
【讨论】:
感谢 Pham 我对 oracle 很陌生 我又遇到一个错误 第 1 行出现错误 ORA-00932:不一致的数据类型:预期 - 得到 - ORA-06512:在“PS_ADMIN.IRE_DE_DUP_PROC5”,第 131 行 ORA-06512:第 9 行 不够清楚。您能说明一下您的程序第 131 行的内容吗? 最有可能是 FETCH。查看 S.RX_DSPNSD_DT 是什么类型。这真的是错误'预期-得到-'吗?没有类型? 第 131 行是 FETCH CLREF INTO REC; @黑客知道了,当FETCH CLREF INTO REC;
,CLREF
有REC_STAT
但REC
没有。您应该像这样将它添加到 TYPE REC_TYP 中:VER_DOSAGE VARCHAR2(2048) , REC_STAT varchar2(10) );
以上是关于我收到了这个错误 ORA-06502 我已经正确定义了每一件事的主要内容,如果未能解决你的问题,请参考以下文章
错误 ORA-06502:PL/SQL:数字或值错误:字符到数字的转换错误 ORA-06512:在第 22 行
收到错误“ORA-06502:PL/SQL:数字或值错误:字符串缓冲区太小”
oracle ORA-06502:PL/SQL:数字或值错误:批量绑定:截断绑定