简体   繁体   English

DB2 SQL列到行

[英]DB2 SQL columns to rows

I am trying to convert columns into rows like the example below. 我正在尝试将列转换为以下示例中的行。

 _________________________________     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

For solving this i used following Statement 为了解决这个问题,我使用了以下语句

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; 

but I got the following Error 但我收到以下错误

THE STATEMENT CANNOT BE EXECUTED BY DB2 OR IN THE ACCELERATOR (REASON 7). 该语句不能由DB2或在加速器中执行(原因7)。 SQLCODE=-4742, SQLSTATE=560D5, DRIVER=4.19.56 SQLCODE = -4742,SQLSTATE = 560D5,DRIVER = 4.19.56

Has someone any hints to solve this? 有任何提示解决这个问题吗? thanks 谢谢

SQLcode 4772 reason 7 from the accelerator means " The query uses multiple encoding schemes ." 加速器中的SQLcode 4772原因7表示“ 查询使用多种编码方案 。”

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

"If you need more information about why the statement cannot be executed in the accelerator, issue the EXPLAIN statement and examine the output of the table DSN_QUERYINFO_TABLE." “如果需要有关为何无法在加速器中执行该语句的更多信息,请发出EXPLAIN语句并检查表DSN_QUERYINFO_TABLE的输出。”

Additional information is on this page which advises 页面上的其他信息可为您提供建议

Ensure that all objects to which the query refers have the same encoding scheme. 确保查询引用的所有对象都具有相同的编码方案。

Talk with your DBA, discover the CCSID of the objects involved in your query, and rework the query accordingly, for example with temporary tables using the same encoding. 与您的DBA交谈,发现查询中涉及的对象的CCSID,然后相应地对查询进行重新处理,例如使用相同编码的临时表。

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

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