我被困在比较plsql编程中的两个日期。
我有2个存储过程。第一个存储过程将日期列返回为OUT
param。
我正在传递第一个输出参数作为第二个存储过程的输入参数。
但我的查询没有返回正确的值。
存储过程#1:
PROCEDURE SP_FIRST_COMPLETE(TASK_ID IN VARCHAR2, FIRST_COMPLETE_DT OUT DATE)
IS
...
BEGIN
...
...
DBMS_OUTPUT.PUTLINE('First completed dt is:= '||FIRST_COMPLETE_DT);
.....
end;
存储过程#2:
PROCEDURE SP_NOT_FIRST_COMPLETE(TASK_ID IN VARCHAR2, FIRST_COMPLETE_DT IN DATE, FIRST_COMPLETE_DT1 OUT DATE)
IS
....
BEGIN
DBMS_OUTPUT.PUTLINE('First completed dt is:= '||FIRST_COMPLETE_DT);
FOR R_ROW IN (SELECT ........ FROM .... WHERE EVENT_DT > FIRST_COMPLETE_DT ORDER BY EVENT_DT
LOOP
DBMS_OUTPUT.PUTLINE('First completed dt is:= '||FIRST_COMPLETE_DT||' QUERY RESULT DATE :='||R_ROW.EVENT_DT);
.....
END;
1ST STORED PROC OUTPUT
First completed dt is:= 14-FEB-14
2ND STORED PROC OUTPUT
First completed dt is:= 14-FEB-14
First completed dt is:= 14-FEB-14 QUERY RESULT DATE := 28-FEB-12
当我在SQL中运行查询时,它给出了正确的结果。
select ... from.... where event_dt > '18-FEB-14' order by event_dt;
请帮忙。
由于 SARMA
答案 0 :(得分:0)
请查看它应该是什么,并与您的代码进行比较:
CREATE OR REPLACE PROCEDURE SP_FIRST_COMPLETE (
TASK_ID IN VARCHAR2,
FIRST_COMPLETE_DT IN OUT DATE)
IS
BEGIN
DBMS_OUTPUT.PUT_LINE ('First date is:= ' ||
TO_DATE(FIRST_COMPLETE_DT, 'DD-MM-YYYY', 'NLS_DATE_LANGUAGE=ENGLISH')
);
END;
CREATE OR REPLACE PROCEDURE SP_NOT_FIRST_COMPLETE (
TASK_ID IN VARCHAR2,
FIRST_COMPLETE_DT IN DATE,
FIRST_COMPLETE_DT1 OUT DATE)
IS
BEGIN
FIRST_COMPLETE_DT1 := TO_DATE(FIRST_COMPLETE_DT, 'DD-MM-YYYY', 'NLS_DATE_LANGUAGE=ENGLISH');
DBMS_OUTPUT.PUT_LINE ('Second date is:= ' || FIRST_COMPLETE_DT1);
END;
执行
DECLARE
THE_OUTPUT_DATE1 DATE ;
THE_OUTPUT_DATE2 DATE ;
BEGIN
THE_OUTPUT_DATE1 := SYSDATE;
SP_FIRST_COMPLETE (1, THE_OUTPUT_DATE1);
SP_NOT_FIRST_COMPLETE (1, THE_OUTPUT_DATE1, THE_OUTPUT_DATE2);
DBMS_OUTPUT.PUT_LINE('Output date ' || TO_DATE(THE_OUTPUT_DATE2, 'DD-MM-YYYY', 'NLS_DATE_LANGUAGE=ENGLISH'));
END;
然后按照你想要的那样输出DBMS:
First Date is:= 06-APR-14
Second Date is:= 06-APR-14
Output date: 06-APR-14