I have a table with an oracle date column
我有一个带有oracle日期列的表
when I do a select on sqlplus on the column it gives me the value like this
当我对列上的sqlplus进行选择时,它给出了这样的值
10-JAN-2007
- Is this the precision of date in an Oracle column i,e does it not have hour sec, millisec in the date column.
- How can I map this to a java timestamp and get seconds since epoch.
这是Oracle列i中日期的精确度,它是否在日期列中没有小时秒,毫秒。
我如何将其映射到java时间戳并获得自纪元以来的秒数。
2 个解决方案
#1
If you select it using java.sql Statement/PreparedStatement, it will return a java.sql.Date, which you can then do a .getTime() on just like a regular java.util.Date.
如果您使用java.sql Statement / PreparedStatement选择它,它将返回一个java.sql.Date,然后您可以像常规java.util.Date一样执行.getTime()。
Depending on the RDBMS, if you really want a timestamp, though, you have to make the column a timestamp type and select it into a java.sql.Timestamp. Otherwise it will give you the time of 12am.
但是,根据RDBMS,如果您确实需要时间戳,则必须使该列成为时间戳类型并将其选择为java.sql.Timestamp。否则它会给你12点的时间。
#2
No, the Oracle DATE column does store hours, minutes and seconds. However, sqlplus will only show month, day, year by default. Use the following before running your query to show the full date and time:
不,Oracle DATE列确实存储了小时,分钟和秒。但是,sqlplus默认只显示月,日,年。在运行查询之前使用以下命令来显示完整的日期和时间:
alter session set NLS_DATE_FORMAT='DD-MM-YYYY HH24:MI:SS';
The difference between the DATE and TIMESTAMP column types in Oracle is that TIMESTAMP will store fractional seconds.
Oracle中DATE和TIMESTAMP列类型之间的区别在于TIMESTAMP将存储小数秒。
#1
If you select it using java.sql Statement/PreparedStatement, it will return a java.sql.Date, which you can then do a .getTime() on just like a regular java.util.Date.
如果您使用java.sql Statement / PreparedStatement选择它,它将返回一个java.sql.Date,然后您可以像常规java.util.Date一样执行.getTime()。
Depending on the RDBMS, if you really want a timestamp, though, you have to make the column a timestamp type and select it into a java.sql.Timestamp. Otherwise it will give you the time of 12am.
但是,根据RDBMS,如果您确实需要时间戳,则必须使该列成为时间戳类型并将其选择为java.sql.Timestamp。否则它会给你12点的时间。
#2
No, the Oracle DATE column does store hours, minutes and seconds. However, sqlplus will only show month, day, year by default. Use the following before running your query to show the full date and time:
不,Oracle DATE列确实存储了小时,分钟和秒。但是,sqlplus默认只显示月,日,年。在运行查询之前使用以下命令来显示完整的日期和时间:
alter session set NLS_DATE_FORMAT='DD-MM-YYYY HH24:MI:SS';
The difference between the DATE and TIMESTAMP column types in Oracle is that TIMESTAMP will store fractional seconds.
Oracle中DATE和TIMESTAMP列类型之间的区别在于TIMESTAMP将存储小数秒。