我已經創建了一個存儲過程,在那裏我卡住了,我試圖打印REC_STAT的值,但我得到其他值當我試圖得到類似ab,ab1和ver_dosage的vlaue時,我可以打印這些值,但是REC.REC_STAT有問題,它通過dbms_output.put_line打印空白值,但打印像這樣的REC。我試圖打印sql查詢的值,但它是打印不同的值
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;
由於它正在打印REC我假設您的CASE語句中的以下條件得到滿足WHD S.DETL_CLMNS_HASH = S.DETL_CLMNS_HASH然後'REC''因此您的DBMS_OUTPUT正在打印REC。此外,您還沒有在IF語句中處理IF(REC.REC_STAT ='REC')條件。 –