Dynamic Condition in STATIC SQL [message #600582] |
Fri, 08 November 2013 12:02 |
|
achockal
Messages: 5 Registered: November 2013
|
Junior Member |
|
|
Is there a way I can create a dynamic condition in Where clause of an sql query
I have a condition as mentioned below .
Is there a way I can MODIFY the last condition of where clause with case statement. I do want to modify this to gain performance
improvement for the remaining 11 months of the query execution.
where (( a.dat1 > sysdate-10 and a.date1 > sysdate-10)
or ( a.date2 > sysdate-10 and a.date2 > sysdate-10)
or ( a.date3 > sysdate-10 and a.date3 > sysdate-10 and to_char(a.date3,'MON')!= 'AUG' ))
case when to_char(a.date3,'MON')!= 'AUG'
THEN (a.date3 > sysdate-10 and a.date3 > sysdate-10
ELSE (a.date3 > sysdate-10 and a.date3 > sysdate-10 and to_char(a.date3,'MON')!= 'AUG' )
Appreciate your input and help on this.
|
|
|
|
|
Re: Dynamic Condition in STATIC SQL [message #600585 is a reply to message #600584] |
Fri, 08 November 2013 12:18 |
|
BlackSwan
Messages: 26766 Registered: January 2009 Location: SoCal
|
Senior Member |
|
|
SQL> connect scott/tiger
Connected.
SQL> set autotrace on explain
SQL>
SQL> select sysdate from dual;
SYSDATE
---------
08-NOV-13
Execution Plan
----------------------------------------------------------
Plan hash value: 1388734953
-----------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-----------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 (0)| 00:00:01 |
| 1 | FAST DUAL | | 1 | 2 (0)| 00:00:01 |
-----------------------------------------------------------------
[Updated on: Fri, 08 November 2013 12:19] Report message to a moderator
|
|
|