안녕하세요
프로시져를 좀 봐주셨으면 해서 이렇게 글을 습니다.
아래 프로시져를 오라클에서 실행하면 디버깅해보니
tquery는 결국 이런식으로 나옵니다
SELECT
C.TPT_INPUT_DATE TPT_INPUT_DATE
, C.PART_CD PART_CD
, C.PART_NM PART_NM
, C.TROUBLE_STATUS TROUBLE_STATUS
, C.SEND_LOCATION SEND_LOCATION
, C.SEND_DATE SEND_DATE
, C.PITURE_YN PITURE_YN
, B.CAR_NM_KR CAR_NM
, A.ITEM_CD ITEM_CD
, FC_GET_YYYY_MM_DD(A.TMMAKE_DT) TMMAKE_DT
, A.MILEAGE MILEAGE
, A.TROUBLE_DETAIL TROUBLE_DETAIL
, A.ETC ETC
, A.ETC_V ETCV
, A.IMPUTATION_CD IMPUTATION_CD
, A.IMPUTATION_OUT IMPUTATION_OUT
, FC_GET_YYYY_MM_DD(A.REPAIR_DT) REPAIR_DT
, A.TM_NO
, A.IN_NO
, C.DC0235 DC0235
from VW_H_TM_ALL A INNER JOIN M_CAR B ON A.CAR_CD = B.CAR_CD
INNER JOIN M_TROUBLE_INFO C ON A.TM_NO = C.TM_NO
WHERE 1=1
and C.TPT_INPUT_DATE >= TO_DATE('2013-07-21');
이상한부분은 저 쿼리를 그냥 실행하면 결과가 나옵니다.
근데 프로시져에서 실행을 하면 결과가 없습니다. -_-?
원인을 모르겠어서 좀 이렇게 여쭤보려고합니다.
이유가 뭘까요?
헤더
TYPE R_CURSOR IS REF CURSOR;
PROCEDURE SP_GET_LIST(
p_Cursor OUT sys_refcursor
--,P_TPT_DATE_START in DATE :=''
,P_IMPUTATION_CD IN VARCHAR2 :=''
,P_IMPUTATION_NM IN VARCHAR2 :=''
,P_TROUBLE_STATUS IN VARCHAR2 :=''
,P_SEND_LOCATION IN VARCHAR2 :=''
-- ,P_TPT_DATE_END IN DATE
, p_NoFlg in varchar2 := '' -- TM_NO, RO_NO, VIN_NO, PLT_NO
, p_No in varchar2 := ''
, p_DateFlg in varchar2 := ''
, p_DateS in varchar2 := ''
, p_DateE in varchar2 := ''
);
바디
PROCEDURE SP_GET_LIST(
p_Cursor OUT sys_refcursor
,P_IMPUTATION_CD IN VARCHAR2 :=''
,P_IMPUTATION_NM IN VARCHAR2 :=''
,P_TROUBLE_STATUS IN VARCHAR2 :=''
,P_SEND_LOCATION IN VARCHAR2 :=''
, p_NoFlg in varchar2 := '' -- TM_NO, RO_NO, VIN_NO, PLT_NO
, p_No in varchar2 := ''
, p_DateFlg in varchar2 := ''
, p_DateS in varchar2 := ''
, p_DateE in varchar2 := ''
)
IS
T_CURSOR sys_refcursor;
V_DATEs VARCHAR(8);
V_DATEe VARCHAR(8);
T_QUERY VARCHAR2(5000);
BEGIN
if p_DateFlg = 'REPAIR_DT' then -- 수리일자
V_DATEs := REPLACE(p_DateS,'-','');
V_DATEe := REPLACE(p_DateE,'-','');
END IF;
T_QUERY := '
SELECT
C.TPT_INPUT_DATE TPT_INPUT_DATE
, C.PART_CD PART_CD
, C.PART_NM PART_NM
, C.TROUBLE_STATUS TROUBLE_STATUS
, C.SEND_LOCATION SEND_LOCATION
, C.SEND_DATE SEND_DATE
, C.PITURE_YN PITURE_YN
, B.CAR_NM_KR CAR_NM
, A.ITEM_CD ITEM_CD
, FC_GET_YYYY_MM_DD(A.TMMAKE_DT) TMMAKE_DT
, A.MILEAGE MILEAGE
, A.TROUBLE_DETAIL TROUBLE_DETAIL
, A.ETC ETC
, A.ETC_V ETCV
, A.IMPUTATION_CD IMPUTATION_CD
, A.IMPUTATION_OUT IMPUTATION_OUT
, FC_GET_YYYY_MM_DD(A.REPAIR_DT) REPAIR_DT
, A.TM_NO
, A.IN_NO
, C.DC0235 DC0235
from VW_H_TM_ALL A INNER JOIN M_CAR B ON A.CAR_CD = B.CAR_CD
INNER JOIN M_TROUBLE_INFO C ON A.TM_NO = C.TM_NO
WHERE 1=1
';
if p_DateFlg = 'IN_DT' then -- 입고일자
T_QUERY := T_QUERY || ' and A.IN_DT >= ''' || V_DATEs || ''' and A.IN_DT <= ''' || V_DATEe || '''';
elsif p_DateFlg = 'REPAIR_DT' then -- 수리일자
T_QUERY := T_QUERY || ' and A.REPAIR_DT >= ''' || V_DATEs || ''' and A.REPAIR_DT <= ''' || V_DATEe || '''';
elsif p_DateFlg = 'TPT_INPUT_DATE' then --
T_QUERY := T_QUERY || ' and C.TPT_INPUT_DATE >= TO_DATE('''||p_DateS||''')';-- ||' and C.TPT_INPUT_DATE < TO_DATE('''||p_DateE||''')';
end if;
T_QUERY := T_QUERY || case when P_IMPUTATION_CD is null then ' ' else ' and A.IMPUTATION_CD like ''' || P_IMPUTATION_CD || '%''' end;
T_QUERY := T_QUERY || case when P_IMPUTATION_NM is null then ' ' else ' and A.IMPUTATION_OUT LIKE ''' || P_IMPUTATION_NM || '%''' end;
T_QUERY := T_QUERY || case when P_TROUBLE_STATUS is null then ' ' else ' and C.TROUBLE_STATUS like ''' || P_TROUBLE_STATUS || '%''' end;
T_QUERY := T_QUERY || case when P_SEND_LOCATION is null then ' ' else ' and C.SEND_LOCATION like ''' || P_SEND_LOCATION || '%''' end;
if p_NoFlg = 'TM_NO' then -- TM No
T_QUERY := T_QUERY || case when p_No is null then ' ' else ' and A.TM_NO like ''' || p_No || '%''' end;
elsif p_NoFlg = 'TM_SERIAL_NO' then -- TM Serial No
T_QUERY := T_QUERY || case when p_No is null then ' ' else ' and A.TM_SERIAL_NO like ''' || p_No || '%''' end;
end if;
DBMS_OUTPUT.PUT_LINE(T_QUERY);
OPEN T_CURSOR FOR T_QUERY
;
p_CURSOR := T_CURSOR;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise