insert into table1(id,corp_id,type)
select fun_gid(),v_corp_id,t.type from table2 t where t.is_defualt = 1
说明:
     table1,table2为表名,
     fun_gid()生成ID的方法,
     v_corp_id已定义的变量,之前已赋值
请教:这个动态sql怎么写?
如下这么写不对:
execute immediate
  'insert into table1(id,corp_id,type)
     select :id,:corp_id,t.type from table2 t where t.isdefualt = :isdefualt'
     using fun_gid(),v_corp_id,1

解决方案 »

  1.   

    execute immediate
    'insert into table1(id,corp_id,type)
    select '||fun_gid()||','||v_corp_id||',t.type from table2 t where t.is_defualt = 1'; 
      

  2.   

    报什么错 t.isdefualt = :isdefualt理论上楼主这样可以实现
      

  3.   

    execute immediate 
      'insert into table1(id,corp_id,type) 
        select t.id,t.corp_id,t.type from table2 t where t.id=:id and t.corp_id=:corp_id and t.isdefualt = :isdefualt' 
        using fun_gid(),v_corp_id,1 
      

  4.   

    execute immediate
    'insert into table1(id,corp_id,type)
    select '||fun_gid()||','||v_corp_id||',t.type from table2 t where t.is_defualt = 1'; 
    UP!!!
    函数方法写在里面要用字串啦
      

  5.   

    where里面的绑定变量肯定没问题。select子句中的绑定变量还没这样用过,或者还有可能是using后面的函数问题,可以分两步试一下:
    1.将fun_gid()的值先覆盖一个变量,using里面改为这个变量。
    2.如果第1步还是报错的话,前两个变量改为1楼的方式拼起来,但是where里面还是用绑定变量。这个肯定没问题了。