var
temp   varchar2(1000);
begin
  temp:='';
  temp:='create table aa(bb varchar2(100));'
  execute immediate temp;
end;

解决方案 »

  1.   

    SQL> create or replace procedure create_table_aa
      2  authid current_user
      3  as
      4  str1   varchar2(1000);
      5  str2   varchar2(1000);
      6  begin
      7  str1:='drop table aa';
      8  execute immediate str1;
      9  str1:='create table aa(bb nvarchar2(100))';
     10  execute immediate str1;
     11  exception
     12  when others then
     13  str2:=sqlerrm(sqlcode);
     14  dbms_output.put_line(str2);
     15  end;
     16  /过程已创建。SQL> execute create_table_aa;PL/SQL 过程已成功完成。SQL> desc aa
     名称                                                  空?      类型
     ----------------------------------------------------- -------- ----------------
     BB                                                             NVARCHAR2(100)SQL> execute create_table_aa;PL/SQL 过程已成功完成。SQL> desc aa
     名称                                                  空?      类型
     ----------------------------------------------------- -------- ----------------
     BB                                                             NVARCHAR2(100)
      

  2.   

    在存储过程里不能直接用CREATE TABLE这样的语句来建立表,是吗?
      

  3.   

    在存储过程用动态sql就可以了,drop 和 create 要连用,以免出现create已经存在的表,
      

  4.   

    见鬼了,我按楼上的建了个表AA,不过建完就找不到它到哪去了desc aa 就说Object AA not found。我在自己的表空间里找了半天也没找到
      

  5.   

    to sasacat(傻傻猫)
    估计你的表没有建成,查看一下错误提示,
    在执行前设置:set serveroutput on size 1000000
      

  6.   

    又试了一次,这次错误提示是ORA-00942: 表或视图不存在
    PL/SQL procedure successfully completed这表示我的表没建成吗?为什么我建不了表呢,是因为我的角色权限不够还是别的原因?