我在plsqldev5.0中执行了没有任何错误

解决方案 »

  1.   

    语法没有错误,user_tables中含有了以_、$、#等非法字符开头的table_name,导致系统无法识别:
    declare 
      v_tablename varchar2(30);
      v_count pls_integer;
      v_sql varchar2(200);
      cursor c is 
        select to_char(table_name) from user_tables
        where tablespace_name in('SYSTEM','TOOLS','USERS');
    begin
      open c;
      loop
        fetch c into v_tablename;
        exit when c%notfound;
        execute immediate 'select count(*) from '||v_tablename into v_count;
        dbms_output.put_line('count is:'||v_count);
      
      end loop;
    exception
       when others then
       dbms_output.put_line('错误代码:'||sqlcode);
       dbms_output.put_line('错误内容:'||sqlerrm);
       dbms_output.put_line('错误表:'||v_tablename);
       
       close c;
     end;count is:0
    count is:2554
    count is:0
    count is:1
    count is:759
    错误代码:-911
    错误内容:ORA-00911: 无效字符
    错误表:_default_auditing_options_
      

  2.   

    解决办法:ORA-00911 invalid characterCause: Special characters are valid only in certain places. If special characters other than $, _, and # are used in a name and the name is not enclosed in double quotation s ("), this message will be issued. One exception to this rule is for database names; in this case, double quotes are stripped out and ignored.Action: Remove the invalid character from the statement or enclose the object name in double quotation s即在execute immediate 前一行加入:
     if substr(v_tablename,1,1)='_' or substr(v_tablename,1,1)='$' or substr    (v_tablename,1,1)='#' then
            v_tablename:='"'||v_tablename||'"';
     end if;
      

  3.   

    declare 开头的好像不可以直接执行阿!
      

  4.   

    sql×plusSYS>>declare
      2    v_tabname varchar2(30);
      3    v_count pls_integer;
      4    cursor c_table is 
      5      select table_name from user_tables 
      6         where tablespace_name in('SYSTEM','TOOLS','USERS');
      7  begin
      8     open c_table;
      9     loop
     10       fetch c_table into v_tabname;
     11       exit when c_table%notfound;
     12       execute immediate 'select count(*) from ' || v_tabname into 
     13  v_count;
     14       if v_count > 0 then
     15         execute immediate 'create table ' || v_tabname || 'bk as 
     16  select * from ' || v_tabname;
     17         execute immediate 'drop table ' || v_tabname;
     18         execute immediate 'alter table ' || v_tabname || 'bk rename 
     19  to ' || v_tabname;
     20         dbms_output.put_line('success move table: ' || v_tabname);
     21       else
     22         execute immediate 'drop table ' || v_tabname;
     23         dbms_output.put_line('success delete table: ' || v_tabname);
     24       end if;
     25     end loop;
     26     close c_table;
     27  end;
     28  /
    declare
    *
    ERROR 位于第 1 行:
    ORA-00942: 表或视图不存在
    ORA-06512: 在line 17
    已用时间:  00: 00: 01.01
    SYS>>show error;
    没有错误。
    SYS>>