以下代码给出了	 9804响应行大小或常量行大小溢出错误'添加LPAD功能后出错。如果我删除LPAD功能它运行正常。
使用ODBC ASCII连接查询与2 LPAD函数一起正常工作。具有3个LPAD功能,其投掷错误。
任何人都可以建议如何解决它。
SELECT
CAST(TableA.A AS VARCHAR(50)) AS A
,LPAD(CAST(CAST(TableA.B AS DECIMAL(18,2) FORMAT '-9999999999999999.9(2)' ) AS VARCHAR(20)),20,' ') AS B
,LPAD(CAST(CAST(TableA.C AS DECIMAL(18,2) FORMAT '-9999999999999999.9(2)' ) AS VARCHAR(20)),20,' ') AS C
,CAST(CAST(TableA.D AS INTEGER FORMAT '9999999999') AS VARCHAR(10)) AS D
,CAST(CAST(TableA.E AS INTEGER FORMAT '9999999999') AS VARCHAR(10)) AS E
,CAST(CAST(TableA.F AS INTEGER FORMAT '9999999999') AS VARCHAR(10)) AS F
,CAST(CAST(TableA.G AS INTEGER FORMAT '9999999999') AS VARCHAR(10)) AS G
,CAST(CAST(TableA.H AS INTEGER FORMAT '9999999999') AS VARCHAR(10)) AS H
,LPAD(CAST(CAST(TableA.I AS DECIMAL(18,2) FORMAT '-9999999999999999.9(2)' ) AS VARCHAR(20)),20,' ') AS I
,CAST(CAST(TableA.J AS SMALLINT FORMAT '99999') AS VARCHAR(10)) AS J
,CAST(CAST(TableA.K AS SMALLINT FORMAT '99999') AS VARCHAR(10)) AS K
FROM TableA AS TableA
答案 0 :(得分:1)
检查LPAD的结果数据类型时,它类似于VarChar(32000)。当你得到多个LPAD时,这超过了最大行长度64k。
您可以添加另一个类型转换以减少计算的大小:
,CAST(LPAD(CAST(CAST(TableA.B AS DECIMAL(18,2) FORMAT '-9999999999999999.9(2)' ) AS VARCHAR(20)),20,' ') AS VARCHAR(20)) AS B
FORMAT指定一个前导空格,但是CAST到VarChar会删除它。 您可以切换到Teradata样式转换,格式为右对齐而左对齐ANSI转换。
Cast(B AS DECIMAL(18,2) Format '-9999999999999999.9(2)' ) ( VARCHAR(20)) -- or better (CHAR(20))
或者您只需切换到TO_CHAR:
To_Char(b, '09999999999999999.99')