我创建了一个表
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;
------解决方案--------------------
错误有如下:
- SQL code
v_arg2 varchar2(200),
------解决方案--------------------
- SQL code
create or replace package a_package_nameis 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 a_package_name;/create or replace package body a_package_nameasprocedure get_procedure_name( v_arg1 number, v_arg2 varchar2, refCur_return out CursorType, v_total_Count out varchar2)isnumArg1 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 = '''|| strArg2 ||''' '; 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;/
------解决方案--------------------
错误还蛮多哦,其实LZ自己根据报错信息都可以调出来呢
- SQL code
CREATE TABLE test(id number, value varchar2(200));create or replace package a_package_nameas PROCEDURE get_procedure_name ( v_arg1 number, v_arg2 VARCHAR2/*(200)*/, refCur_return out SYS_REFCURSOR , v_total_Count out varchar2 );END;/create or replace package body a_package_nameas procedure get_procedure_name( v_arg1 number, v_arg2 varchar2, refCur_return out SYS_REFCURSOR, v_total_Count out varchar2)isnumArg1 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;