Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Can least/greatest be used in where clause

ChingJan 13 2010 — edited Jan 15 2010
My 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 12 2010
Added on Jan 13 2010
6 comments
1,529 views