문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top