oracle AS400 DB2 SQL 语法中Oracle 的to_char 的等价物是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1125421/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the equivalent of Oracle's to_char in AS400 DB2 SQL syntax?
提问by Nick Pierpoint
I'm trying to display a DATE field fetched from a DB2 instance.
我正在尝试显示从 DB2 实例中提取的 DATE 字段。
In Oracle I'd use something like:
在 Oracle 中,我会使用类似的东西:
to_char(v_date, 'YYYY-MM-DD')
What's the equivalent in AS400 DB2?
AS400 DB2 中的等价物是什么?
回答by Tracy Probst
In V5R3 or later, use the CHAR() function. To get the same results as your Oracle example, use this:
在 V5R3 或更高版本中,使用 CHAR() 函数。要获得与 Oracle 示例相同的结果,请使用以下命令:
char(v_date, ISO)
When using the CHAR() function with date fields, you can choose from the following formats: ISO, USA, EUR, JIS, and local. When using "local" as the format, it will use the attributes of the ODBC connection job, which will probably be the system-level values of date format and date separator. The other date formats are as such:
将 CHAR() 函数与日期字段一起使用时,您可以从以下格式中进行选择:ISO、USA、EUR、JIS 和本地。当使用“local”作为格式时,它将使用 ODBC 连接作业的属性,这些属性可能是日期格式和日期分隔符的系统级值。其他日期格式如下:
ISO = 'yyyy-mm-dd' USA = 'mm/dd/yyyy' EUR = 'dd.mm.yyyy' JIS = 'yyyy-mm-dd'
In V5R4, you can use the varchar_format function. The only valid formats for this function are 'YYYY-MM-DD HH24:MI:SS' and 'YYYY-MM-DD'.
在 V5R4 中,您可以使用 varchar_format 函数。此函数的唯一有效格式是“YYYY-MM-DD HH24:MI:SS”和“YYYY-MM-DD”。
In V6R1 you have better formatting options for the varchar_format function. As mentioned in another answer, to_char is an alternative to varchar_format.
在 V6R1 中,您为 varchar_format 函数提供了更好的格式化选项。正如另一个答案中提到的,to_char 是 varchar_format 的替代方案。
回答by Nick Pierpoint
It turns out that the DB2 equivalent to "to_char
" is... "to_char
".
事实证明,等效于“ to_char
”的 DB2是...“ to_char
”。
:)
http://publib.boulder.ibm.com/infocenter/db2luw/v9/topic/com.ibm.db2.udb.admin.doc/doc/r0007108.htm
http://publib.boulder.ibm.com/infocenter/db2luw/v9/topic/com.ibm.db2.udb.admin.doc/doc/r0007108.htm
The underlying function is varchar_format
, for which to_char
is a synonym.
底层函数是varchar_format
, for whichto_char
是同义词。