oracle中如何得到游标的列数,我在表里select一个sql语句,然后执行,但是我不知道他返回的字段个数,没办法fetch into给变量,能事先得到游标返回的字段个数吗,是用plsql写的,能fetch into 给一个数组吗?
请各位高手指点指点!
请各位高手指点指点!
解决方案 »
- 为什么 pl/sql desc 不能用 还有 就是每次create 表老报错 说缺失右括号
- 关于在eclipse的data source explorer上连接oracle 11g数据库的存储过程问题
- 散分并分享一个oracle视频,顺便倡议积极结帖~!
- "oracle装成了,但问题仍很多!"第2集
- 启动OracleOracleTNSListener服务说无法找到路径怎么办?
- 哪有oracle的好的教程下载?
- 经常进入不了数据库或很短时间就掉下来
- 在OEM中怎么连接另外一个数据库?
- 关于american_america.us7ascii字符集的问题
- 两张表数据一样 一张表增加数据 怎么样让另一张表也增加
- VB6.0向Oracle10数据库表增加记录失败
- Connection refused(DESCRIPTION=(TMP=)(VSNNUM=169869568)(ERR=12505)(ERROR_STACK=(
declare
cursor cur_test is select * from dual;
list cur_test%rowtype;
begin
open cur_test;
fetch cur_test into list;
dbms_output.put_line(list.dummy);
end;
/
fetch给数组?没听说过,但是可以fetch给自定义记录类型。游标长度不知道怎么获得,定义游标的时候应该知道列数及列名了啊SQL> declare
2 cursor cur_test is select id,name from a;
3 type t_a is record(
4 id1 a.id%TYPE,
5 name1 a.name%TYPE
6 );
7 rec_a t_a;
8 begin
9 open cur_test;
10 loop
11 fetch cur_test into rec_a;
12 exit when cur_test%notfound;
13 dbms_output.put_line(rec_a.id1||':'||rec_a.name1);
14 end loop;
15 close cur_test;
16 end;
17 /
1:甲
2:乙
3:丙
4:丁PL/SQL 过程已成功完成。
cursor v_cursor is select * from a;呢?
而a的字段又比较多呢?
insert into a select 1,'甲' from dual union select 2,'乙' from dual;
insert into a select 3,'丙' from dual union select 4,'丁' from dual;declare
cursor cur_test is select to_char(id) id,name from a;
type t_a is varray(2) of varchar2(10);
rec_a t_a;
begin
open cur_test;
loop
fetch cur_test into rec_a;
exit when cur_test%notfound;
dbms_output.put_line(rec_a(1)||':'||rec_a(2));
end loop;
close cur_test;
end;
/
ERROR 位于第 8 行:
ORA-06550: line 8, column 26:
PLS-00597: expression 'REC_A' in the INTO list is of wrong type
ORA-06550: line 8, column 6:
PL/SQL: SQL Statement ignored
[TEST@ora10gr1#2009-12-18/17:32:17] SQL>select * from t1; ID NAME
---------- ----------
1 aaa
2 bbb
3 ccc[TEST@ora10gr1#2009-12-18/17:32:26] SQL>set serveroutput on
[TEST@ora10gr1#2009-12-18/17:32:28] SQL>declare
2 type t_type is table of t1%rowtype;
3 t_rec t_type;
4 begin
5 select * bulk collect into t_rec from t1;
6 for i in t_rec.first..t_rec.count loop
7 dbms_output.put_line(t_rec(i).id||t_rec(1).name);
8 end loop;
9 end;
10 /
1aaa
2aaa
3aaaPL/SQL procedure successfully completed.[TEST@ora10gr1#2009-12-18/17:32:28] SQL>
[TEST@ora10gr1#2009-12-18/17:33:53] SQL>declare
2 type t_type is table of t1%rowtype;
3 t_rec t_type;
4 begin
5 select * bulk collect into t_rec from t1;
6 for i in t_rec.first..t_rec.count loop
7 dbms_output.put_line(t_rec(i).id||t_rec(i).name);
8 end loop;
9 end;
10 /
1aaa
2bbb
3cccPL/SQL procedure successfully completed.
SELECT OWNER,TABLE_NAME,COLUMN_NAME FROM DBA_TAB_COLUMNS
lz想要的是:得到一个游标其包含的字段个数(比如:cursor cur_test is select deptno,comm from scott.dept,楼主可能是想要得到该游标包含的字段个数是2!)。
select count(*) into a from user_tab_cols where table_name= upper('table');
这样就可以了
思考一下
如果只知道游标名
游标的定义你是看不到的
那么如何查看这个游标的select语句中返回了哪些列和列数呢?