有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

SpringJDBC绑定java。sql。oracle日期问题的时间戳

我目前正在使用Spring的NamedParameterJdbcTemplate向sql注入一些值。当我将两个java.sql.Timestamp值注入sql时,我遇到了性能问题,而sql的oracle列的类型是DATE并正在执行

它非常慢(大约4分钟),但当我通过sql developer运行它时,它会在不到一秒钟内执行,因为我在DATE列上有一个索引。下面是我调试日志的一个片段:

select * from test_table.test_column where eventts >= :startDate and eventts <= :endDate and loginname= :loginname and channelind= :channelind
2014-04-21 15:02:50 48416 [http-8080-1] DEBUG org.springframework.jdbc.core.JdbcTemplate  - Executing prepared SQL query
2014-04-21 15:02:50 48417 [http-8080-1] DEBUG org.springframework.jdbc.core.JdbcTemplate  - Executing prepared SQL statement [select * from test_table.test_column where eventts >= ? and eventts <= ? and loginname= ? and channelind= ?]
2014-04-21 15:02:50 48417 [http-8080-1] DEBUG org.springframework.jdbc.datasource.DataSourceUtils  - Fetching JDBC Connection from DataSource
2014-04-21 15:02:50 48438 [http-8080-1] DEBUG org.springframework.jdbc.core.StatementCreatorUtils  - Setting SQL statement parameter value: column index 1, parameter value [2014-04-21 12:02:38.0], value class [java.sql.Timestamp], SQL type 93
2014-04-21 15:02:50 48439 [http-8080-1] DEBUG org.springframework.jdbc.core.StatementCreatorUtils  - Setting SQL statement parameter value: column index 2, parameter value [2014-04-22 00:00:00.0], value class [java.sql.Timestamp], SQL type 93
2014-04-21 15:02:50 48439 [http-8080-1] DEBUG org.springframework.jdbc.core.StatementCreatorUtils  - Setting SQL statement parameter value: column index 3, parameter value [MY_LOGIN], value class [java.lang.String], SQL type unknown
2014-04-21 15:02:50 48439 [http-8080-1] DEBUG org.springframework.jdbc.core.StatementCreatorUtils  - Setting SQL statement parameter value: column index 4, parameter value [WEB], value class [java.lang.String], SQL type unknown

我错过了什么?Oracle是否将值强制转换为TIMESTAMP导致丢失我在“events”DATE列上的索引


共 (1) 个答案

  1. # 1 楼答案

    我想你的猜测是对的。 当你有

    select something from some_table where column1 = :val1
    

    va1与column1的类型不同,Oracle会:

    select something from some_table where to_val1type(column1) = :val1
    

    to_val1type函数不存在,它将由上下文决定(to_DATE、to_NUMBER等)

    要么使用相同类型的参数,要么自己使用函数