请问大家,定义创建成功,但包体出现:Warning: PACKAGE BODY created with compilation errors.为何???还有请问我如何调包并返回查询的结果集?
----------------------------------------------------------------------------------------
CREATE OR REPLACE PACKAGE pkg_BBB
AS
TYPE myrctype IS REF CURSOR;PROCEDURE get (p_id NUMBER, p_rc OUT myrctype);
END pkg_BBB;
/CREATE OR REPLACE PACKAGE BODY pkg_BBB
AS
PROCEDURE get (p_id NUMBER, p_rc OUT myrctype)
IS
qlstr VARCHAR2 (500);
BEGIN
sqlstr :='select ID1,AAA from BBB where id=:w_id';
OPEN p_rc FOR sqlstr USING p_id;
END pkg_BBB;
----------------------------------------------------------------------------------------
CREATE OR REPLACE PACKAGE pkg_BBB
AS
TYPE myrctype IS REF CURSOR;PROCEDURE get (p_id NUMBER, p_rc OUT myrctype);
END pkg_BBB;
/CREATE OR REPLACE PACKAGE BODY pkg_BBB
AS
PROCEDURE get (p_id NUMBER, p_rc OUT myrctype)
IS
qlstr VARCHAR2 (500);
BEGIN
sqlstr :='select ID1,AAA from BBB where id=:w_id';
OPEN p_rc FOR sqlstr USING p_id;
END pkg_BBB;
在 end END pkg_BBB 上面
写end get
AS
PROCEDURE get (p_id NUMBER, p_rc OUT myrctype)
IS
qlstr VARCHAR2 (500);
BEGIN
sqlstr :='select ID1,AAA from BBB where id=:w_id';
OPEN p_rc FOR sqlstr USING p_id;
end get;
END pkg_BBB;-------------------
还是这样呀
qlstr VARCHAR2 (500);
应该是sqlsrt
AS
TYPE myrctype IS REF CURSOR;PROCEDURE getid (p_id NUMBER, p_rc OUT myrctype);
END pkg_BBB;
/CREATE OR REPLACE PACKAGE BODY pkg_BBB
AS
PROCEDURE getid (p_id NUMBER, p_rc OUT myrctype)
IS
qlstr VARCHAR2 (500);
BEGIN
sqlstr :='select ID1,AAA from BBB where id=:w_id';
OPEN p_rc FOR sqlstr USING p_id;
end getid;
END pkg_BBB;
qlstr VARCHAR2 (500);
应该是sqlsrt
------------
好了??感谢zqz117(南瓜少爷)
但如何调用返回查询的结果集?
is
type cur is ref cursor;
end;
create or replace function mytest return pkg_test.cur
is
c pkg_test.cur;
begin
open c for select * from emp;
return c;
end;select mytest() from dual;mytest就返回记录的结果集
CREATE OR REPLACE PACKAGE pkg_BBB
AS
TYPE myrctype IS REF CURSOR;PROCEDURE getid (p_id NUMBER, p_rc OUT myrctype);
END pkg_BBB;CREATE OR REPLACE PACKAGE BODY pkg_BBB
AS
PROCEDURE getid (p_id NUMBER, p_rc OUT myrctype)
IS
sqlstr VARCHAR2 (500);
BEGIN
sqlstr :='select ID1,AAA from BBB where id=:w_id';
OPEN p_rc FOR sqlstr USING p_id;
end getid;
END pkg_BBB;declare
cur pkg_BBB.myrctype;
v_id BBB.ID1%type;
v_aaa BBB.AAA%type;
begin
pkg_BBB.getid(1, cur);
loop
fetch cur into v_id, v_aaa;
exit when cur%notfound;
dbms_output.put_line(v_id || ' ' || v_aaa);
end loop;
close cur;
end;