Question

Here is a simple working query without bind variables:

select * from table1 where time_stamp > sysdate - INTERVAL '1' day;

where time_stamp is of type DATE.

I should be able to input any number of days in the above query using bind variable.

So I tried the following and does not seem to work:

select * from table1 where time_stamp > sysdate - INTERVAL :days day;

I tried entering the numeric input both as 10 and '10',for eg. You get ORA-00933 error on 10g.

Was it helpful?

Solution

The string INTERVAL '1' day in your original query is an interval literal, i.e. it is evaluated by the parser to a single value. You can't replace part of it with a bind variable.

If you instead use NUMTODSINTERVAL( 1, 'DAY' ), then 1 is an integer literal which you should be able to replace with a bind variable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top