本帖最后由 zhouzhiyuan1985 于 2010-05-13 15:29:44 编辑

解决方案 »

  1.   

    动态语句绑定变量
    execute immediate 'select column_name from user_tab_cols where rownum<2 and table_name=:1' into v_1 using 'TEST';
      

  2.   

    declare 
       l_depnam varchar2(20) := 'testing'; 
       l_loc     varchar2(10) := 'Dubai'; 
       begin 
       execute immediate 'insert into dept values   (:1, :2, :3)' 
         using 50, l_depnam, l_loc; 
       commit; 
    end; 说明:
        动态SQL语句使用了占位符“:1”,其实它相当于函数的形式参数,使用“:”作为前缀,
        然后使用using语句将“50”在运行时刻将“:1”给替换掉,这里“50”相当于函数里的实参。
      

  3.   

      --这样
      if nvl(pOrganizationCode,'')<>'' or pOrganizationCode is not null then
       vSQL := vSQL ||' AND em.organizationCode=:pOrganizationCode';
      else
       pOrganizationCode := '1';
       vSQL := vSQL ||' AND ''1''=:pOrganizationCode';
      end if;  
      --其它条件类似
      
      --动态游标
       open c_Cur for vSQL using pOrganizationCode,....;