Conversion of number to date affect the performance in oracle -


i have below query dt_id number data type column , value stored in column date in format 'yyyymmdd'.

in below query want previous week data monday till sunday weekly reporting , query works fast.

select  id,name test_report  dt_id between 20170904 , 20170910; 

but hardcoded date , want make dynamic. tried query:

select  id,name test_report  dt_id>= next_day(trunc(sysdate), 'monday') - 14 ,           dt_id< next_day(trunc(sysdate), 'monday') - 7; 

but gives error:

expecting number , got date

when convert number date below query it's resulting lot of performance issue. there other way ican make dynamic better performance?

select  id,name test_report  to_date(dt_id,'yyyymmdd') >= next_day(trunc(sysdate), 'monday') - 14 ,           (dt_id,'yyyymmdd') < next_day(trunc(sysdate), 'monday') - 7; 

you can convert date values strings , numbers:

select  id,name test_report dt_id >= to_number (to_char (next_day(trunc(sysdate), 'monday') - 14,                            'yyyymmdd'))   , dt_id < to_number (to_char (next_day(trunc(sysdate), 'monday') - 7,                            'yyyymmdd')); 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -