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 楼答案
我想你的猜测是对的。 当你有
va1与column1的类型不同,Oracle会:
to_val1type函数不存在,它将由上下文决定(to_DATE、to_NUMBER等)
要么使用相同类型的参数,要么自己使用函数