如何取出filter_code列中的表达式,当表达式全部满足的时候返回‘0’,失败的时候把表达式的内容给全部返回出去,存在另一张表中,并逐条插入失败原因,返回结果,看那个条件有问题,示例如下
/**
case when user_status_id=1 
      and x_cust_count=1 
      and call_duration_nofree>10 
      and arrear_all_fee<1
      and (z_call_count>1  or bill_cust_count_last=1) and user_status_id=1 
      and x_cust_count=1 and arrear_all_fee<1 
      and (z_call_count>1 or bill_cust_count_last=1)  then '0' else '1' end*/我自己写的代码请大神看一下是否正确,没思路了,谢谢create or replace procedure sp_ceshi_case_lmx is
 --声明变量
  v integer;
  v_sql varchar2(1000);
 
begin
  
for v in (select to_number(t.condition_id)condition_id,t.rule_id,t.filter_code 
          from TB_EW_M_PAY_CONDIION_bak t 
          group by to_number(t.condition_id) ,t.rule_id,t.filter_code
          order by to_number(t.condition_id) ,t.rule_id,t.filter_code)
          
loop
          
          v_sql:=v_sql||v.filter_code ||' ' ;        
  end loop;execute immediate v_sql;
 /**往临时表中插入数据*/
insert into LMX_TB_EW_M_PAY_CONDIION 
     (
       rule_id,
       filter_name
     )
/**success 返回值'0',fail 返回值 '1'*/
select 
      rule_id,
      case when user_status_id=1 
      and x_cust_count=1 
      and call_duration_nofree>10 
      and arrear_all_fee<1
      and (z_call_count>1  or bill_cust_count_last=1) and user_status_id=1 
      and x_cust_count=1 and arrear_all_fee<1 
      and (z_call_count>1 or bill_cust_count_last=1)  then '0' else  v_sql end
      
      from TB_EW_M_PAY_CONDIION_bak;dbms_output.put_line(v_sql);end sp_ceshi_case_lmx;

解决方案 »

  1.   

    试试这个看,看我理解的对不对Select t.Rule_Id,
           Listagg(t.Filter_Code, '') Within Group(Order By t.Condition_Id)
      From Tb_Ew_m_Pay_Condiion_Bak t
     Group By t.Rule_Id;
      

  2.   


    看你截图像是以Rule_Id进行分组处理。过程中通过Rule_Id进行循环,执行失败就直接通过Rule_Id从B_EW_M_PAY_CONDIION_bak表中取数据插入新表;
    至于取数逻辑看你截图猜测
    1.如果Is_Must为1,filter_code取Operatino_Code为1的值(And)
    2.如果Is_Must为0,filter_code取Operatino_Code为1的值(Or)。
      

  3.   


    看你截图像是以Rule_Id进行分组处理。过程中通过Rule_Id进行循环,执行失败就直接通过Rule_Id从B_EW_M_PAY_CONDIION_bak表中取数据插入新表;
    至于取数逻辑看你截图猜测
    1.如果Is_Must为1,filter_code取Operatino_Code为1的值(And)
    2.如果Is_Must为0,filter_code取Operatino_Code为1的值(Or)。
    如果没有这个规律,你也可以对拼接好后的Listagg(t.Filter_Code, '') Within Group(Order By t.Condition_Id)
    进行截取拆分“And” 为截取点
      

  4.   


    最后还是没看明白,这一串很明显都不是你提供的表里面的字段,判断失败的原则是什么?查询无数据?.....
    call_duration_nofree>10  and  user_status_id=1  and  x_cust_count=1 and arrear_all_fee<1 and ( z_call_count>1  or  bill_cust_count_last=1 )
      

  5.   

    TB_EW_M_PAY_CONDIION_bak这个表中的字段filter_code连接起来有一个不成立及判定失败