问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/2829409/oracle-sql-using-bind-variable-for-dates