我创建了一个表
test(id number,value varchar2(200))
create or replace package a_package_name
as
TYPE CursorType is REF CURSOR;
PROCEDURE get_procedure_name
(
v_arg1 number,
v_arg2 varchar2(200),
refCur_return out cursor,
v_total_Count out varchar2
)
END;
create or replace package body a_package_name
as
procedure get_procedure_name
(
v_arg1 number,
v_arg2 varchar2(200),
refCur_return out cursor,
v_total_Count out varchar2
)
is
numArg1 number := '';
strArg2 varchar2(200) := '';
strSql varchar2(200) := '';
strQuery varchar2(200) := '';
strCondition varchar2(200) := ' where 1=1 ';
Begin
if v_arg1 is not null and length(v_arg1)>0 then
numArg1 := v_arg1;
strCondition := ' '|| strCondition ||' and id = '|| numArg1 ||' ';
end if;
if v_arg2 is not null and length(v_arg2)>0 then
strArg2 := v_arg2;
strCondition := ' '|| strCondition ||' and value = '''|| v_arg2 ||''' ';
end if;
strSql := 'selec * from test '|| strCondition ||' ';
OPEN refCur_return FOR strSql;
strQuery := 'select count(1) from test '|| strCondition ||' '
EXECUTE IMMEDIATE strQuery INTO v_total_Count;
end get_procedure_name;
end a_package_name;
------解决方案--------------------
晕,竟然复制不全。。。
create or replace package a_package_name
as
TYPE CursorType is REF CURSOR;
PROCEDURE get_procedure_name
(
v_arg1 number,
v_arg2 varchar2,
refCur_return out CursorType,
v_total_Count out varchar2
);
END;
create or replace package body a_package_name
as
procedure get_procedure_name
(
v_arg1 number,
v_arg2 varchar2,
refCur_return out CursorType,
v_total_Count out varchar2
)
is
numArg1 number := '';
strArg2 varchar2(200) := '';
strSql varchar2(200) := '';
strQuery varchar2(200) := '';
strCondition varchar2(200) := ' where 1=1 ';
Begin
if v_arg1 is not null and length(v_arg1)>0 then
numArg1 := v_arg1;
strCondition := ' '|| strCondition ||' and id = '|| numArg1 ||' ';
end if;
if v_arg2 is not null and length(v_arg2)>0 then
strArg2 := v_arg2;
strCondition := ' '|| strCondition ||' and value = '''|| v_arg2 ||''' ';
end if;
strSql := 'selec * from test '|| strCondition ||' ';
OPEN refCur_return FOR strSql;
strQuery := 'select count(1) from test '|| strCondition ||' ';
EXECUTE IMMEDIATE strQuery INTO v_total_Count;
end get_procedure_name;
end a_package_name;