在AS400 DB2 SQL语法中,Oracle的to_char相当于什么?

时间:2023-02-04 15:48:02

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中的等价物是什么?

3 个解决方案

#1


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。使用“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的替代品。

#3


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

The underlying function is varchar_format, for which to_char is a synonym.

底层函数是varchar_format,其中to_char是同义词。

#1


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。使用“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的替代品。

#2


#3


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

The underlying function is varchar_format, for which to_char is a synonym.

底层函数是varchar_format,其中to_char是同义词。