insert into t_Table
(id,name,address,phone,TableName)
select id,name,address,phone,'t_Customer'
from t_Customer

解决方案 »

  1.   

    如果't_Customer'的值存在一变量v_Tablename中
    要写动态SQL怎么写呢
      

  2.   

    动态SQL:
    STRSQL VARCHAR(100);
    V_TABLENAME VARCHAR(10);
    STRSQL:='insert into t_Table(id,name,address,phone,TABLENAME)';
    STRSQL:=STRSQL || 'select id,name,address,phone,' || V_TABLENAME;
    STRSQL:=STRSQL || 'FROM' || V_TABLENAME;
    EXECUTE IMMEDIATE STRSQL;