简体   繁体   中英

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). 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 ."

Check this page https://www.ibm.com/support/knowledgecenter/en/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."

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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