CURRENT_TIMESTAMP的数据库不可知SQL [英] DB agnostic SQL for CURRENT_TIMESTAMP

查看:149
本文介绍了CURRENT_TIMESTAMP的数据库不可知SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用Oracle,但是大多数SQL与数据库无关. CURRENT_TIMESTAMP是一个例外,它在MSSQL中失败.是否有可能为此使用更便携的语法?

I'm currently using Oracle, but most of the SQL is db agnostic. One exception is CURRENT_TIMESTAMP which fails in MSSQL. Is is possible to move to a more portable syntax for this too?

推荐答案

根据其文档,以下供应商支持CURRENT_TIMESTAMP.

According to their documentation the following vendors support CURRENT_TIMESTAMP.

  • Oracle
  • Postgresql
  • MySQL
  • SQL Server
  • Firebird
  • H2
  • HSQLDB
  • DB2
  • Vertica
  • InterSystems Caché
  • Doctrine
  • Teradata

总而言之,CURRENT_TIMESTAMP是SQL标准中规定的方法,其摘要如下所示,如果您正在寻找与数据库无关的SQL,则您可以做的最好的事情就是坚持该标准,尽管这样做不是确保所有内容都完全与数据库无关:

In summary, CURRENT_TIMESTAMP is the method stated in the SQL Standard, a summary of which is below, and if you are looking for DB agnostic SQL the best you can really do is stick to the standard, although this does not guarantee that anything will be fully DB agnostic:

功能

指定产生日期时间类型值的函数.

Specify a function yielding a value of type datetime.

格式

<current date value function> ::= CURRENT_DATE`
<current time value function> ::= CURRENT_TIME [ <left paren> <time precision> <right paren> ]
<current local time value function> ::= LOCALTIME [ <left paren> <time precision> <right paren> ]
<current timestamp value function> ::= CURRENT_TIMESTAMP [ <left paren> <timestamp precision> <right paren> ]
<current local timestamp value function> ::= LOCALTIMESTAMP [ <left paren> <timestamp precision> <right paren> ]

一般规则

1)s的CURRENT_DATE,CURRENT_TIME和CURRENT_TIMESTAMP分别返回当前日期,当前时间和当前时间戳;返回的时间和时间戳记值的时区位移等于SQLsession的当前默认时区位移.

1) The s CURRENT_DATE, CURRENT_TIME, and CURRENT_TIMESTAMP respectively return the current date, current time, and current timestamp; the time and timestamp values are returned with time zone displacement equal to the current default time zone displacement of the SQLsession.

这篇关于CURRENT_TIMESTAMP的数据库不可知SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆