sfuk
asked on
Function does not return any data
Hi Experts,
here is the function that I am having a problem with. It doesn't return any data. However, when I run the select statement from SQL*PLUS it brings data back. what is the problem?
Please help!
CREATE OR REPLACE FUNCTION get_usage_rep(p_start_date date, p_end_date date)
RETURN sys_refcursor AS
v_report sys_refcursor;
whereclause varchar2(3200):='and u.affiliate_id in (select aff_id from ultra_affiliate)';
begin
open v_report for
'select distinct initcap( u.first_name) || initcap( u.last_name )full_name '
|| chr (10)
||' from ubcsecurity.user_session s,cod_security_vw u, ultra_affiliate ua '
|| chr (10)
||' where s.user_name = u.user_name '
|| chr (10)
||' and ua.aff_id = u.affiliate_id '
|| chr (10)
||' and s.login >= '''|| p_start_date|| ''' and s.login <= '''|| p_end_date|| ''' '
|| chr (10)
|| whereclause
|| chr (10)
|| ' group by initcap( u.first_name) || initcap( u.last_name ) '
|| chr(10)
||' order by initcap( u.first_name) || initcap( u.last_name ) ';
return v_report;
end;
here is the function that I am having a problem with. It doesn't return any data. However, when I run the select statement from SQL*PLUS it brings data back. what is the problem?
Please help!
CREATE OR REPLACE FUNCTION get_usage_rep(p_start_date
RETURN sys_refcursor AS
v_report sys_refcursor;
whereclause varchar2(3200):='and u.affiliate_id in (select aff_id from ultra_affiliate)';
begin
open v_report for
'select distinct initcap( u.first_name) || initcap( u.last_name )full_name '
|| chr (10)
||' from ubcsecurity.user_session s,cod_security_vw u, ultra_affiliate ua '
|| chr (10)
||' where s.user_name = u.user_name '
|| chr (10)
||' and ua.aff_id = u.affiliate_id '
|| chr (10)
||' and s.login >= '''|| p_start_date|| ''' and s.login <= '''|| p_end_date|| ''' '
|| chr (10)
|| whereclause
|| chr (10)
|| ' group by initcap( u.first_name) || initcap( u.last_name ) '
|| chr(10)
||' order by initcap( u.first_name) || initcap( u.last_name ) ';
return v_report;
end;
this link also give the more in detail....
http://www.enterprisedb.com/documentation/spl-ref-cursors.html
http://www.enterprisedb.com/documentation/spl-ref-cursors.html
for this query group by is not require... remove the group by and try it...
try to format the dates
CREATE OR REPLACE FUNCTION get_usage_rep(p_start_date date, p_end_date date)
RETURN sys_refcursor AS
v_report sys_refcursor;
whereclause varchar2(3200):='and u.affiliate_id in (select aff_id from ultra_affiliate)';
begin
open v_report for
'select distinct initcap( u.first_name) || initcap( u.last_name )full_name '
|| chr (10)
||' from ubcsecurity.user_session s,cod_security_vw u, ultra_affiliate ua '
|| chr (10)
||' where s.user_name = u.user_name '
|| chr (10)
||' and ua.aff_id = u.affiliate_id '
|| chr (10)
||' and s.login >='||'to_date('||''''||to_ char(p_sta rt_date,'d d/mm/yyyy' )||''','|| ''''||'dd/ mm/yyyy'|| ''') '
||' and s.login <='||'to_date('||''''||to_ char(p_end ,'dd/mm/yy yy')||''', '||''''||' dd/mm/yyyy '||''') '
|| chr (10)
|| whereclause
|| chr (10)
|| ' group by initcap( u.first_name) || initcap( u.last_name ) '
|| chr(10)
||' order by initcap( u.first_name) || initcap( u.last_name ) ';
return v_report;
end;
CREATE OR REPLACE FUNCTION get_usage_rep(p_start_date
RETURN sys_refcursor AS
v_report sys_refcursor;
whereclause varchar2(3200):='and u.affiliate_id in (select aff_id from ultra_affiliate)';
begin
open v_report for
'select distinct initcap( u.first_name) || initcap( u.last_name )full_name '
|| chr (10)
||' from ubcsecurity.user_session s,cod_security_vw u, ultra_affiliate ua '
|| chr (10)
||' where s.user_name = u.user_name '
|| chr (10)
||' and ua.aff_id = u.affiliate_id '
|| chr (10)
||' and s.login >='||'to_date('||''''||to_
||' and s.login <='||'to_date('||''''||to_
|| chr (10)
|| whereclause
|| chr (10)
|| ' group by initcap( u.first_name) || initcap( u.last_name ) '
|| chr(10)
||' order by initcap( u.first_name) || initcap( u.last_name ) ';
return v_report;
end;
CREATE OR REPLACE FUNCTION get_usage_rep(p_start_date date, p_end_date date)
RETURN sys_refcursor AS
v_report sys_refcursor;
whereclause varchar2(3200):='and u.affiliate_id in (select aff_id from ultra_affiliate)';
begin
open v_report for
'select distinct initcap( u.first_name) || initcap( u.last_name )full_name '
|| chr (10)
||' from ubcsecurity.user_session s,cod_security_vw u, ultra_affiliate ua '
|| chr (10)
||' where s.user_name = u.user_name '
|| chr (10)
||' and ua.aff_id = u.affiliate_id '
|| chr (10)
||' and s.login >= '''|| to_char(p_start_date,'dd-m on-yy')|| ''' and s.login < '''|| to_char(p_end_date+1,'dd-m on-yy')|| ''' '
|| chr (10)
|| whereclause
|| chr (10)
|| ' group by initcap( u.first_name) || initcap( u.last_name ) '
|| chr(10)
||' order by initcap( u.first_name) || initcap( u.last_name ) ';
return v_report;
end;
try this
RETURN sys_refcursor AS
v_report sys_refcursor;
whereclause varchar2(3200):='and u.affiliate_id in (select aff_id from ultra_affiliate)';
begin
open v_report for
'select distinct initcap( u.first_name) || initcap( u.last_name )full_name '
|| chr (10)
||' from ubcsecurity.user_session s,cod_security_vw u, ultra_affiliate ua '
|| chr (10)
||' where s.user_name = u.user_name '
|| chr (10)
||' and ua.aff_id = u.affiliate_id '
|| chr (10)
||' and s.login >= '''|| to_char(p_start_date,'dd-m
|| chr (10)
|| whereclause
|| chr (10)
|| ' group by initcap( u.first_name) || initcap( u.last_name ) '
|| chr(10)
||' order by initcap( u.first_name) || initcap( u.last_name ) ';
return v_report;
end;
try this
ASKER
Thanks a lot for your help!
I am calling the function with
select get_usage_rep(to_date('01- JAN-2009', 'DD-MON-YY YY'),to_da te('01-APR -2009','DD -MON-YYYY' )) from dual
or
select get_usage_rep('01-JAN-2009 ','01-APR- 2009') from dual
It still does not return anything back. But the data is there. Am I doing this right?
I am calling the function with
select get_usage_rep(to_date('01-
or
select get_usage_rep('01-JAN-2009
It still does not return anything back. But the data is there. Am I doing this right?
ASKER
I see the problem: I was trying to run the select statement from TOAD, however it did not anything.
When I tried SQL*PLUS I got the exact result that is described at http://www.orafaq.com/node/980
GET_USAGE_REP('01-JA
--------------------
CURSOR STATEMENT : 1
CURSOR STATEMENT : 1
FULL_NAME
--------------------------
name1
name2
name2
Could you suggest how I can call the function and get a result without
GET_USAGE_REP('01-JA
--------------------
CURSOR STATEMENT : 1
CURSOR STATEMENT : 1
I need to run the function using the select statement at iReports.
Thanks!
When I tried SQL*PLUS I got the exact result that is described at http://www.orafaq.com/node/980
GET_USAGE_REP('01-JA
--------------------
CURSOR STATEMENT : 1
CURSOR STATEMENT : 1
FULL_NAME
--------------------------
name1
name2
name2
Could you suggest how I can call the function and get a result without
GET_USAGE_REP('01-JA
--------------------
CURSOR STATEMENT : 1
CURSOR STATEMENT : 1
I need to run the function using the select statement at iReports.
Thanks!
http://www.psoug.org/reference/ref_cursors.html
check this link it will give better idea about ref cursor....
check this link it will give better idea about ref cursor....
i think it is a property of sqlplus only, u can use the function in reports
ASKER
No, unfortunately I can not use the function as it is in iReports.
There is useful link that I found
http://it.toolbox.com/blog s/jjflash- oracle-jou rnal/ref-c ursors-pip elined-tab le-functio ns-and-adf -bc-20740
There is useful link that I found
http://it.toolbox.com/blog
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help.
http://www.orafaq.com/node/980