0

我已经通过这种方式实现了参数化查询。你知道任何变体吗?

WITH temp AS (SELECT 'case1' case FROM DUAL)
SELECT 1
  FROM temp
 WHERE    (    (1 = DECODE (case, 'case1', 1, 0))
           AND SYSDATE > TO_DATE ('01/01/2013', 'DD/MM/YYYY'))
       OR (    (1 = DECODE (case, 'case2', 1, 0))
           AND SYSDATE < TO_DATE ('01/01/2013', 'DD/MM/YYYY'))
4

3 回答 3

3

你可以用案例

WITH temp AS (SELECT 'case1' _case FROM DUAL)
SELECT 1
  FROM temp
 WHERE   
 1 = case
      when _case = 'case1'
      AND SYSDATE > TO_DATE ('01/01/2013', 'DD/MM/YYYY')
      then 1
      when _case = 'case2'
      AND SYSDATE > TO_DATE ('01/01/2013', 'DD/MM/YYYY')
      then 1
      else 0
     end 
; 
于 2013-07-18T11:57:25.560 回答
2

这似乎很尴尬。你可以用基本的逻辑来做到这一点:

WITH temp AS (SELECT 'case1' case FROM DUAL)
SELECT 1
FROM temp
WHERE ((case = 'case1') and SYSDATE > TO_DATE('01/01/2013', 'DD/MM/YYYY')) or
      ((case = 'case2') and SYSDATE < TO_DATE('01/01/2013', 'DD/MM/YYYY'))
于 2013-07-18T11:25:54.363 回答
0

为什么不使用函数:

 CREATE FUNCTION x ( p_case IN VARCHAR2, p_date IN VARCHAR2 )
 RETURN INTEGER
 IS
 BEGIN
      IF p_case = 'case1' AND TO_DATE(p_date, 'DD/MM/YYYY') < SYSDATE THEN RETURN 1;
      ELSE IF p_case = 'case2' AND TO_DATE(p_date, 'DD/MM/YYYY') < SYSDATE THEN RETURN 1;
      ELSE RETURN 0;
      END IF;
 END;

 SELECT 1 FROM dual WHERE x('case1', '01/01/2013') = 1;
于 2013-07-18T11:27:51.293 回答