【问题标题】:How can I specify timezone with current_timestamp in Oracle如何在 Oracle 中使用 current_timestamp 指定时区
【发布时间】:2021-11-13 03:35:05
【问题描述】:

在 Oracle 中调用 CURRENT_TIMESTAMP 函数时如何指定时区?请注意,我想以编程方式而不是通过设置一些环境变量来完成。

【问题讨论】:

  • 您可能需要转换为字符串,更改 tz 偏移量,然后转换回带时区的时间戳 - docs.oracle.com/cd/B19306_01/server.102/b14200/functions194.htm
  • 调用current_timestamp 时不能“指定时区” - current_timestamp 已经有自己的、非常明确的指定时区。您的意思是“将时间戳转换为不同的时区”?这就是 MT0 的答案。

标签: sql oracle timestamp


【解决方案1】:

使用AT TIME ZONE:

SELECT CURRENT_TIMESTAMP AT TIME ZONE 'UTC' AS utc_time,
       CURRENT_TIMESTAMP AT TIME ZONE 'PST' AS pst_time
FROM   DUAL;

哪些输出:

UTC_TIME PST_TIME
18-SEP-21 20.02.58.762964 UTC 18-SEP-21 13.02.58.762964 PST

db小提琴here

【讨论】:

    猜你喜欢
    • 2015-03-05
    • 1970-01-01
    • 2019-07-14
    • 1970-01-01
    • 2011-03-24
    • 1970-01-01
    • 2015-11-23
    • 1970-01-01
    相关资源
    最近更新 更多