1

execute immediate我正在尝试使用语句将数据插入表中。但我得到一个错误

FROM keyword not found where expected

任何人都可以看看有什么问题吗?

declare
  c1 SYS_REFCURSOR;
  v_tabl_name varchar2(30);
begin
  open c1 for
    select tablename from table1;

  LOOP
    FETCH c1 INTO v_tabl_name;
    EXIT WHEN c1%NOTFOUND;

    execute immediate 'insert tabl2(tabl_name) (select ''tem'' from'||v_tabl_name||')' ;
  END LOOP;

  close c1;
end;
4

1 回答 1

0
create table table1(tem varchar2(50), tablename varchar2(50));
create table tabl2(tabl_name varchar2(50));

insert into table1(tem, tablename) values ('table1','table1');

begin
  for rc in (select tablename from table1) loop
     --dbms_output.put_line('insert into tabl2(tabl_name) (select ''tem'' from '||rc.tablename||')');
     execute immediate 'insert into tabl2(tabl_name) (select ''tem'' from '||rc.tablename||')' ;    
  end LOOP; 
end;
于 2015-10-30T10:05:49.237 回答