
比如表中這一個date對應四條記錄,按位或,組成表二中的一條記錄,最終也可根據新組成的type欄位,翻譯出來原來對應的type的值

簡單的說就是多條記錄變一條,原來的資訊還要保留,要如何實作的?或者有沒有更好的辦法?交流下
uj5u.com熱心網友回復:
直接逗號拼接 type欄位不行嗎? 可行就是 listagg(type,',') within group(order by 1) from tt group by dateuj5u.com熱心網友回復:
忽略一樓 寫錯了。。uj5u.com熱心網友回復:
SQL>
SQL> create table test(id, type)
2 as
3 select 1, 2 from dual union all
4 select 2, 8 from dual union all
5 select 3, 16 from dual union all
6 select 4, 32 from dual;
Table created
SQL> create or replace function bitor(p varchar2)
2 return number is
3 prev number := 0 ;
4 result number;
5 begin
6 for x in (select regexp_substr(p, '[^,]+', 1,level) + 0 value
7 from dual
8 connect by rownum <= regexp_count(p,',') + 1
9 )
10 loop
11 result := (prev + x.value) - bitand(prev, x.value);
12 prev := result;
13 end loop;
14 return result;
15 end;
16 /
Function created
SQL> select bitor(listagg(type,',') within group (order by id)) from test;
BITOR(LISTAGG(TYPE,',')WITHING
------------------------------
58
SQL> drop function bitor;
Function dropped
SQL> drop table test purge;
Table dropped
SQL>
uj5u.com熱心網友回復:
如果這個date的某一個type失效了,還需要bitand掉uj5u.com熱心網友回復:
這個邏輯,你自己加一下吧。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/69681.html
標籤:開發
上一篇:oracle用sys或者sysdba登錄的時候顯示權限不足
下一篇:指定列欄位去重,其它列都要顯示
