Saturday, 17 August 2013

case statement not working with ref cursor

case statement not working with ref cursor

I am writing a stored procedure to retrieve matched file location from a
table add_files_tables. I am using case statement with ref cursor to get
resultset and then will print filenames. I have created the packages ,but
it is giving me empty set always. Where is the problem .
create or replace package search_cur
as type my_cursor is ref cursor;
function search_File(FILE_NAME varchar2,opt number) return my_cursor;
end search_cur;
/
create or replace package body search_cur
as
function search_File(FILE_NAME varchar2,opt number) return my_cursor
is
ret my_cursor;
begin
Case
when opt=1 THEN
OPEN ret FOR
select file_location from add_files_details where upper(username) like
'%'||file_Name||'%';
return ret;
when 2 THEN
OPEN ret FOR
select file_location from add_files_details where upper(EXTENSION) like
'%'||file_name||'%';
return ret;
WHEN 3 THEN
OPEN ret FOR
select file_location from add_files_details where upper(UPLOAD_DATE) like
'%'||file_name||'%';
return ret;
WHEN 4 THEN
OPEN ret FOR
select file_location from add_files_details where upper(FOLDER_ID) like
'%'||file_name||'%';
return ret;
when 5 then
open ret for
select file_location from add_files_details where upper(file_name) like
'%'||file_name||'%';
return ret;
end case;
end search_file;
end search_cur;
/

No comments:

Post a Comment