oracle ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和

4c8rllxm  于 2022-12-22  发布在  Oracle
关注(0)|答案(7)|浏览(146)

我尝试通过Java执行查询,如下所示:

public ResultSet execSumStatment2() throws SQLException{
String query = "Select SUM(A) as NCCSeptember from NCC where Datum >= '01-09-2013 00:00:00' and Datum <= '30-09-2013 23:59:59'";
return execStatement(query);
}

然后在类中调用execSumStatement:

sql.execSumStatement2 () ;

当我运行它时,我得到以下错误消息:
java.sql.SQLDataException:ORA-01830:日期格式图片在转换整个输入字符串之前结束

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:951)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:513)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:227)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:208)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:886)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1175)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1296)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3613)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3657)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1495)
at com.bachelorarbeit.SQLExecutor.execStatement(SQLExecutor.java:20)
at com.bachelorarbeit.SQLExecutor.execSumStatment2(SQLExecutor.java:56)
at com.bachelorarbeit.Test.doGet(Test.java:63)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

当我在SQL Developer中执行相同的查询时,它工作正常。我已经在Internet上进行了搜索,我猜问题是查询中日期的数据类型,应该是日期,但我尝试的所有方法都不起作用...

bnlyeluc

bnlyeluc1#

我认为你不应该依赖隐式转换,这是一种不好的做法。
相反,您应该这样尝试:

datenum >= to_date('11/26/2013','mm/dd/yyyy')

或类似

datenum >= date '2013-09-01'
zy1mlcev

zy1mlcev2#

你可以试试这个:

Select To_date ('15/2/2007 00:00:00', 'DD/MM/YYYY HH24:MI:SS'),
       To_date ('28/2/2007 10:12', 'DD/MM/YYYY HH24:MI:SS')
  From DUAL;
mjqavswn

mjqavswn3#

在SQL Developer中..转至“首选项”--〉“NLS”--〉并相应地更改日期格式

v7pvogib

v7pvogib4#

您在sql字符串中写入的是Timestamp,而不是Date。您必须将其转换为Date或将数据库字段的类型更改为Timestamp才能正确显示。

wswtfjt7

wswtfjt75#

你可以尝试如下它为我工作

select * from nm_admission where trunc(entry_timestamp) = to_date('09-SEP-2018','DD-MM-YY');
    • 或**
select * from nm_admission where trunc(entry_timestamp) = '09-SEP-2018';

您也可以尝试使用to_char,但请记住to_char的开销太大

select * from nm_admission where to_char(entry_timestamp) = to_date('09-SEP-2018','DD-MM-YY');

TRUNC(2018年9月17日08:30:11)将给出2018年9月17日00:00:00作为结果,您可以单独比较唯一的日期部分,时间部分将跳过。

m528fe3b

m528fe3b6#

您可以使用
第一个月
如果在SP中使用它,则变量数据类型应为Varchar2
and also in your ado.net code the datatype of your input parameter should be
OracleDbType.Varchar2
基本上我必须在我的SP中放置一个DateFrom和DateTo过滤器,所以我将日期作为字符串传递给它。

    • 注:**这是对我有效的解决方案之一,这个问题可能有更多的解决方案。
8xiog9wr

8xiog9wr7#

SELECT CAST(COLUMN_NAME AS DATE) FROM TABLE_NAME

相关问题