开发者

Oracle sql: using bind variable for dates

开发者 https://www.devze.com 2022-12-30 09:10 出处:网络
Here is a simple working query without bind variables: select * from table1 where time_stamp > sysdate - INTERVAL \'1\' day;

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 &开发者_运维知识库gt; 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消