为什么CURRENT_DATE包含Oracle模式中的时间?

时间:2022-05-18 08:46:18

When I connect to

当我连接到

jdbc:hsqldb:mem:lbw;sql.syntax_ora=true

the statement

该声明

SELECT CURRENT_DATE FROM dual

results in

结果是

2014-01-31 10:35:54

This is in opposite to connections without Oracle syntax mode, where CURRENT_DATE doesn't contain time. As described in the HSQLDB documentation, DATE is interpreted as TIMESTAMP(0) in Oracle syntax mode. But in Oracle 10g itself, CURRENT_DATE behaves as expected (without time).

这与没有Oracle语法模式的连接相反,其中CURRENT_DATE不包含时间。如HSQLDB文档中所述,在Oracle语法模式下,DATE被解释为TIMESTAMP(0)。但在Oracle 10g本身中,CURRENT_DATE的行为与预期一致(没有时间)。

This difference seems to include DATE fields in general.

这种差异似乎通常包括DATE字段。

Why does HSQLDB behave this way?
Is there a way to disable the automatic conversion?

为什么HSQLDB会以这种方式运行?有没有办法禁用自动转换?

1 个解决方案

#1


3  

From the same HSQLDB documentation you linked to:

从您链接到的相同HSQLDB文档:

Datetime types

日期时间类型

HSQLDB fully supports datetime and interval types and operations, including all relevant optional features, as specified by the SQL Standard since SQL-92. The two groups of types are complementary.

HSQLDB完全支持日期时间和间隔类型和操作,包括自SQL-92以来SQL标准指定的所有相关可选功能。这两类类型是互补的。

The DATE type represents a calendar date with YEAR, MONTH and DAY fields.

DATE类型表示具有YEAR,MONTH和DAY字段的日历日期。

The TIME type represents time of day with HOUR, MINUTE and SECOND fields, plus an optional SECOND FRACTION field.

TIME类型表示具有HOUR,MINUTE和SECOND字段的时间,以及可选的SECOND FRACTION字段。

The TIMESTAMP type represents the combination of DATE and TIME types.

TIMESTAMP类型表示DATE和TIME类型的组合。

The Oracle compatibility section says:

Oracle兼容性部分说:

  • The DATE type is interpreted as TIMESTAMP(0) in ORA syntax mode.
  • 在ORA语法模式下,DATE类型被解释为TIMESTAMP(0)。

Oracle's DATE data type "contains the datetime fields YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND". So it's equivalent to an HSQLDB TIMESTAMP(0) data type, and in Oracle mode it is treated as such.

Oracle的DATE数据类型“包含日期时间字段YEAR,MONTH,DAY,HOUR,MINUTE和SECOND”。所以它等同于HSQLDB TIMESTAMP(0)数据类型,并且在Oracle模式下它被视为这样。

Oracle dates always have a time component, even if it is all zeros for midnight. If your SQL client doesn't show it by default you can see that with select to_char(current_date, 'YYYY-MM-DD HH24:MI:SS'), as others have already pointed out.

Oracle日期总是有一个时间组件,即使它在午夜全部为零。如果你的SQL客户端默认没有显示它,你可以看到select to_char(current_date,'YYYY-MM-DD HH24:MI:SS'),正如其他人已经指出的那样。

In normal non-Oracle mode HSQLDB is just treating the value as an SQL-standard DATE and dropping the time portion; in Oracle mode it preserves the time. There doesn't seem to be any way to selectively enable some aspects of the Oracle mode, so you're stuck with the time - really not sure why that is an issue though since it's just reflecting the data you have in your database. If you want to ignore the time you could always select trunc(current_date), which will take the time back to midnight; but it will still show as 2014-01-31 00:00:00 because it's still going to be treated as TIMESTAMP(0).

在正常的非Oracle模式下,HSQLDB只是将值视为SQL标准DATE并删除时间部分;在Oracle模式下,它保留了时间。似乎没有任何方法可以选择性地启用Oracle模式的某些方面,因此您会遇到时间 - 实际上不确定为什么这是一个问题,因为它只是反映了您在数据库中的数据。如果你想忽略时间,你总是可以选择截断(current_date),这将花费时间回到午夜;但它仍将显示为2014-01-31 00:00:00,因为它仍将被视为TIMESTAMP(0)。

#1


3  

From the same HSQLDB documentation you linked to:

从您链接到的相同HSQLDB文档:

Datetime types

日期时间类型

HSQLDB fully supports datetime and interval types and operations, including all relevant optional features, as specified by the SQL Standard since SQL-92. The two groups of types are complementary.

HSQLDB完全支持日期时间和间隔类型和操作,包括自SQL-92以来SQL标准指定的所有相关可选功能。这两类类型是互补的。

The DATE type represents a calendar date with YEAR, MONTH and DAY fields.

DATE类型表示具有YEAR,MONTH和DAY字段的日历日期。

The TIME type represents time of day with HOUR, MINUTE and SECOND fields, plus an optional SECOND FRACTION field.

TIME类型表示具有HOUR,MINUTE和SECOND字段的时间,以及可选的SECOND FRACTION字段。

The TIMESTAMP type represents the combination of DATE and TIME types.

TIMESTAMP类型表示DATE和TIME类型的组合。

The Oracle compatibility section says:

Oracle兼容性部分说:

  • The DATE type is interpreted as TIMESTAMP(0) in ORA syntax mode.
  • 在ORA语法模式下,DATE类型被解释为TIMESTAMP(0)。

Oracle's DATE data type "contains the datetime fields YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND". So it's equivalent to an HSQLDB TIMESTAMP(0) data type, and in Oracle mode it is treated as such.

Oracle的DATE数据类型“包含日期时间字段YEAR,MONTH,DAY,HOUR,MINUTE和SECOND”。所以它等同于HSQLDB TIMESTAMP(0)数据类型,并且在Oracle模式下它被视为这样。

Oracle dates always have a time component, even if it is all zeros for midnight. If your SQL client doesn't show it by default you can see that with select to_char(current_date, 'YYYY-MM-DD HH24:MI:SS'), as others have already pointed out.

Oracle日期总是有一个时间组件,即使它在午夜全部为零。如果你的SQL客户端默认没有显示它,你可以看到select to_char(current_date,'YYYY-MM-DD HH24:MI:SS'),正如其他人已经指出的那样。

In normal non-Oracle mode HSQLDB is just treating the value as an SQL-standard DATE and dropping the time portion; in Oracle mode it preserves the time. There doesn't seem to be any way to selectively enable some aspects of the Oracle mode, so you're stuck with the time - really not sure why that is an issue though since it's just reflecting the data you have in your database. If you want to ignore the time you could always select trunc(current_date), which will take the time back to midnight; but it will still show as 2014-01-31 00:00:00 because it's still going to be treated as TIMESTAMP(0).

在正常的非Oracle模式下,HSQLDB只是将值视为SQL标准DATE并删除时间部分;在Oracle模式下,它保留了时间。似乎没有任何方法可以选择性地启用Oracle模式的某些方面,因此您会遇到时间 - 实际上不确定为什么这是一个问题,因为它只是反映了您在数据库中的数据。如果你想忽略时间,你总是可以选择截断(current_date),这将花费时间回到午夜;但它仍将显示为2014-01-31 00:00:00,因为它仍将被视为TIMESTAMP(0)。