fetch bulk collect into 问题

[复制链接]
查看11 | 回复9 | 2010-10-8 09:31:21 | 显示全部楼层 |阅读模式
请问高手们:
在ORACEL9i 下。用 fetch bulk collect into 可以同时取多个字段吗
例如:
open testcur for 'select a,b,c from test ';
fetchtestcur bulk collect intorecordTable;
这样行吗?
回复

使用道具 举报

千问 | 2010-10-8 09:31:21 | 显示全部楼层
可以,eg:
[php]
declare
v_ref sys_refcursor;
type toms_type is table of toms%rowtype;
v_toms toms_type := toms_type();
begin
open v_ref for 'select * from toms';
fetch v_ref bulk collect into v_toms;
dbms_output.put_line('bulk collected: ' || v_toms.count);
end;
/
[/php]
回复

使用道具 举报

千问 | 2010-10-8 09:31:21 | 显示全部楼层
谢谢 Toms_Zhang,但是怎么这样就不行呢?
declare
v_ref sys_refcursor;
type tEmp is record
( eno number(4),
ename varchar2(10));
type toms_type is table of tEmp;
v_toms toms_type := toms_type();
begin
open v_ref for 'select empno,ename from emp';
fetch v_ref bulk collect into v_toms;
dbms_output.put_line('bulk collected: ' || v_toms.count);
end;
回复

使用道具 举报

千问 | 2010-10-8 09:31:21 | 显示全部楼层
不要说
“怎么这样就不行呢?”
应该说
我这样run的时候,报了错,具体信息是这个样子的
...
...
...
回复

使用道具 举报

千问 | 2010-10-8 09:31:21 | 显示全部楼层
哪里不行
[php]
SQL> set serveroutput on
SQL> select * from toms;
10 900001111
SQL> declare
2v_ref sys_refcursor;
3type toms_type is table of toms%rowtype;
4v_toms toms_type := toms_type();
5begin
6open v_ref for 'select * from toms';
7fetch v_ref bulk collect into v_toms;
8dbms_output.put_line('bulk collected: ' || v_toms.count);
9end;
10/
bulk collected: 1
PL/SQL 过程已成功完成。
SQL>
[/php]

那个不行用这个试试,这些我都是学习调试过的
[php]
SQL> declare
2cursor cur_toms is select * from toms;
3type toms_type is table of toms%rowtype;
4v_toms toms_type := toms_type();
5begin
6open cur_toms;
7fetch cur_tomsbulk collect into v_toms;
8dbms_output.put_line('bulk collected: ' || v_toms.count);
9end;
10/
bulk collected: 1
PL/SQL 过程已成功完成。
SQL>
[/php]
回复

使用道具 举报

千问 | 2010-10-8 09:31:21 | 显示全部楼层
Toms_zhang,用你的我调试也没有问题,但是我用下面的代码就不行,不知道为什么?
declare
v_ref sys_refcursor;
type tEmp is record
( eno number(4),
ename varchar2(10));
type toms_type is table of tEmp;
v_toms toms_type := toms_type();[/COLOR]
begin
open v_ref for 'select empno,ename from emp';
fetch v_ref bulk collect into v_toms;
dbms_output.put_line('bulk collected: ' || v_toms.count);
end;
ORA-06550: 第 10 行, 第 31 個欄位:
PLS-00597: INTO 清單中的表示式 'V_TOMS' 是錯誤的類型
ORA-06550: 第 10 行, 第 1 個欄位:
PL/SQL: SQL Statement ignored
回复

使用道具 举报

千问 | 2010-10-8 09:31:21 | 显示全部楼层
最初由 llkyq 发布
[B]Toms_zhang,用你的我调试也没有问题,但是我用下面的代码就不行,不知道为什么?
declare
v_ref sys_refcursor;
type tEmp is record
( eno number(4),
ename varchar2(10));
type toms_type is table of tEmp;
v_toms toms_type := toms_type();[/COLOR]
begin
open v_ref for 'select empno,ename from emp';
fetch v_ref bulk collect into v_toms;
dbms_output.put_line('bulk collected: ' || v_toms.count);
end;
ORA-06550: 第 10 行, 第 31 個欄位:
PLS-00597: INTO 清單中的表示式 'V_TOMS' 是錯誤的類型
ORA-06550: 第 10 行, 第 1 個欄位:
PL/SQL: SQL Statement ignored [/B]

版本?
回复

使用道具 举报

千问 | 2010-10-8 09:31:21 | 显示全部楼层
版本: oracle 9.2.0.1.0
回复

使用道具 举报

千问 | 2010-10-8 09:31:21 | 显示全部楼层
最初由 llkyq 发布
[B]版本: oracle 9.2.0.1.0 [/B]

这个版本可能不行
PLS-00597 expression string in the INTO list is of wrong type
Cause: This exception is raised for the following errors:
the expression in INTO clause of OPEN or RETURNING statement is neither of legal SQL datatypes nor of PL/SQL RECORD datatype
a collection of records is used in INTO clause of OPEN or RETURNING statement.
a record or a collection of records is used in BULK COLLECT INTO
Action: Use expression with correct datatype in the INTO clause.

我在9.2.0.6上做没问题!
回复

使用道具 举报

千问 | 2010-10-8 09:31:21 | 显示全部楼层
谢谢toms_zhang. 你知道哪里下载补丁可以直接升级到 9.2.0.6 吗?
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行