execute immediate v_sql的例子:
            begin
              v_sql := 'select channel_id  from imp_sh_cms_channel where wg_code =' ||
                       in_wg_id;
              execute immediate v_sql
                into v_contentid;
            exception
              when no_data_found then
                out_result := 1; -- can't find data in imp_sh_cms_channel
                rollback;
                return;
            end;
直接使用sql的例子:
         begin
         select channel_id into v_contentid from imp_sh_cms_channel where wg_code=in_wg_id;
               exception
               when no_data_found then
               out_result := 1;  -- can't find data in imp_sh_cms_channel
               rollback;
               return;
         end;

解决方案 »

  1.   

    就单纯的你这个例子来说
    两者返回的结果是一样的,想你这样情况就没有必要用动态SQL
      

  2.   

    此例没必要用动态SQL。
    动态SQL是指SQL文不确定时,不同条件下,拼接出不同SQL文。
      

  3.   

    你只传入一个值的话,效率上基本没什么区别
    另外用动态SQL的另一种情况就是在programme中执行DDL语句
      

  4.   

    执行的SQL:--每一个值不一样,SQL语句也不一样。也有可能导致执行计划不一样
    select channel_id from imp_sh_cms_channel where wg_code = '123';
    select channel_id from imp_sh_cms_channel where wg_code = '456';--这是使用绑定变量
    select channel_id from imp_sh_cms_channel where wg_code = :code;google一下:绑定变量http://www.google.com.hk/search?hl=zh-CN&source=hp&q=%E7%BB%91%E5%AE%9A%E5%8F%98%E9%87%8F&meta=&aq=f&aqi=&aql=&oq=&gs_rfai=
      

  5.   

    只能上CSDN,不能其他外网 
    悲哀啊