如何使用TABLE表达式“展平”结构

时间:2021-07-09 15:22:29

I have a VARRAYS TYPE wanted to "flatten" the structure with the TABLE expression.

我有一个VARRAYS TYPE希望用TABLE表达式“展平”结构。

The example data

示例数据

CREATE OR REPLACE TYPE ARIS.NUMBER_VARRAY_5 AS VARRAY (5) OF NUMBER NOT NULL;  


CREATE TABLE ARIS.TEST_2  
(  
  DATE_START  DATE,  
  DATE_END    DATE,  
  O3          ARIS.NUMBER_VARRAY_5,  
  CATEGORY    NUMBER  
)  


SET DEFINE OFF;  
Insert into TEST_2  
   (DATE_START, DATE_END, O3, CATEGORY)  
 Values  
   (TO_DATE('01/01/2005 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('01/05/2005 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), NUMBER_VARRAY_5(281.25,-9999,291.5,310.5,298.75), NULL);  
Insert into TEST_2  
   (DATE_START, DATE_END, O3, CATEGORY)  
 Values  
   (TO_DATE('01/02/2005 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('01/06/2005 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), NUMBER_VARRAY_5(-9999,291.5,310.5,298.75,300.75), NULL);  
COMMIT;  

using the SQL statement

使用SQL语句

select O3.* from test_2 t, table(t.o3) O3  

I can get the result

我可以得到结果

COLUMN_VALUE
281.25
-9999
291.5
310.5
298.75
-9999
291.5
310.5
298.75
300.75

The question is how I get the results like

问题是我如何得到结果

DATE_START  DATE_END    03.VALUE1 03.VALUE2 03.VALUE3 03.VALUE4 03.VALUE5
01/01/2005  01/05/2005             281.25    -9999     291.5   310.5     298.75
01/02/2005  01/06/2005             -9999     291.5     310.5   298.75    300.75

1 个解决方案

#1


3  

Try This,

尝试这个,

SELECT
   * 
FROM
   (
      select
         t.Date_start,
         t.Date_end,
         row_number() OVER ( PARTITION BY DATE_START, DATE_END 
      ORDER BY
         ROWNUM) rn,
         O3.* 
      from
         test_2 t,
         table(t.o3) O3 
   )
   PIVOT ( MAX(column_value) FOR rn in 
   (
      1 as "03.VALUE1",
      2 as "03.VALUE2",
      3 as "03.VALUE3",
      4 as "03.VALUE4",
      5 as "03.VALUE5"
   )
) ;

#1


3  

Try This,

尝试这个,

SELECT
   * 
FROM
   (
      select
         t.Date_start,
         t.Date_end,
         row_number() OVER ( PARTITION BY DATE_START, DATE_END 
      ORDER BY
         ROWNUM) rn,
         O3.* 
      from
         test_2 t,
         table(t.o3) O3 
   )
   PIVOT ( MAX(column_value) FOR rn in 
   (
      1 as "03.VALUE1",
      2 as "03.VALUE2",
      3 as "03.VALUE3",
      4 as "03.VALUE4",
      5 as "03.VALUE5"
   )
) ;