以前发过一个帖子 没解决问题 这次直接贴代码问题:两个存储过程 P_TEST_P2 调用P_TEST_P1,传的参数都一样
最后一个是测试语句 调用P_TEST_P2获取返回的游标 然后在输出出结果 可是在fetch 这句会报 结果集变量或查询返回结果不匹配 这个错误!
但是在P_TEST_P2里面fetch 是有数据集的 为什么在测试语句就取不到呢?是存储过程传2次游标就不行吗??
create or replace procedure P_TEST_P1
(
IDvalue in out NUMBER,
TempCursor in out sys_refcursor
)
is
begin
open TempCursor for select * from tbl_config_headlist where HEAD_ID=IDvalue;end P_TEST_P1;create or replace procedure P_TEST_P2
(
IDvalue in out NUMBER,
TempCursor in out sys_refcursor
)
is
v_row tbl_config_headlist%rowtype;
begin
P_TEST_P1(IDvalue=>IDvalue,TempCursor=>TempCursor);
-- FETCH TempCursor into v_row;
--DBMS_OUTPUT.put_line(v_row.HEAD_NAME);
end P_TEST_P2;-- ADMINISTRATOR 创建于 2009-8-20
declare
-- 这里是本地变量
IDValue number;
TestCursor SYS_REFCURSOR;
V_ROW tbl_config_headlist%rowtype;
begin
-- 这里是测试语句
IDValue:='3';
p_test_p2(idvalue => IDValue,
tempcursor => TestCursor);
loop
begin
fetch TestCursor into V_ROW;
exit when TestCursor%notfound;
DBMS_OUTPUT.put_line(V_ROW.HEAD_NAME);
end;
end loop;
end;
最后一个是测试语句 调用P_TEST_P2获取返回的游标 然后在输出出结果 可是在fetch 这句会报 结果集变量或查询返回结果不匹配 这个错误!
但是在P_TEST_P2里面fetch 是有数据集的 为什么在测试语句就取不到呢?是存储过程传2次游标就不行吗??
create or replace procedure P_TEST_P1
(
IDvalue in out NUMBER,
TempCursor in out sys_refcursor
)
is
begin
open TempCursor for select * from tbl_config_headlist where HEAD_ID=IDvalue;end P_TEST_P1;create or replace procedure P_TEST_P2
(
IDvalue in out NUMBER,
TempCursor in out sys_refcursor
)
is
v_row tbl_config_headlist%rowtype;
begin
P_TEST_P1(IDvalue=>IDvalue,TempCursor=>TempCursor);
-- FETCH TempCursor into v_row;
--DBMS_OUTPUT.put_line(v_row.HEAD_NAME);
end P_TEST_P2;-- ADMINISTRATOR 创建于 2009-8-20
declare
-- 这里是本地变量
IDValue number;
TestCursor SYS_REFCURSOR;
V_ROW tbl_config_headlist%rowtype;
begin
-- 这里是测试语句
IDValue:='3';
p_test_p2(idvalue => IDValue,
tempcursor => TestCursor);
loop
begin
fetch TestCursor into V_ROW;
exit when TestCursor%notfound;
DBMS_OUTPUT.put_line(V_ROW.HEAD_NAME);
end;
end loop;
end;
(
IDvalue in out NUMBER,
TempCursor in out sys_refcursor
)
IDvalue应该是传入的参数,你却写成了输出参数,当然无法得到你要的结果!
9iSQL> create table tbl_config_headlist (head_id number, head_name varchar2(20));Table created.9iSQL>
9iSQL> insert into tbl_config_headlist values(1, 'kevin');1 row created.9iSQL> create or replace procedure P_TEST_P1(IDvalue in out NUMBER,
2 TempCursor in out sys_refcursor) is
3 begin
4 open TempCursor for
5 select * from tbl_config_headlist where HEAD_ID = IDvalue;
6 end P_TEST_P1;
7 /Procedure created.9iSQL> create or replace procedure P_TEST_P2(IDvalue in out NUMBER,
2 TempCursor in out sys_refcursor) is
3 v_row tbl_config_headlist%rowtype;
4 begin
5 P_TEST_P1(IDvalue => IDvalue, TempCursor => TempCursor);
6 -- FETCH TempCursor into v_row;
7 --DBMS_OUTPUT.put_line(v_row.HEAD_NAME);
8 end P_TEST_P2;
9 /Procedure created.9iSQL> set serverout on
9iSQL>
9iSQL> declare
2 -- 这里是本地变量
3 IDValue number;
4 TestCursor SYS_REFCURSOR;
5 V_ROW tbl_config_headlist%rowtype;
6 begin
7 -- 这里是测试语句
8 IDValue := '1';
9
10 p_test_p2(idvalue => IDValue, tempcursor => TestCursor);
11
12 loop
13 begin
14 fetch TestCursor
15 into V_ROW;
16 exit when TestCursor%notfound;
17
18 DBMS_OUTPUT.put_line(V_ROW.HEAD_NAME);
19
20 end;
21 end loop;
22 end;
23 /
kevinPL/SQL procedure successfully completed.
你看看,你的过程在我的机器里执行一点问题都没有啊
PL/SQL 是7.1.4.1391我这个问题以前有个07年的帖子也是10G的一样是这个问题
SQL> set serverout on
SQL>
SQL> declare
2 IDValue number;
3 TestCursor sys_refcursor;
4 v_row tbl_config_headlist%rowtype;
5 begin
6 IDValue:=1;
7
8 p_test_p2(idvalue=>idvalue,tempcursor=>testcursor);
9
10 loop
11 begin
12 fetch testcursor into v_row;
13 exit when testcursor%notfound;
14
15 dbms_output.put_line(v_row.HEAD_NAME);
16
17 end;
18 end loop;
19
20 end;
21 /
CellID
declare
*
第 1 行出现错误:
ORA-01001: 无效的游标
ORA-06512: 在 line 12
如下:
SQL> set serverout on
SQL> declare
2 IDValue number;
3 TestCursor sys_refcursor;
4 v_row tbl_config_headlist%rowtype;
5 begin
6 IDValue:=1;
7
8 p_test_p2(idvalue=>idvalue,tempcursor=>testcursor);
9
10 loop
11 begin
12 fetch testcursor into v_row;
13 exit when testcursor%notfound;
14
15 dbms_output.put_line(v_row.HEAD_NAME);
16
17 end;
18 end loop;
19
20 end;
21 /
declare
*
第 1 行出现错误:
ORA-06504: PL/SQL: 结果集变量或查询的返回类型不匹配
ORA-06512: 在 line 12
open TempCursor for select * from tbl_config_headlist where HEAD_ID=IDvalueselect句用()括起来试试
是不是上面这样 报语法错误
我没用过sys_refcursor
但游标经常会在这种地方出现问题
难道ORACLE版本还有兼容性问题??
ORACLE的东西真的不人性化
oracle在这种地方可能出现语法解析问题
找不到别的原因所以让你试试
你看看你的oracle版本,4楼的9i已经测试通过
create or replace package test
is
type t_cursor is ref cursor return tbl_config_headlist%rowtype;
procedure P_TEST_P1 (IDvalue in NUMBER, TempCursor in out t_cursor);
procedure P_TEST_P2 (IDvalue in NUMBER, TempCursor in out t_cursor);
end test;
/
create or replace package body test
is
procedure P_TEST_P1 (IDvalue in NUMBER, TempCursor in out t_cursor)
is
begin
open TempCursor for select * from tbl_config_headlist where HEAD_ID=IDvalue;
end P_TEST_P1;
procedure P_TEST_P2 (IDvalue in NUMBER, TempCursor in out t_cursor)
is
begin
P_TEST_P1(IDvalue,TempCursor);
end P_TEST_P2;
end test;
/
过程 我上个帖子发的游标其实返回的数据表是动态的 会根据判断来返回不同表的数据 强类型会
限定死 我还是同意wildwave的可能是ORACLE版本问题 想换个11G看看另外不是我说ORACLE不好或不好学 只是感觉ORACLE的东西不规范 最初设计的时候没有MSSQL的规范
简单点说:
1.ORACLE居然对表名长度,大小写做限制,我觉得这个就没考虑开发人员和以后维护的方便。
2.ORACLE数据库的概念是一个数据库 管理很多的表空间什么的,而微软的数据库概念简单,微软这样可以做到不同的项目用到不同的数据库,在管理器里面看的时候都很方便,而且容易备份和还原。
3.ORACLE的函数很多都是缩写(和前面的一些约束一样,不知道为什么),ORACLE的临时表需要事先建好,而MSSQL可以分局部临时和全局临时,数据库可以自动管理其生存周期。ORACLE那游标的功能和微软做页面ASP的游标功能一样,比较弱。所以我个人觉得ORACLE难学是它不规范,MSSQL好学是因为它规范。
规范的东西才能更好的发展,有点啰嗦了,只是我的体会
可以换个版本试试,刚才查了下你那种写法在oracle 10.2里面都是可以的。长度超过30个字符的变量,表名,函数或者过程名,也太夸张了。
现在换到ORACLE感觉麻烦多了~~~
用过MSSQL的人用其他的数据库感觉真的不方便~~~
呵呵 彻底对ORACLE无语了。
我还是下个ORACLE 11G R2 直接装了再测 哎 真不知道自己哪来的这么大动力去研究ORACLE 觉得学了完全没必要
SQL Server2008都不知道功能强大到哪里去了。