Hi all,
I am using CR XI, Oracle 9.2. I am trying the SP in CR using CR Oracle driver 5.1 (with Oracle native driver, I was not able to get this far).
When I run the SP in SQLdeveloper, I get the desired / correct values in the Table. But when I run the SP in CR, I get zero for my values. DECODE or CASE in the function did not make any difference in either CR or SQLdeveloper. I could not get the IF THEN ELSE to work in the function.
Any ideas what have I done wrong here? Any help would be appreciated.
Thanks and regards,
Chandra
I am using CR XI, Oracle 9.2. I am trying the SP in CR using CR Oracle driver 5.1 (with Oracle native driver, I was not able to get this far).
When I run the SP in SQLdeveloper, I get the desired / correct values in the Table. But when I run the SP in CR, I get zero for my values. DECODE or CASE in the function did not make any difference in either CR or SQLdeveloper. I could not get the IF THEN ELSE to work in the function.
Any ideas what have I done wrong here? Any help would be appreciated.
Code:
Package:
create or replace PACKAGE TEST_REUSE_PACKAGE
AS TYPE Test_Type IS REF CURSOR RETURN ALL_USERS_REUSE%ROWTYPE;
END TEST_REUSE_PACKAGE;
Stored Procedure SP_REFCURSOR_REUSE:
CREATE OR REPLACE
PROCEDURE SP_REFCURSOR_REUSE (
Test_Cursor IN OUT Test_REUSE_Package.Test_Type,
Test_Parameter1 IN ALL_USERS_REUSE.sequence%TYPE,
Test_Parameter2 IN ALL_USERS_REUSE.sequence%TYPE)
AS
STATISTICS1 Number;
currentEndDate DATE;
BEGIN
delete from ALL_USERS_REUSE;
currentEndDate := SYSDATE;
-- change the number next to sysdate to run report for earlier months. -1 is for previous month
SELECT TO_CHAR(LAST_DAY(ADD_MONTHS(SYSDATE,-2)), 'DD-MON-YYYY') INTO currentEndDate FROM dual;
INSERT INTO ALL_USERS_REUSE
SELECT 1 AS SEQUENCE, 'Number of users revisited in the last year' AS DESCRIPTION,
trade.Report.returned_users(currentEndDate, 12) AS STATISTICS1, NULL
FROM dual;
INSERT INTO ALL_USERS_REUSE
SELECT 3 AS SEQUENCE, 'Number of users revisited in the last month' AS DESCRIPTION,
trade.Report.returned_users(currentEndDate, 1) AS STATISTICS1, NULL
FROM dual;
FROM dual; */
commit;
DBMS_OUTPUT.PUT_LINE(STATISTICS1);
DBMS_OUTPUT.PUT_LINE(currentEndDate);
OPEN Test_Cursor FOR
select * from ALL_USERS_REUSE
where ALL_USERS_REUSE.sequence between Test_Parameter1 and Test_Parameter2;
END SP_REFCURSOR_REUSE;
Function returned_users1:
FUNCTION returned_users1(end_date DATE, time_frame NUMBER)
RETURN NUMBER
IS
return_value NUMBER(20) := 0;
BEGIN
SELECT COUNT(1)
INTO return_value
FROM (SELECT user_id, customertype
FROM oradba.temp_hist
WHERE TRUNC(txtimestamp) BETWEEN ADD_MONTHS(TRUNC(end_date), -time_frame) AND TRUNC(end_date)
GROUP BY user_id, customertype
HAVING COUNT(1) > DECODE(new_user(user_id, customertype, end_date, time_frame), 'Y', 1, 0));
-- HAVING COUNT(1) > (case when (new_user(user_id, customertype, end_date, time_frame)) = 'Y' then 1 else 0 end)); */
-- HAVING COUNT(1) > (if (new_user(user_id, customertype, end_date, time_frame)) = 'Y' then 1 else 0));
RETURN return_value;
EXCEPTION
WHEN OTHERS
THEN
RETURN 0;
END;
Thanks and regards,
Chandra