Oracle sql:使用日期的绑定变量

发布于 2024-09-02 03:42:38 字数 407 浏览 1 评论 0原文

这是一个没有绑定变量的简单工作查询:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对你的占有欲 2024-09-09 03:42:38

原始查询中的字符串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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文