declare
type emp_table_type is table of emp_ann%rowtype index by binary_integer;
emp_table emp_table_type;
begin
select * into emp_table from emp_ann;
dbms_output.put_line('ok');
end;
错误在什么地方啊?请大家帮帮忙
type emp_table_type is table of emp_ann%rowtype index by binary_integer;
emp_table emp_table_type;
begin
select * into emp_table from emp_ann;
dbms_output.put_line('ok');
end;
错误在什么地方啊?请大家帮帮忙
PLS-00597: expression 'EMP_TABLE' in the INTO list is of wrong type
ORA-06550: line 5, column 26:
PL/SQL: ORA-00904: : invalid identifier
ORA-06550: line 5, column 1:
PL/SQL: SQL Statement ignored不清楚
还有是不是和type emp_table_type is table of emp_ann%rowtype index by binary_integer
这句话有关系啊?
定义的类型不允许你这么操作啊
请大家各抒己见,帮帮小弟吧
type emp_table_type is table of emp%ROWTYPE
index by binary_integer;
emp_table emp_table_type;
CURSOR cur_emp IS
select * from emp;
i NUMBER;
BEGIN
i:= 1;
OPEN cur_emp;
LOOP
EXIT WHEN cur_emp%NOTFOUND;
FETCH cur_emp INTO emp_table(i);
i:=i+1;
END LOOP;
CLOSE cur_emp;
dbms_output.put_line('ok');
end;看看ORACLE关于PL/SQL面向对象编程有关概念。
改成
select * bulk collect into emp_table from emp_ann;
就没有错误了
怎么回事啊?
万分感谢
[email protected]
bulk collect是一次性提取,你单条提取的话,必须用游标循环。
这句中为什么要写成emp_table(i)啊?直接写成emp_table行吗?
同一index by表的不同元素。
因为是单条取的,所以必须不同指针。bulk collect一次性提取,故不需要。
fetch每次只能fetch一条record记录,所以用emp_table(i)。这里的emp_table(i)相当于一个record变量。
emp_table只能一次性批量插入,就是用bulk collect into