Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Oracle Sql Statement
Message
 
General information
Forum:
Oracle
Category:
Other
Miscellaneous
Thread ID:
00802182
Message ID:
00803268
Views:
26
Mark,
First, I wouldn't recommend doing the conversion for the index. Simply index on the datetime field itself. The index will be smaller.

Second, if you are always going to combine the two peices of information for your queries, then you can create a compound index expression. Put the datetime field first and then add the character field. You don't have to convert them. Oracle can handle different data types in compound indexes without any problems.

Third, if option 2 isn't available for you, you can always use a subquery to force Oracle into querying in the correct order. The subquery would extract all the rows that fell into the correct date range. The outer query would use that result set to extract all the rows that had a cStatus of 'A'.
select * from 
   (SELECT * FROM voter 
      WHERE tDob 
      between TO_DATE("12/31/1971 12:00:00 am","MM/DD/YYYY HH:MI:SS AM") 
         and TO_DATE("12/31/1971 11:59:59 pm","MM/DD/YYYY HH:MI:SS AM")) 
where cStatus = 'A'
HTH.

>Like I explained before, our fields are DATETIME ie 12/31/1971 11:59:59 pm. If I just do a [tDob = to_date("12/31/1971","MM/DD/YYYY")] I get 0 records. Because for what ever reason, oracle wants to filter on the TIME too. So, i have to do the BETWEEN. With that said, I created an INDEX on the TDOB field as follows TO_CHR(tDob, "MM/DD/YYYY"). When I create my sql as follows [TO_CHAR(tDob, "MM/DD/YYYY") = "12/31/1971" it works, but the problem I have there is ORACLE doesn't use the INDEX I created w/ out being told to do so with the HINTs clause.
>
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform