sql >> データベース >  >> RDS >> Oracle

listunagg関数?

    @be hereがコメントですでに述べているように、Oracleはそのような関数を提供していません。したがって、簡単な回避策として、同様のクエリを作成できます。

    with t1(user_id, degree_fi, degree_en, degree_sv) as
    (
      select 3601464, '3700', '1600', '2200' from dual union all
      select 1020   , '100' , '0'   , '0'    from dual union all
      select 3600520, '100,3200,400', '1300, 800, 3000', '1400, 600, 1500'  from dual union all
      select 3600882, '0',    '100',  '200'  from dual
    ),
    Occurence(ocr) as(
      select Level as ocr
        from (select max(greatest(regexp_count(degree_fi, '[^,]+')
                                 , regexp_count(degree_en, '[^,]+')
                                 , regexp_count(degree_sv, '[^,]+')
                                 )
                        ) mx
                from t1    
              ) 
        connect by level <= mx
    )
    select *
      from (
    select User_id
         , regexp_substr(degree_fi, '[^,]+', 1, o.ocr) as degree_fi
         , regexp_substr(degree_en, '[^,]+', 1, o.ocr) as degree_en
         , regexp_substr(degree_sv, '[^,]+', 1, o.ocr) as degree_sv
       from t1 t
      cross join Occurence o
    )
    where degree_fi is not null
      or degree_en is not null 
      or degree_sv is not null
    

    結果:

    User_Id   Degree_Fi  Degree_En  Degree_Sv
    ------------------------------------------------------------ 
    3601464   3700       1600       2200 
    1020      100        0          0 
    3600520   100        1300       1400 
    3600882   0          100        200 
    3600520   3200       800        600 
    3600520   400        3000       1500 
    


    1. Oracleの数値を含む行を返す

    2. MariaDBの日時値からマイクロ秒を減算します

    3. PostgreSQLの日付と時刻の関数

    4. CHAR(10)でクラウドに向かう