Home » SQL & PL/SQL » SQL & PL/SQL » Dynamic Condition in STATIC SQL (Oracle 11g)
Dynamic Condition in STATIC SQL [message #600582] Fri, 08 November 2013 12:02 Go to next message
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 #600583 is a reply to message #600582] Fri, 08 November 2013 12:05 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
SQL must be known and static at compile time.

> I do want to modify this to gain performance improvement for the remaining 11 months of the query execution.
post EXPLAIN PLANs that show actual performance gain results for the different SQL statements
Re: Dynamic Condition in STATIC SQL [message #600584 is a reply to message #600583] Fri, 08 November 2013 12:15 Go to previous messageGo to next message
achockal
Messages: 5
Registered: November 2013
Junior Member
I am not able to access the Explain Plan as it is restricted for me.

But I see an improve of 10 sec for execution of the query without to_char(a.date3,'MON')!= 'AUG' condition
Re: Dynamic Condition in STATIC SQL [message #600585 is a reply to message #600584] Fri, 08 November 2013 12:18 Go to previous message
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

Previous Topic: Writing to CSV or excel using UTL_FILE in ORACLE
Next Topic: Record vs Object problem
Goto Forum:
  


Current Time: Wed Apr 24 12:06:10 CDT 2024