在线等 oracle 游标不用循环 能否直接取指定行的值? 本帖最后由 lixiaolong09 于 2010-12-13 10:58:14 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 只取一行的数据吗?那就没必要用游标了啊 直接用select into 就好了 办法是有不过通过游标不能实现你可以使用bulk collect 把所有的游标记录放入到一个关联数组里,然后你就直接操作数组就行了。我这里有个例子:SQL> declare 2 type deptrecord is record( 3 deptno dept.deptno%type, 4 dname dept.dname%type, 5 loc dept.loc%type); 6 type number_array is table of deptrecord; 7 number_collection number_array := number_array(); 8 begin 9 number_collection.extend(5); 10 dbms_output.put_line('number_collection的数量:' || 11 number_collection.count); 12 select * bulk collect into number_collection from dept; 13 dbms_output.put_line(number_collection(1).deptno); 14 end; 15 /number_collection的数量:510PL/SQL procedure successfully completedSQL> fetch cursor bulk collect into 数组 SQL写法急急,求助 请教如何向sql传递参数的问题 oracle:在触发器中,如何获得自增id的值,并实现更新数据! 用c#连接Oracle被拒绝怎么办 多表连接问题 oracle数据库中 多条同名数据取各自最新的时间的数据 请教高手,帮忙转一个SQLSERVER的函数(100分) Oracle一安装就蓝屏是什么问题啊? update ..... (比较更新)! 因函数中的死循环,我该如何解锁呢? 在线等 菜鸟测试存储过程 如何附值参数 Oracle中的注释导入到sql server2005中
那就没必要用游标了啊 直接用select into 就好了
你可以使用bulk collect 把所有的游标记录放入到一个关联数组里,然后你就直接操作数组就行了。我这里有个例子:SQL> declare
2 type deptrecord is record(
3 deptno dept.deptno%type,
4 dname dept.dname%type,
5 loc dept.loc%type);
6 type number_array is table of deptrecord;
7 number_collection number_array := number_array();
8 begin
9 number_collection.extend(5);
10 dbms_output.put_line('number_collection的数量:' ||
11 number_collection.count);
12 select * bulk collect into number_collection from dept;
13 dbms_output.put_line(number_collection(1).deptno);
14 end;
15 /number_collection的数量:5
10PL/SQL procedure successfully completedSQL>