create or replace procedure sunjq_test(p_func_id    IN VARCHAR2) is  v_sql         varchar2(5000);
begin
  
  v_sql := 'create table sunjq_test_base as select * from func_config';
  execute immediate v_sql;
    
  v_sql := 'create table sunjq_test_select as select func_id,func_desc from sunjq_test_base';
  execute immediate v_sql;  commit;
exception
  when others then
    dbms_output.put_line('异常');
end;为什么最后会显示异常,我的动态SQL语句没问题啊?
另外:如果我想分别判断上述两个动态SQL到底是哪出了问题,或者是分别判断异常,而不是在最后写一个exception,该怎么弄

解决方案 »

  1.   

    改为下面的试试create or replace procedure sunjq_test(p_func_id    IN VARCHAR2) is 
      v_sql varchar2(5000); 
    begin 
      v_sql := 'create table sunjq_test_base as select * from func_config;';     
      v_sql := v_sql||'create table sunjq_test_select as select func_id,func_desc from sunjq_test_base;'; 
      execute immediate v_sql; 
    exception 
      when others then 
        dbms_output.put_line('异常'||sqlerrm); 
    end; 
      

  2.   

    先把 exception 那段去掉, 看看到底是什么错
      

  3.   

     v_sql varchar2(5000); 
    不知道是不是这个报的错,pl/sql里定义变量能这么大么?
      

  4.   

    似乎少了begin .. endcreate or replace procedure sunjq_test(p_func_id IN VARCHAR2) is 
      v_sql varchar2(5000); 
    begin 
      begin
        v_sql := 'create table sunjq_test_base as select * from func_config;';     
        v_sql := v_sql||'create table sunjq_test_select as select func_id,func_desc from sunjq_test_base;'; 
        execute immediate v_sql; 
      exception 
        when others then 
          dbms_output.put_line('异常'||sqlerrm); 
      end;
    end; 
      

  5.   

    我在exception里加了
    dbms_output.put_line(SQLCODE);
    dbms_output.put_line(SQLERRM);测试显示说
    -1031
    ORA-01031: 权限不足
      

  6.   

    oracle中varchar2定义的字符最大长度为4000吧,你改成小点试一下
      

  7.   

    grant create table to  用户名; 
    为什么动态授权呢,直接给用户授建表权限就可以了吧
      

  8.   

    确定当前用户有对func_config表的查询权限
    确定当前用户有创建表的权限。
      

  9.   

    你这个表是当临时表用的吧?如果是,就直接先建好表吧。你的错误提示显示,运行这个SP的用户没有建表的权限,为什么要让SP动态去建表呢?如果多人并发执行这个SP就会出现问题了,干脆用临时表得了。