${if()}sql参数

${if(a="sss","select * from table where  lotId='"+lotid+"' "," and  product='"+pro+"'")} 

想把 lotId='"+lotid+"' 这段 加上if(len(lotid=0,"" ," lotId='"+lotid+"' "))

判断 怎么弄

FineReport 燚燚燚 发布于 2020-10-16 11:52
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共3回答
最佳回答
2
cherishdqyLv7高级互助
发布于2020-10-16 11:59(编辑于 2020-10-16 11:59)

${if(a="sss","select * from table where  1=1 "+if(len(lotid)=0,"" ," and lotId='"+lotid+"' ")," and  product='"+pro+"'")}

  • 燚燚燚 燚燚燚(提问者) 我这边试不行啊,可以加你好友请教下吗
    2020-10-16 12:31 
  • cherishdqy cherishdqy 回复 燚燚燚(提问者) 那你看一下楼下shiroko的回复吧
    2020-10-16 14:36 
  • 燚燚燚 燚燚燚(提问者) 回复 cherishdqy ${IF(isSubLot=\"yes\",\" select t2.lot_id,t1.ROUTE_ID,t1.OPERATION_ID,t2.IN_QTY,t2.OUT_QTY,t2.yield from (SELECT T.STEP_SEQ,ROUTE_ID,OM.OPERATION_ID FROM (SELECT P.ROUTE_ID,P.OPERATION_RRN, MIN(P.STEP_SEQ) STEP_SEQ FROM PROCESS_WORKFLOW_SUMM P, PROCESS_MASTER PM WHERE P.PROCESS_RRN = PM.PROCESS_RRN -- AND P.PROCESS_VERSION = PM.CURRENT_VERSION AND P.PROCESS_VERSION = \'\"+ver+\"\' AND EXISTS (SELECT 1 FROM PRODUCT_PROCESS_MASTER PPM, PRODUCT_MASTER PM WHERE P.PROCESS_RRN = PPM.PROCESS_RRN and PPM.PRODUCT_RRN = PM.PRODUCT_RRN AND pm.product_id = \'\"+productId+\"\' ) group BY P.ROUTE_ID,P.OPERATION_RRN) T, OPERATION_MASTER OM WHERE T.OPERATION_RRN = OM.OPERATION_RRN) t1, (SELECT t.lot_id, t.route_id, t.operation_id, sum(t.move_in_qty1) IN_QTY, sum(t.move_out_qty1) OUT_QTY, round(decode(nvl(sum(t.move_in_qty1), 0), 0, 0, nvl(sum(t.move_out_qty1), 0) / nvl(sum(t.move_in_qty1), 0)), 6) yield FROM (select T.LOT_ID, T.STEP_SEQUENCE, T.ROUTE_ID, T.OPERATION_ID, T.MOVE_IN_QTY1, T.MOVE_OUT_QTY1, RANK() OVER(PARTITION BY T.LOT_RRN,T.ROUTE_ID, T.OPERATION_RRN order by T.STEP_SEQUENCE DESC) R from lot_step_history t, LOT_MASTER LM, p2rptda1.workorder wo,P2RPTDA1.Item i where t.move_out_qty1 is not null and lm.product_rrn = i.item_rrn(+) AND lm.Outer_Order_No = \'\"+orderNo+\"\' AND WO.WORK_ORDER_TYPE = \'\"+orderType+\"\' AND i.Encapsulated_Type = \'\"+encapsulatedType+\"\' AND lm.product_id = \'\"+productId+\"\' AND lm.LOT_ID = \'\"+lotId+\"\' AND T.PROCESS_VERSION = \'\"+ver+\"\' AND T.LOT_RRN = LM.LOT_RRN and lm.outer_order_no = wo.workorder_id(+) ) T WHERE R = 1 group by t.lot_id, t.route_id, t.operation_id) t2 where t1.ROUTE_ID = t2.ROUTE_ID(+) and t1.OPERATION_ID= t2.OPERATION_ID(+) order by t1.STEP_SEQ\",\"select 2 from dual\")}
    2020-10-16 16:35 
  • 燚燚燚 燚燚燚(提问者) 回复 cherishdqy 就是 大写and 那几个条件加上if(len) 判断
    2020-10-16 16:36 
  • 燚燚燚 燚燚燚(提问者) 回复 cherishdqy 多谢了
    2020-10-16 16:37 
最佳回答
1
shirokoLv6资深互助
发布于2020-10-16 13:45

你的代码一开始就是错的吧


select * from table where  1=1

${if(a="sss", if(len(lotid)=0,"" ," and lotId='"+lotid+"'")," and  product='"+pro+"'")}

最佳回答
0
firegunzxLv6高级互助
发布于2020-10-16 13:42

单看sql代码片段是矛盾的,最好吧整个sql都发出来,然后指出要在哪里加len0判断。

  • 燚燚燚 燚燚燚(提问者) ${IF(isSubLot=\"yes\",\" select t2.lot_id,t1.ROUTE_ID,t1.OPERATION_ID,t2.IN_QTY,t2.OUT_QTY,t2.yield from (SELECT T.STEP_SEQ,ROUTE_ID,OM.OPERATION_ID FROM (SELECT P.ROUTE_ID,P.OPERATION_RRN, MIN(P.STEP_SEQ) STEP_SEQ FROM PROCESS_WORKFLOW_SUMM P, PROCESS_MASTER PM WHERE P.PROCESS_RRN = PM.PROCESS_RRN -- AND P.PROCESS_VERSION = PM.CURRENT_VERSION AND P.PROCESS_VERSION = \'\"+ver+\"\' AND EXISTS (SELECT 1 FROM PRODUCT_PROCESS_MASTER PPM, PRODUCT_MASTER PM WHERE P.PROCESS_RRN = PPM.PROCESS_RRN and PPM.PRODUCT_RRN = PM.PRODUCT_RRN AND pm.product_id = \'\"+productId+\"\' ) group BY P.ROUTE_ID,P.OPERATION_RRN) T, OPERATION_MASTER OM WHERE T.OPERATION_RRN = OM.OPERATION_RRN) t1, (SELECT t.lot_id, t.route_id, t.operation_id, sum(t.move_in_qty1) IN_QTY, sum(t.move_out_qty1) OUT_QTY, round(decode(nvl(sum(t.move_in_qty1), 0), 0, 0, nvl(sum(t.move_out_qty1), 0) / nvl(sum(t.move_in_qty1), 0)), 6) yield FROM (select T.LOT_ID, T.STEP_SEQUENCE, T.ROUTE_ID, T.OPERATION_ID, T.MOVE_IN_QTY1, T.MOVE_OUT_QTY1, RANK() OVER(PARTITION BY T.LOT_RRN,T.ROUTE_ID, T.OPERATION_RRN order by T.STEP_SEQUENCE DESC) R from lot_step_history t, LOT_MASTER LM, p2rptda1.workorder wo,P2RPTDA1.Item i where t.move_out_qty1 is not null and lm.product_rrn = i.item_rrn(+) AND lm.Outer_Order_No = \'\"+orderNo+\"\' AND WO.WORK_ORDER_TYPE = \'\"+orderType+\"\' AND i.Encapsulated_Type = \'\"+encapsulatedType+\"\' AND lm.product_id = \'\"+productId+\"\' AND lm.LOT_ID = \'\"+lotId+\"\' AND T.PROCESS_VERSION = \'\"+ver+\"\' AND T.LOT_RRN = LM.LOT_RRN and lm.outer_order_no = wo.workorder_id(+) ) T WHERE R = 1 group by t.lot_id, t.route_id, t.operation_id) t2 where t1.ROUTE_ID = t2.ROUTE_ID(+) and t1.OPERATION_ID= t2.OPERATION_ID(+) order by t1.STEP_SEQ\",\"select 2 from dual\")}
    2020-10-16 16:40 
  • 燚燚燚 燚燚燚(提问者) AND lm.Outer_Order_No = \'\"+orderNo+\"\' AND WO.WORK_ORDER_TYPE = \'\"+orderType+\"\' AND i.Encapsulated_Type = \'\"+encapsulatedType+\"\' AND lm.product_id = \'\"+productId+\"\' AND lm.LOT_ID = \'\"+lotId+\"\' AND T.PROCESS_VERSION = \'\"+ver+\"\' 这几个加上if(len) 判断
    2020-10-16 16:40 
  • 4关注人数
  • 925浏览人数
  • 最后回答于:2020-10-16 13:45
    请选择关闭问题的原因
    确定 取消
    返回顶部