找不出错在哪里了

[复制链接]
查看11 | 回复8 | 2014-10-8 15:16:50 | 显示全部楼层 |阅读模式
declare
TYPE t_record IS RECORD(
id test.id%type,
mc test.mc%type);
--- var_record t_record;
type t_test is table of t_record;
var_test t_test;
cursor cur_test is
select id, mc from test;
begin
open cur_test;
fetch cur_test BULK COLLECT
INTO var_test;
for i in 1 .. var_test.count() loop
dbms_output.put_line(var_test(i).id || '---' || var_test(i).mc);
end loop;
end;
回复

使用道具 举报

千问 | 2014-10-8 15:16:50 | 显示全部楼层
从语法上没有任何问题,你什么版本,报什么错误?
回复

使用道具 举报

千问 | 2014-10-8 15:16:50 | 显示全部楼层
Compilation errors for TYPE PETER.T_RECORD
Error: PLS-00597: INTO 列表中的表达式 'VAR_TEST'类型错误
Line: 16
Text: fetch cur_test BULK COLLECT
Error: PL/SQL: SQL Statement ignored
Line: 15
Text: open cur_test;
========================
SQL> select * from V$version;
BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.0.1.1.1 - Production
PL/SQL Release 9.0.1.1.1 - Production
CORE
9.0.1.1.1
Production
TNS for 32-bit Windows: Version 9.0.1.1.0 - Production
NLSRTL Version 9.0.1.1.1 - Production
回复

使用道具 举报

千问 | 2014-10-8 15:16:50 | 显示全部楼层
版本问题,升级吧 ^|^
回复

使用道具 举报

千问 | 2014-10-8 15:16:50 | 显示全部楼层

改为如下即可!
declare
TYPE t_record IS RECORD
(
id test.id%type,
mc test.mc%type);
type t_test is table of t_record;
var_test t_test;
cursor cur_test is
select id, mc from test;
begin
select id, mc bulk collect into var_test from test;
for i in 1 .. var_test.count loop
dbms_output.put_line(var_test(i).id || '---' || var_test(i).mc);
end loop;
end;

回复

使用道具 举报

千问 | 2014-10-8 15:16:50 | 显示全部楼层
Before Oracle9i 9.2 there was an restriction of BULK COLLECT INTO
colletion of records, this restriction is lifted, though FETCH..BULK COLLECT
INTO a PL/SQL collection of records incorrectly raises error PLS-00597 when the
record type is defined as a PL/SQL record or using CURSOR%ROWTYPE. No error is
raised if the record is defined using TABLE%ROWTYPE.
This is fixed in Oracle9i 9.2.0.3 and higher versions
回复

使用道具 举报

千问 | 2014-10-8 15:16:50 | 显示全部楼层
没有CLOSE 游标啊
回复

使用道具 举报

千问 | 2014-10-8 15:16:50 | 显示全部楼层
在我这运行没错.
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
PL/SQL Release 9.2.0.8.0 - Production
CORE
9.2.0.8.0
Production
TNS for Linux: Version 9.2.0.8.0 - Production
NLSRTL Version 9.2.0.8.0 - Production
回复

使用道具 举报

千问 | 2014-10-8 15:16:50 | 显示全部楼层
楼上的还是不可以啊,而且cur_test放那还有用吗?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行