繁体   English   中英

DB2 SQL列到行

[英]DB2 SQL columns to rows

我正在尝试将列转换为以下示例中的行。

 _________________________________     ROW       | Columns  | values_
      |Column1 | Column2  | Column3   _____________________________
 _________________________________     1         | 1        | 12 
 Row 1|     12  |     25  |     11     1         | 2        | 25
 Row 2|     30  |      5  |     15 --> 1         | 3        | 11
                                       2         | 1        | 30
                                       2         | 2        | 5
                                       2         | 3        | 15

为了解决这个问题,我使用了以下语句

with t as (
      <my query which builds the cross tab>
     )
select t.Row,
       (case when n.n = 1 then Column1
             when n.n = 2 then Column2
             when n.n = 3 then Column3
        end) as values_
from t cross join
     (select 1 as n from sysibm.sysdummy1 union all
      select 2 from sysibm.sysdummy1 union all
      select 3 from sysibm.sysdummy1
     ) n; 

但我收到以下错误

该语句不能由DB2或在加速器中执行(原因7)。 SQLCODE = -4742,SQLSTATE = 560D5,DRIVER = 4.19.56

有任何提示解决这个问题吗? 谢谢

加速器中的SQLcode 4772原因7表示“ 查询使用多种编码方案 。”

检查此页面https://www.ibm.com/support/knowledgecenter/zh-CN/SSEPEK_10.0.0/codes/src/tpc/n4742.html 它建议:

“如果需要有关为何无法在加速器中执行该语句的更多信息,请发出EXPLAIN语句并检查表DSN_QUERYINFO_TABLE的输出。”

页面上的其他信息可为您提供建议

确保查询引用的所有对象都具有相同的编码方案。

与您的DBA交谈,发现查询中涉及的对象的CCSID,然后相应地对查询进行重新处理,例如使用相同编码的临时表。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM