存储过程中动态拼接sql,拼接单引号问题


create or replace procedure mergerOrder(
      v_ids in varchar2,
      v_productCode in varchar2,
      v_productCateCode in varchar2) is
      type cur_type is ref cursor;
      cur_policy cur_type;

      rec_policy ecc_pln.order_detail2%rowtype;
      sqlStr varchar2(500);

begin
       sqlStr := 'select id ,order_number from ecc_pln.order_detail2 d where 1=1';
         if v_ids is not null then
           sqlStr := sqlStr || ' and d.id in( SELECT COLUMN_VALUE FROM TABLE(jomoo_oms.SPLIT('''||v_ids||''')))';
         end if;
         if v_productCode is not null then
           sqlStr := sqlStr || ' and d.material_code='''|| v_productCode||'''';
         end if;
         if v_productCateCode is not null then
           sqlStr := sqlStr || ' and d.product_ca_code=''' || v_productCateCode||'''' ;
         end if;
       Dbms_Output.put_line('sqlStr: '||sqlStr);

     open cur_policy for sqlStr;
         loop
          fetch cur_policy into rec_policy.id, rec_policy.order_number;
             exit when cur_policy%notfound;

         Dbms_Output.put_line('id:'||rec_policy.id|| ' order_number:'||rec_policy.order_number);

        end loop;
     close cur_policy;
end mergerOrder;


你可能感兴趣的:(oracle问题解决)