在命令窗口中是绝对可以执行的,但我现在不知道在(比如)存储过程中如何来执行这个块呢
不能用游标,我的意思是我把这个块读到一个变量中。然后用execute immediate 变量名来执行这个块,但是立即执行不支持执行块的语句,只能单条语句执行。请教大侠用哪个命令可以执行块语句呢?

解决方案 »

  1.   

    比如数据库表:
    create table test(a varchar2(1000),id);
    insert into test values ('declare b varchar2(1000);
    begin
     select a into b from test where id=1;
     insert into test values (b,2);
     commit;
    end;',1);在存储过程中执行:
    create procedure aa as
    v_sql varchar2(1000);
    begin
    select a into v_sql from test where id=1;
    execute immediate v_sql;
    end;这样执行就会出现错误。还有没有别的办法呢?
      

  2.   

    select a into v_sql from test where id=1;
    execute immediate v_sql;
    怎么能这样做,当然错了
    你直接写insert into test values (v_sql,2);就可以了要不也可以execute immediate 'insert into test values (v_sql,2)';
      

  3.   

    不好意思,错了
    execute immediate 'insert into test values (:1,2)' using v_sql;
      

  4.   

    to leborety(那只螃蟹) 你可能理解错了,目的不是往数据库里插入数据。我只是举个例子。我是要通过存储过程来执行 v_sql 中的内容,而v_sql不是一个单条语句,而是一个块语句。
      

  5.   

    楼上越摸越黑块语句不是你那样写的create procedure aa as
    v_sql varchar2(1000);
    num number;
    begin
    v_sql:='select a into num from test where id=1';
    execute immediate v_sql;
    end;
    这样才对
      

  6.   

    我知道execute immediate 只能执行单条语句,那能不能有那一个命令可以执行块语句呢?
      

  7.   

    把你要执行的东西选到sql脚本中,然后再执行.
      

  8.   

    揭帖,其实是非常的简单,用execute immediate 执行有可以了。为什么这么久都没有人能回答的上。唉............................