oracle 数组怎么用

jin_ok 2010-11-03 10:02:30
我声明了一个数组,不知怎样取出数组的值,操作表的字段
cursor c_test is select * from tbl_test;
TYPE myarray IS TABLE OF c_test%ROWTYPE;
cur_array myarray;
begin
open c_test;
loop
fetch c_test bulk collect into cur_array limit 100000;
exit when c_flight_info%notfound;
怎样取出数组里面的值呀?

end loop;
close c_flight_info;
exception
when others then
raise_application_error(-20199,'处理数据出错!');
return;
end;

另外limit参数的作用是什么?,我的表中有10W条记录需要处理
...全文
127 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jin_ok 2010-11-03
  • 打赏
  • 举报
回复
呵呵,谢谢,结分
心中的彩虹 2010-11-03
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 wkc168 的回复:]
引用楼主 jin_ok 的回复:
我声明了一个数组,不知怎样取出数组的值,操作表的字段
cursor c_test is select * from tbl_test;
TYPE myarray IS TABLE OF c_test%ROWTYPE;
cur_array myarray;
begin
open c_test;
loop
fetch c_test bulk colle……
[/Quote]

--使用了bulk collect into 就不要循环 limit 是取游标中的100000的行数

后面接limit n 就是每次从游标中取n条记录 你的是100000
心中的彩虹 2010-11-03
  • 打赏
  • 举报
回复
[Quote=引用楼主 jin_ok 的回复:]
我声明了一个数组,不知怎样取出数组的值,操作表的字段
cursor c_test is select * from tbl_test;
TYPE myarray IS TABLE OF c_test%ROWTYPE;
cur_array myarray;
begin
open c_test;
loop
fetch c_test bulk collect into cu……
[/Quote]

--使用了builk collect into 就不要循环 limit 是取游标中的100000的行数
declare
cursor c_test is select * from tbl_test;
TYPE myarray IS TABLE OF c_test%ROWTYPE;
cur_array myarray;
begin
open c_test;

fetch c_test bulk collect into cur_array limit 100000;
close c_flight_info;
for i in 1..cur_array.count loop
dbms.output.put_line(i.col....);
end loop;
exception
when others then
raise_application_error(-20199,'处理数据出错!');
return;
end;




kaiee 2010-11-03
  • 打赏
  • 举报
回复
哈哈,什么啊
jin_ok 2010-11-03
  • 打赏
  • 举报
回复
另外 bulk collect中limit参数啥意思?
jin_ok 2010-11-03
  • 打赏
  • 举报
回复
知道了,谢谢
  • 打赏
  • 举报
回复
用数组名加下标就可以取数据的
gelyon 2010-11-03
  • 打赏
  • 举报
回复

--给你个例子:
declare
type ename_table_type is table of emp.ename%type ;--index by binary_integer;
type sal_table_type is table of emp.sal%type; --index by binary_integer;
ename_table ename_table_type;
sal_table sal_table_type:=sal_table_type();
sql_stat varchar2(200);
begin
ename_table:=ename_table_type('SCOTT','SMITH','ALLEN');
sql_stat:='update emp set sal=sal*1.1 where ename=:1 returning sal into :2';
forall i in 1..ename_table.count
execute immediate sql_stat using ename_table(i) returning bulk collect into sal_table;
for j in 1..ename_table.count loop
dbms_output.put_line('雇员:'||ename_table(j)||'的薪水:'||sal_table(j));
end loop;
end;
/

PL/SQL block, executed in 0.454 sec.
雇员:SCOTT的薪水:3300
雇员:SMITH的薪水:880
雇员:ALLEN的薪水:1760
Total execution time 0.454 sec.

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧