Oracle sql:使用日期的绑定变量
这是一个没有绑定变量的简单工作查询:
select * from table1 where time_stamp > sysdate - INTERVAL '1' day;
其中 time_stamp
的类型为 DATE
。
我应该能够使用绑定变量在上述查询中输入任意天数。
所以我尝试了以下方法,但似乎不起作用:
select * from table1 where time_stamp > sysdate - INTERVAL :days day;
我尝试输入数字输入作为 10 和“10”,例如。您在 10g 上收到 ORA-00933 错误。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原始查询中的字符串
INTERVAL '1' day
是一个间隔文字,即解析器将其计算为单个值。您不能用绑定变量替换它的一部分。如果您改为使用
NUMTODSINTERVAL( 1, 'DAY' )
,则 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.