- SQL 教程
- SQL - 首页
- SQL - 概述
- SQL - RDBMS 概念
- SQL - 数据库
- SQL - 语法
- SQL - 数据类型
- SQL - 运算符
- SQL - 表达式
- SQL 数据库
- SQL - 创建数据库
- SQL - 删除数据库
- SQL - 选择数据库
- SQL - 重命名数据库
- SQL - 显示数据库
- SQL - 备份数据库
- SQL 表
- SQL - 创建表
- SQL - 显示表
- SQL - 重命名表
- SQL - 截断表
- SQL - 克隆表
- SQL - 临时表
- SQL - 修改表
- SQL - 删除表
- SQL - 删除表
- SQL - 约束
- SQL 查询
- SQL - 插入查询
- SQL - 选择查询
- SQL - Select Into
- SQL - Insert Into Select
- SQL - 更新查询
- SQL - 删除查询
- SQL - 排序结果
- SQL 视图
- SQL - 创建视图
- SQL - 更新视图
- SQL - 删除视图
- SQL - 重命名视图
- SQL 运算符和子句
- SQL - Where 子句
- SQL - Top 子句
- SQL - Distinct 子句
- SQL - Order By 子句
- SQL - Group By 子句
- SQL - Having 子句
- SQL - AND & OR
- SQL - BOOLEAN (BIT) 运算符
- SQL - LIKE 运算符
- SQL - IN 运算符
- SQL - ANY, ALL 运算符
- SQL - EXISTS 运算符
- SQL - CASE
- SQL - NOT 运算符
- SQL - 不等于
- SQL - IS NULL
- SQL - IS NOT NULL
- SQL - NOT NULL
- SQL - BETWEEN 运算符
- SQL - UNION 运算符
- SQL - UNION vs UNION ALL
- SQL - INTERSECT 运算符
- SQL - EXCEPT 运算符
- SQL - 别名
- SQL 连接
- SQL - 使用连接
- SQL - 内连接
- SQL - 左连接
- SQL - 右连接
- SQL - 交叉连接
- SQL - 全连接
- SQL - 自连接
- SQL - 删除连接
- SQL - 更新连接
- SQL - 左连接 vs 右连接
- SQL - Union vs Join
- SQL 密钥
- SQL - 唯一键
- SQL - 主键
- SQL - 外键
- SQL - 组合键
- SQL - 备用键
- SQL 索引
- SQL - 索引
- SQL - 创建索引
- SQL - 删除索引
- SQL - 显示索引
- SQL - 唯一索引
- SQL - 集群索引
- SQL - 非集群索引
- 高级 SQL
- SQL - 通配符
- SQL - 注释
- SQL - 注入
- SQL - 托管
- SQL - Min & Max
- SQL - Null 函数
- SQL - 检查约束
- SQL - 默认约束
- SQL - 存储过程
- SQL - NULL 值
- SQL - 事务
- SQL - 子查询
- SQL - 处理重复项
- SQL - 使用序列
- SQL - 自动递增
- SQL - 日期和时间
- SQL - 游标
- SQL - 公共表表达式
- SQL - Group By vs Order By
- SQL - IN vs EXISTS
- SQL - 数据库调优
- SQL 函数参考
- SQL - 日期函数
- SQL - 字符串函数
- SQL - 聚合函数
- SQL - 数值函数
- SQL - 文本和图像函数
- SQL - 统计函数
- SQL - 逻辑函数
- SQL - 游标函数
- SQL - JSON 函数
- SQL - 转换函数
- SQL - 数据类型函数
- SQL 有用资源
- SQL - 问答
- SQL - 快速指南
- SQL - 有用函数
- SQL - 有用资源
- SQL - 讨论
SQL - CURRENT_TIMEZONE_ID() 函数
SQL 的CURRENT_TIMEZONE_ID()函数是 SQL 中的一个内置函数,用于检索服务器或实例观察到的当前时区的 ID。
CURRENT_TIMEZONE_ID() 函数返回的 ID 在不同的数据库管理系统中可能有所不同。它可能是时区名称或缩写。例如,在Oracle中,此函数可能返回“America/New_York”表示美国东部时间,而在IBM Db2中,它可能返回“EST5EDT”表示相同的时区。
注意 - 在 SQL 中,时区始终设置为 UTC,CURRENT_TIMEZONE_ID 将返回 UTC 时区的 ID。
语法
以下是 SQL CURRENT_TIMEZONE_ID()函数的语法:
CURRENT_TIMEZONE_ID()
参数
此函数不接受任何参数。
示例
以下示例演示了 SQL 中 SQL CURRENT_TIMEZONE_ID() 函数的用法:
SQL> SELECT CURRENT_TIMEZONE_ID() AS CURRENT_TIMEZONE_ID;
输出
当我们执行上述查询时,输出如下所示:
+----------------------+ | CURRENT_TIMEZONE_ID | +----------------------+ | India Standard Time | +----------------------+
示例
我们可以使用以下查询检索数据库服务器上的所有时区 ID:
SQL> SELECT * FROM sys.time_zone_info;
输出
如果我们执行上述查询,则结果如下所示:
+-----------------------------------+--------------------+------------------+ | name | current_utc_offset | is_currently_dst | +-----------------------------------+--------------------+------------------+ | Dateline Standard Time | -12:00 | 0 | | Dateline Standard Time | -11:00 | 0 | | UTC-11 | -10:00 | 0 | | Aleutian Standard Time | -10:00 | 0 | | Hawaiian Standard Time | -09:30 | 0 | | Marquesas Standard Time | -09:00 | 0 | | Alaskan Standard Time | -09:00 | 0 | | UTC-09 | -08:00 | 0 | | Pacific Standard Time (Mexico) | -08:00 | 0 | | UTC-08 | -08:00 | 0 | | Pacific Standard Time | -07:00 | 0 | | US Mountain Standard Time | -07:00 | 0 | | Mountain Standard Time (Mexico) | -07:00 | 0 | | Mountain Standard Time | -07:00 | 0 | | Yukon Standard Time | -06:00 | 0 | | Central America Standard Time | -06:00 | 0 | | Central Standard Time | -05:00 | 0 | | Easter Island Standard Time | -06:00 | 1 | | Central Standard Time (Mexico) | -06:00 | 0 | | Canada Central Standard Time | -05:00 | 0 | | SA Pacific Standard Time | -05:00 | 0 | | Eastern Standard Time (Mexico) | -05:00 | 0 | | Eastern Standard Time | -05:00 | 0 | | Haiti Standard Time | -05:00 | 0 | | Cuba Standard Time | -05:00 | 0 | | US Eastern Standard Time | -05:00 | 0 | | Turks And Caicos Standard Time | -03:00 | 0 | | Paraguay Standard Time | -04:00 | 1 | | Atlantic Standard Time | -04:00 | 0 | | Venezuela Standard Time | -04:00 | 0 | | Central Brazilian Standard Time | -04:00 | 0 | | SA Western Standard Time | -03:00 | 0 | | Pacific SA Standard Time | -03:30 | 1 | | Newfoundland Standard Time | -03:00 | 0 | | Tocantins Standard Time | -03:00 | 0 | | E. South America Standard Time | -03:00 | 0 | | SA Eastern Standard Time | -03:00 | 0 | | Argentina Standard Time | -03:00 | 0 | | Greenland Standard Time | -03:00 | 0 | | Montevideo Standard Time | -03:00 | 0 | | Magallanes Standard Time | -03:00 | 0 | | Saint Pierre Standard Time | -03:00 | 0 | | Bahia Standard Time | -02:00 | 0 | | UTC-02 | -02:00 | 0 | | Mid-Atlantic Standard Time | -01:00 | 0 | | Azores Standard Time | -01:00 | 0 | | Cape Verde Standard Time | +00:00 | 0 | | UTC | +00:00 | 0 | | GMT Standard Time | +00:00 | 0 | | Greenwich Standard Time | +00:00 | 0 | | Sao Tome Standard Time | +01:00 | 0 | | Morocco Standard Time | +01:00 | 1 | | W. Europe Standard Time | +01:00 | 0 | | Central Europe Standard Time | +01:00 | 0 | | Romance Standard Time | +01:00 | 0 | | Central European Standard Time | +01:00 | 0 | | W. Central Africa Standard Time | +02:00 | 0 | | GTB Standard Time | +02:00 | 0 | | Middle East Standard Time | +02:00 | 0 | | Egypt Standard Time | +02:00 | 0 | | E. Europe Standard Time | +02:00 | 0 | | Syria Standard Time | +02:00 | 0 | | West Bank Standard Time | +02:00 | 0 | | South Africa Standard Time | +02:00 | 0 | | FLE Standard Time | +02:00 | 0 | | Israel Standard Time | +02:00 | 0 | | South Sudan Standard Time | +02:00 | 0 | | Kaliningrad Standard Time | +02:00 | 0 | | Sudan Standard Time | +02:00 | 0 | | Libya Standard Time | +02:00 | 0 | | Namibia Standard Time | +03:00 | 0 | | Jordan Standard Time | +03:00 | 0 | | Arabic Standard Time | +03:00 | 0 | | Turkey Standard Time | +03:00 | 0 | | Arab Standard Time | +03:00 | 0 | | Belarus Standard Time | +03:00 | 0 | | Russian Standard Time | +03:00 | 0 | | E. Africa Standard Time | +03:00 | 0 | | Volgograd Standard Time | +03:30 | 0 | | Iran Standard Time | +04:00 | 0 | | Arabian Standard Time | +04:00 | 0 | | Astrakhan Standard Time | +04:00 | 0 | | Azerbaijan Standard Time | +04:00 | 0 | | Russia Time Zone 3 | +04:00 | 0 | | Mauritius Standard Time | +04:00 | 0 | | Saratov Standard Time | +04:00 | 0 | | Georgian Standard Time | +04:00 | 0 | | Caucasus Standard Time | +04:30 | 0 | | Afghanistan Standard Time | +05:00 | 0 | | West Asia Standard Time | +05:00 | 0 | | Ekaterinburg Standard Time | +05:00 | 0 | | Pakistan Standard Time | +05:00 | 0 | | Qyzylorda Standard Time | +05:30 | 0 | | India Standard Time | +05:30 | 0 | | Sri Lanka Standard Time | +05:45 | 0 | | Nepal Standard Time | +06:00 | 0 | | Central Asia Standard Time | +06:00 | 0 | | Bangladesh Standard Time | +06:00 | 0 | | Omsk Standard Time | +06:30 | 0 | | Myanmar Standard Time | +07:00 | 0 | | SE Asia Standard Time | +07:00 | 0 | | Altai Standard Time | +07:00 | 0 | | W. Mongolia Standard Time | +07:00 | 0 | | North Asia Standard Time | +07:00 | 0 | | N. Central Asia Standard Time | +07:00 | 0 | | Tomsk Standard Time | +08:00 | 0 | | China Standard Time | +08:00 | 0 | | North Asia East Standard Time | +08:00 | 0 | | Singapore Standard Time | +08:00 | 0 | | W. Australia Standard Time | +08:00 | 0 | | Taipei Standard Time | +08:00 | 0 | | Ulaanbaatar Standard Time | +08:45 | 0 | | Aus Central W. Standard Time | +09:00 | 0 | | Transbaikal Standard Time | +09:00 | 0 | | Tokyo Standard Time | +09:00 | 0 | | North Korea Standard Time | +09:00 | 0 | | Korea Standard Time | +09:00 | 0 | | Yakutsk Standard Time | +10:30 | 0 | | Cen. Australia Standard Time | +09:30 | 1 | | AUS Central Standard Time | +10:00 | 0 | | E. Australia Standard Time | +11:00 | 0 | | AUS Eastern Standard Time | +10:00 | 1 | | West Pacific Standard Time | +11:00 | 0 | | Tasmania Standard Time | +10:00 | 1 | | Vladivostok Standard Time | +11:00 | 0 | | Lord Howe Standard Time | +11:00 | 1 | | Bougainville Standard Time | +11:00 | 0 | | Russia Time Zone 10 | +11:00 | 0 | | Magadan Standard Time | +12:00 | 0 | | Norfolk Standard Time | +11:00 | 1 | | Sakhalin Standard Time | +11:00 | 0 | | Central Pacific Standard Time | +12:00 | 0 | | Russia Time Zone 11 | +13:00 | 0 | | New Zealand Standard Time | +12:00 | 1 | | UTC+12 | +12:00 | 0 | | Fiji Standard Time | +12:00 | 0 | | Kamchatka Standard Time | +13:45 | 0 | | Chatham Islands Standard Time | +13:00 | 1 | | UTC+13 | +13:00 | 0 | | Tonga Standard Time | +14:00 | 0 | | Samoa Standard Time | +14:00 | 1 | | Line Islands Standard Time | +14:00 | 0 | +-----------------------------------+--------------------+------------------+
示例
假设我们使用 CREATE 语句在 SQL 数据库中创建了一个名为 STUDENTS 的表,如下面的查询所示:
SQL> CREATE TABLE STUDENTS(ID INT NOT NULL, NAME VARCHAR (200) NOT NULL, AGE INT NOT NULL);
现在,让我们使用 INSERT 语句在 STUDENTS 表中插入一些记录,如下面的查询所示:
SQL> INSERT INTO STUDENTS(ID, NAME, AGE) VALUES(1, 'Dhruv', '20'); INSERT INTO STUDENTS(ID, NAME, AGE) VALUES(2, 'Arjun', '23'); INSERT INTO STUDENTS(ID, NAME, AGE) VALUES(3, 'Dev', '25'); INSERT INTO STUDENTS(ID, NAME, AGE) VALUES(4, 'Riya', '19'); INSERT INTO STUDENTS(ID, NAME, AGE) VALUES(5, 'Aarohi','24'); INSERT INTO STUDENTS(ID, NAME, AGE) VALUES(6, 'Lisa', '20'); INSERT INTO STUDENTS(ID, NAME, AGE) VALUES(7, 'Roy', '24');
我们可以使用以下查询验证表是否已创建:
SQL> SELECT * FROM STUDENTS;
STUDENTS 表已成功在 SQL 数据库中创建。
+----+--------+-----+ | ID | NAME | AGE | +----+--------+-----+ | 1 | Dhruv | 20 | | 2 | Arjun | 23 | | 3 | Dev | 25 | | 4 | Riya | 19 | | 5 | Aarohi | 24 | | 6 | Lisa | 20 | | 7 | Roy | 24 | +----+--------+-----+
我们可以使用以下查询检索学生的当前时区 ID:
SQL> SELECT *, CURRENT_TIMEZONE_ID() AS CURRENT_TIMEZONE_IDS FROM STUDENTS;
输出
上述查询的输出如下所示:
+----+--------+-----+----------------------+ | ID | NAME | AGE | CURRENT_TIMEZONE_IDS | -----+--------+-----+----------------------+ | 1 | Dhruv | 20 | India Standard Time | | 2 | Arjun | 23 | India Standard Time | | 3 | Dev | 25 | India Standard Time | | 4 | Riya | 19 | India Standard Time | | 5 | Aarohi | 24 | India Standard Time | | 6 | Lisa | 20 | India Standard Time | | 7 | Roy | 24 | India Standard Time | +----+--------+-----+----------------------+
sql-date-functions.htm
广告