MySQL 是否有相当于 Oracle 的 TIMESTAMP WITH TIME ZONE 的功能?
MySQL 是否有相当于 Oracle 的 TIMESTAMP WITH TIME ZONE 的功能?
我需要将一个 Oracle 表(其中包含一些具有该数据类型的列)映射到 MySQL 表中,但我似乎无法找到一种简单的方法来完成此操作,而不需要借助某些 MySQL 函数。
谢谢并致以诚挚的问候。
Is there MySQL equivalent to Oracle's TIMESTAMP WITH TIME ZONE?
I need to map a Oracle table, which has some columns with that datatype, into a MySQL table but I can't seem to find an easy way to do this without resorting to some MySQL functions.
Thanks and best regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,您需要将数据分成两列,一列是日期时间,另一列保存时区信息。但是您在后一个字段中输入的内容取决于您在 Oracle 中存储的内容 - 带时区的 TIMESTAMP 数据类型可以包含 TZ 偏移量和(可选)时区区域。显然,后者是日期时间在语义上正确的要求,但 IIRC Oracle 并不强制填充此数据。
由于 MySQL 没有数据类型,因此编写 MySQL 函数来处理它会非常困难 - 在支持该数据类型的 Oracle 中创建 MySQL 兼容表示要简单得多。您只需要计算出您实际获得的数据并决定如何在 MySQL 中表示它。按照惯例,这意味着将其与 TZ 一起存储在 UTC 中的单独列中,然后在选择时使用 Convert_tz 函数进行转换(始终来自 UTC)
No, you'll need to split the data into 2 columns, one a datetime, and the other holding the timezone information. But what you put in the latter field is dependant on what you've got stored in Oracle - the TIMESTAMP WITH TIME ZONE Datatype can contain the TZ offset and (optionally) the time zone region. Obviously the latter is a requirement for the date time to be semantically correct, but IIRC Oracle does not enforce this data being populated.
Since MySQL doesn't have the datatype, it'll be very difficult to write MySQL function to process it - it's a lot simpler to create a MySQL compatible representation in Oracle where the datatype is supported. You just need to work out what data you've actually got and decide how you want to represent it in MySQL. By convention that means storing it in UTC along with the TZ in a seperate column, then convert it on selection with the convert_tz function (always from UTC)
MySQL 始终将时间戳存储为 utc。存储的日期始终不包含时区信息。
您可以将 mysql 配置为从 now() 返回不同 的值时区。
要存储当前偏移量,您需要自行将其添加到某个列中。
MySQL always store timestamps as utc. Dates are always stored without timezone information.
You can configure mysql to return values from now() in different timezones.
To store the current offset you need to add this to some column on your own.