我创建了一个存储过程,我遇到了困难,我试图打印REC_STAT的值,但是当我试图获得vlaue的时候,另一方面我得到空白值像ab,ab1和ver_dosage我能够打印值但是REC.REC_STAT的问题它是通过dbms_output.put_line打印空白值,但它打印得像这个REC。
declare
EXT_PHARMA_ID varchar2(10) := 'MCL_051270';
begin
TEST_SP('T_MCL_051270_20160314_0019057','MCL',EXT_PHARMA_ID,'0');
end;
/
DBMS_OUTPUT.PUT_LINE是这样打印的
REC
REC
REC
REC
存储过程: -
CREATE OR REPLACE PROCEDURE TEST_SP(Dy_File_Name IN VARCHAR2,
SUPPLIER_CD IN VARCHAR2,
EXT_PHARMA_ID IN OUT VARCHAR2,
FLAG_VALUE IN VARCHAR2)
AS
CLREF SYS_REFCURSOR;
TYPE REC_TYP IS RECORD
(
AB VARCHAR2(256) ,
AB1 VARCHAR2(256) ,
AB2 NUMBER(20),
REC_STAT VARCHAR2(9),
VER_DOSAGE VARCHAR2(20),
OPEN CLREF FOR ('SELECT
S.ABC AS AB,
S.ABC1 AS AB1,
S.ABC2 AS AB2,
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 S.DETL_CLMNS_HASH = S.DETL_CLMNS_HASH THEN ''REC''
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')
LOOP
FETCH CLREF INTO REC;
EXIT WHEN CLREF%NOTFOUND;
dbms_output.put_line(REC.REC_STAT);
IF (REC.REC_STAT = 'UPDT')
THEN
L_UPD_COUNT := L_UPD_COUNT + 1;
ELSIF (REC.REC_STAT = 'DUPL' ) -- DUPLICATE
THEN
L_DUP_COUNT := L_DUP_COUNT + 1;
ELSIF REC.REC_STAT = 'DEL' THEN-- DELETION
L_DEL_COUNT := L_DEL_COUNT +1;
ELSIF REC.REC_STAT = 'DEL_IGNR' THEN
SRC_ID := SRC_FILE_ID_SEQ.NEXTVAL;
END IF;
END LOOP;
END;
答案 0 :(得分:0)
通过查看你的代码,我可以看到程序中缺少一些指针。这种情况只有在null
或&#34;空白&#34;对于REC_STAT
字段。
首先打印动态sql,然后尝试运行它并检查值。希望这些都有帮助。
CREATE OR REPLACE PROCEDURE TEST_SP(
Dy_File_Name IN VARCHAR2,
SUPPLIER_CD IN VARCHAR2,
EXT_PHARMA_ID IN OUT VARCHAR2,
FLAG_VALUE IN VARCHAR2)
AS
CLREF SYS_REFCURSOR;
TYPE REC_TYP
IS
RECORD
(
AB VARCHAR2(256) ,
AB1 VARCHAR2(256) ,
AB2 NUMBER(20),
REC_STAT VARCHAR2(9),
VER_DOSAGE VARCHAR2(20)
);
REC REC_TYP; --Was missing
BEGIN -- was missing
OPEN CLREF FOR
'SELECT
S.ABC AS AB,
S.ABC1 AS AB1,
S.ABC2 AS AB2,
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 S.DETL_CLMNS_HASH = S.DETL_CLMNS_HASH THEN ''REC''
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';
LOOP
FETCH CLREF INTO REC;
EXIT WHEN CLREF%NOTFOUND;
dbms_output.put_line(REC.REC_STAT); --Try to print any other entity returned by the dynamic sql
IF (REC.REC_STAT = 'UPDT') THEN
L_UPD_COUNT := L_UPD_COUNT + 1;
ELSIF (REC.REC_STAT = 'DUPL' ) -- DUPLICATE
THEN
L_DUP_COUNT := L_DUP_COUNT + 1;
ELSIF REC.REC_STAT = 'DEL' THEN-- DELETION
L_DEL_COUNT := L_DEL_COUNT +1;
ELSIF REC.REC_STAT = 'DEL_IGNR' THEN
SRC_ID := SRC_FILE_ID_SEQ.NEXTVAL;
END IF;
END LOOP;
END;
答案 1 :(得分:0)
如上所述Avrajit,请修改代码,我也可以在case
语句的代码中看到:
WHEN S.DETL_CLMNS_HASH = S.DETL_CLMNS_HASH THEN ''REC''
由于上述条件,您将输出为REC
,此语句始终为真。