create table w (a number);declare
str varchar2(1000);
CURSOR tname_cursor IS
SELECT table_name
FROM user_tables
where table_name like 'W';
begin
FOR x IN tname_cursor LOOP
str := 'drop table '||x.table_name;
dbms_output.put_line(str);
EXECUTE IMMEDIATE str;
END LOOP;
END;
/
里这句 FOR x IN tname_cursor LOOP
str := 'drop table '||x.table_name; 中不是变量啊,怎么也可以运行呢?而且执行结果还是正常的
str varchar2(1000);
CURSOR tname_cursor IS
SELECT table_name
FROM user_tables
where table_name like 'W';
begin
FOR x IN tname_cursor LOOP
str := 'drop table '||x.table_name;
dbms_output.put_line(str);
EXECUTE IMMEDIATE str;
END LOOP;
END;
/
里这句 FOR x IN tname_cursor LOOP
str := 'drop table '||x.table_name; 中不是变量啊,怎么也可以运行呢?而且执行结果还是正常的
str varchar2(1000);
CURSOR tname_cursor IS
SELECT table_name
FROM user_tables
where table_name like 'W%';
begin
FOR x IN tname_cursor LOOP
str := 'drop table '||x.table_name;
dbms_output.put_line(str);
EXECUTE IMMEDIATE str;
END LOOP;
END;
/
scott@LYMORA> desc w;
名称 是否为空? 类型
----------------------------------------------------------------- -------- -----------------------------------------
A NUMBERscott@LYMORA> declare
2 str varchar2(1000);
3 CURSOR tname_cursor IS
4 SELECT table_name
5 FROM user_tables
6 where table_name like 'W%';
7
8
9 begin
10
11 FOR x IN tname_cursor LOOP
12 str := 'drop table '||x.table_name;
13 dbms_output.put_line(str);
14 EXECUTE IMMEDIATE str;
15
16 END LOOP;
17 END;
18 /
drop table WPL/SQL 过程已成功完成。已用时间: 00: 00: 00.11
scott@LYMORA> desc w;
ERROR:
ORA-04043: 对象 w 不存在
scott@LYMORA>
在循环中,其实执行了
open tname_cursor;
fetch tname_cursor into x;
的操作。
-- x 这只是一个变量的名字! 你要这样问的话,那你的游标名为什么也可以随便写呢?-- 在你出生,还没有命名之时,你的名字是不是可以随便取,但是一旦注册了(有身份证了),是不是修改名……
[/Quote]
-- 是的,但变量名不能以数据开头!
-- 建议去看一看 oracle 变量命名规则!
说的
x 默认就是 tname_cursor 的记录类型。
在循环中,其实执行了
open tname_cursor;
fetch tname_cursor into x;
的操作。
呵呵,在次感谢两位