DB2 - TRANSLATE功能的参数02无效 [英] DB2 - Argument 02 of function TRANSLATE not valid
问题描述
我使用TRANSLATE将一个字符串(yyyymmddhhiiss)转换为日期有一些问题。
I am having some issues converting a string (yyyymmddhhiiss) to a date using TRANSLATE.
如果我直接使用字符串,那么它工作得很好,但是当我使用完全相同数据类型的字段varchar(14),然后它会从标题中抛出错误。
If I use a string directly then it works perfectly fine, but when i use a field of exactly same datatype, varchar(14), then it throws the error from the title.
这是我正在尝试做的一个基本示例:
Here is a basic example of what i am trying to do:
WITH test_table AS (
SELECT '20160101123059' AS d FROM SYSIBM.SYSDUMMY1
)
SELECT d
, translate('ABCD-EF-GH IJ:KL:MN', d, 'ABCDEFGHIJKLMN')
, translate('ABCD-EF-GH IJ:KL:MN', '20160101123059','ABCDEFGHIJKLMN')
FROM test_table
不工作谢谢。
推荐答案
从DB2 for i手册...
From the DB2 for i manual...
to-string
一个字符串,用于指定要转换表达式中某些
字符的字符。这个字符串有时是
,称为输出转换表。字符串必须是任何内置的
数字或字符串常量。
所以它赢了
参数2必须是一个常量值。
Argument 2 must be a constant value.
假设IBM i的受支持版本,您应该可以使用 timestamp()
函数将14个字符的字符串直接转换为时间戳。
Assuming a supported release of the IBM i, you should be able to use the timestamp()
function to convert the 14-character string directly to timestamp.
select timestamp('20160101123059')
from sysibm.sysdummy1
这篇关于DB2 - TRANSLATE功能的参数02无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!