日期:2014-05-17  浏览次数:25759 次

ORA-00903: invalid table name
SQL code

SQL> select table_name from user_tables where table_name like 'T_';

TABLE_NAME
------------------------------
TB
T5
T4
T2
T1



SQL code

declare
    s varchar2(100);
begin
    for x in (select table_name from user_tables where table_name like 'T_') loop
        s := 'drop table :1';
        dbms_output.put_line(s);
        execute immediate s using x.table_name;
    end loop;
end;



错误如下:请问这是怎么回事啊?
SQL code

drop table :1
declare
*
ERROR at line 1:
ORA-00903: invalid table name
ORA-06512: at line 7



------解决方案--------------------
s := 'drop table :1';
dbms_output.put_line(s);
execute immediate s using x.table_name;
因为你这段话等效于
drop table 'T1';
------解决方案--------------------
探讨
引用:
s := 'drop table :1';
dbms_output.put_line(s);
execute immediate s using x.table_name;
因为你这段话等效于
drop table 'T1';



SQL code




1 declare
2 s varchar2(100);
3……

------解决方案--------------------
在表名上有所有无法处理了