SQL 日期格式绑定变量

发布于 2024-09-12 18:59:10 字数 1251 浏览 11 评论 0原文

谁能告诉我这个 SQL 查询有什么问题吗?

select 
    USERNAME, DATECREATED, CREDTYPE, USAGETYPE,  OPERATIONID, TXNID, CALLERID 
from 
    arwfissuanceauditlog 
where 
    OPERATIONID in (2104,2107) 
and datecreated >= 'to_date('2010/06/21', 'yyyy/MM/dd HH24:MI:SS')' 
and datecreated < 'to_date('2010/08/03', 'yyyy/MM/dd HH24:MI:SS')'

当我在 SQL Developer 中运行它时,我收到此消息

Unknown Command
Bind Variable "MI" is NOT DECLARED

,我从 java 中调用此消息,如下所示

try {
            stmt = conn.createStatement();
            results = stmt.executeQuery(queryToExecute);
        } catch (SQLException e) {
            CredChangeReportSVC.DEFAULTLOGGER.error("An exception occurred while executing query: " + queryToExecute, e);
}

在日志中,我收到此消息

ERROR 03 Aug 2010 14:51:06,939 - An exception occurred while executing query: "select USERNAME, DATECREATED, CREDTYPE, USAGETYPE,  OPERATIONID, TXNID, CALLERID from arwfissuanceauditlog where OPERATIONID in (2104,2107) and datecreated >= 'to_date('2010/06/21', 'yyyy/MM/dd HH24:MI:SS')' and datecreated < 'to_date('2010/08/03', 'yyyy/MM/dd HH24:MI:SS')'"
java.sql.SQLException: Invalid SQL type

提前致谢。

Can anyone please tell me what is wrong with this SQL query.

select 
    USERNAME, DATECREATED, CREDTYPE, USAGETYPE,  OPERATIONID, TXNID, CALLERID 
from 
    arwfissuanceauditlog 
where 
    OPERATIONID in (2104,2107) 
and datecreated >= 'to_date('2010/06/21', 'yyyy/MM/dd HH24:MI:SS')' 
and datecreated < 'to_date('2010/08/03', 'yyyy/MM/dd HH24:MI:SS')'

I got this message when I ran it in SQL developer

Unknown Command
Bind Variable "MI" is NOT DECLARED

I am calling this from java like this

try {
            stmt = conn.createStatement();
            results = stmt.executeQuery(queryToExecute);
        } catch (SQLException e) {
            CredChangeReportSVC.DEFAULTLOGGER.error("An exception occurred while executing query: " + queryToExecute, e);
}

In the logs I get this message

ERROR 03 Aug 2010 14:51:06,939 - An exception occurred while executing query: "select USERNAME, DATECREATED, CREDTYPE, USAGETYPE,  OPERATIONID, TXNID, CALLERID from arwfissuanceauditlog where OPERATIONID in (2104,2107) and datecreated >= 'to_date('2010/06/21', 'yyyy/MM/dd HH24:MI:SS')' and datecreated < 'to_date('2010/08/03', 'yyyy/MM/dd HH24:MI:SS')'"
java.sql.SQLException: Invalid SQL type

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

瀞厅☆埖开 2024-09-19 18:59:10

您的日期格式指定了时间部分,但您在日期时间字符串中省略了它。从日期字符串中删除“HH24:MI:SS”,然后重试

Your date format specifies a time part, but you have omitted this in your datetime strings. Drop the "HH24:MI:SS" from the date strings and try again

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