Can least/greatest be used in where clause
ChingJan 13 2010 — edited Jan 15 2010My database is partitined by day, with index ndate from 1-366. When I set p10_sdate='30-DEC-09' and p10_edate='10-JAN-10', Used ndate (with date 1-366) in where cause, return 1 row only, without using ndate, return all rows
-Without using partitioned index in where clause, the query retrun result correctly, but performance suffer
-Using partitioned index in where clause, the query return wrong result, even though the performance is better
bad sql:
SELECT * FROM PERF_OWNER.RAW_BEST1_SYSTEM_STATISTICS
WHERE HOST = LOWER (:P10_HOST) AND TDATE BETWEEN :P10_SDATE AND :P10_EDATE
AND (ndate BETWEEN
LEAST (TO_CHAR (TO_DATE (:P10_SDATE, 'DD-MON-RR'),'DDD'), TO_CHAR (TO_DATE (:P10_EDATE, 'DD-MON-RR'),'DDD'))
AND GREATEST (TO_CHAR (TO_DATE (:P10_SDATE, 'DD-MON-RR'),'DDD'), TO_CHAR (TO_DATE (:P10_EDATE, 'DD-MON-RR'),'DDD')))
good sql:
SELECT * FROM PERF_OWNER.RAW_BEST1_SYSTEM_STATISTICS
WHERE HOST = LOWER (:P10_HOST) AND TDATE BETWEEN :P10_SDATE AND :P10_EDATE
Could anybody let me know what is wrong with my 'bad' sql?
1. are least and greatest allowed in where clause
2. ndate has 1-366 as value. When my parameter, the where clause had 'ndate between 365 and 010. If this is wrong, what is 'normal' way to handle the case?
Thank you in advance for your help