如果在一个游标内部再定义一个新的游标
时间:2011-09-23
来源:互联网
codes......
cursor t_name is
select table_name
from user_tab_cols
where column_name = 'AAC001'
and (length(table_name) = 4 or length(table_name) = 5)
and table_name not like 'S%'
and table_name not like '%AC01%';
codes...
open t_name;
loop
fetch t_name
into v_tname;
exit when t_name%notfound;
cursor t_cname is
select column_name from user_tab_cols where table_name=v_tname;
codes...
end loop;
codes...
分割线
==================================================================================
上段代码中的红色部分编译的时候报错,那应该怎么改才正确呢?!求高人指点!!
cursor t_name is
select table_name
from user_tab_cols
where column_name = 'AAC001'
and (length(table_name) = 4 or length(table_name) = 5)
and table_name not like 'S%'
and table_name not like '%AC01%';
codes...
open t_name;
loop
fetch t_name
into v_tname;
exit when t_name%notfound;
cursor t_cname is
select column_name from user_tab_cols where table_name=v_tname;
codes...
end loop;
codes...
分割线
==================================================================================
上段代码中的红色部分编译的时候报错,那应该怎么改才正确呢?!求高人指点!!
作者: lwlmj2008 发布时间: 2011-09-23
亲,在ORACLE中,CURSOR的声明或者定义,是不能出现的实际的代码段中的。
还是得放到codes前面。
在codes里,直接使用就可以了
还是得放到codes前面。
在codes里,直接使用就可以了
作者: yixilan 发布时间: 2011-09-23
set serveroutput on;
declare
v_tname varchar2(100) := '';
c_tname varchar2(100) := '';
cursor t_name is
select table_name from user_tab_cols where column_name = 'T3';
cursor t_cname is
select column_name from user_tab_cols where table_name = v_tname;
begin
open t_name;
loop
fetch t_name into v_tname;
exit when t_name%notfound;
open t_cname;
loop fetch t_cname into c_tname;
dbms_output.put_line(c_tname);
exit when t_cname%notfound;
end loop;
close t_cname;
end loop;
close t_name;
end;
declare
v_tname varchar2(100) := '';
c_tname varchar2(100) := '';
cursor t_name is
select table_name from user_tab_cols where column_name = 'T3';
cursor t_cname is
select column_name from user_tab_cols where table_name = v_tname;
begin
open t_name;
loop
fetch t_name into v_tname;
exit when t_name%notfound;
open t_cname;
loop fetch t_cname into c_tname;
dbms_output.put_line(c_tname);
exit when t_cname%notfound;
end loop;
close t_cname;
end loop;
close t_name;
end;
作者: yixilan 发布时间: 2011-09-23
你这有必要声明两个游标吗?
SQL code
SQL code
declare cursor c_tab_col is select table_name, column_name from user_tab_cols where column_name = 'AAC001' and (length(table_name) = 4 or length(table_name) = 5) and table_name not like 'S%' and table_name not like '%AC01%'; begin for tab in c_tab_col loop -- 代码中获取表名使用 tab.table_name -- 获取列名 tab.column_name end loop; end;
作者: opps_zhou 发布时间: 2011-09-23
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28