Hi,
I have a query that looks like
select *
from fact, dim_time
where fact.my_dt = dim_time.clndr_dt
and fact.my_dt between '1-jan-2005' and '10-mar-2005'
this query eliminates partitions which are based on week.
Now, if i replace the literal strings in the between clause with some kind of sub-queries that provide the values at run time, the partitions dont get eliminated. any ideas, clues, suggestions, advices? all are welcome and appreciated.
Regards,
Software/Hardware used:
ASKED:
May 27, 2005 8:09 PM
UPDATED:
June 6, 2005 1:38 PM
What does your subquery look like?
Nothing personal, but it doesn’t look like the first respondant is familar with Oracle date format.
It could be that your sub-queries don’t return what you think they do. By that I mean the BETWEEN is looking for dates and the queries may be returning characters. Check out the Oracle TO_DATE function.
May have to change your clause to fact.my_dt BETWEEN TO_DATE(sub-query1) and TO_DATE(sub-query2).
Hope this helps,
~ M
Nothing personal, but it doesn’t look like the first respondant is familar with Oracle date format.
It could be that your sub-queries don’t return what you think they do. By that I mean the BETWEEN is looking for dates and the queries may be returning characters. Check out the Oracle TO_DATE function.
May have to change your clause to fact.my_dt BETWEEN TO_DATE(sub-query1) and TO_DATE(sub-query2).
Hope this helps,
~ M
Hi
What you are assuming is that Oracle will convert the literal date strings to the datatype of you fact.my_dt column.
Since you say the subquery works, and the ‘hardcoded’ string literals does not, I assume that in your subquery you compare the fact.my_dt with a DATE, and NOT a varchar2.
Put a to_date around your literals and the query
should pick up your partitions.
For comparison try:
select * from dual where dummy = 1.
You will get an ‘invalid number’ error.
Why? Because Oracle converts the value in dummy to a number, not the number to a varchar2. (you can create a test table with a varchar and only put numbers in it, and the exception will not be thrown) Now try:
select * from dual where dummy = to_char(1).
Works like a charm
In your example Oracle will convert the value in fact.my_dt to varchar2, which works so no exception is thrown, but then you loose the concepts of weeks, so the partition can not be used.