oracle中如何得到游标的列数,我在表里select一个sql语句,然后执行,但是我不知道他返回的字段个数,没办法fetch into给变量,能事先得到游标返回的字段个数吗,是用plsql写的,能fetch into 给一个数组吗?
请各位高手指点指点!
请各位高手指点指点!
解决方案 »
- 在本地导出远程数据库到本地:是先建立database link, 还是在本地先建立远程服务器的服务命名并加入监听,然后用exp导出???
- windows下开机启动Weblogic设置
- 查表时出错
- 请教一个sql,实现根据截止到每个日期的总数量,计算出分散每个日期段的数量
- 我要崩溃了,新建的本地数据库连不上。谁能帮我。紧急!
- 高手解决复杂问题
- 关于字符的问题,很奇怪
- 关于索引
- 循环序列的简单的问题,大家快来帮忙呀!
- 如何才能到出oracle指定用户所有表的sql脚本,也就是它的表结构,而不没有里面的数据。
- 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语句中返回了哪些列和列数呢?