2016-08-05 4 views
0

私は以下のようにテーブルEmployeeを持っています。変更列には、アプリケーションを通じて値が変更された列の名前が含まれます。この列のデータはコンマで区切られています。私は結果が行ごとに1つの変更を持つようにこのテーブルを照会する必要があります。つまり、Changeカラムのデータをコンマで区切り、対応するローをフェッチします。私はどこから始めるべきかわからない!助けてください。 enter image description here列に基づいて行をフェッチするSQLクエリ

答えて

2

あなたは、Oracleのregexp_substr機能を使用することができ、見てみましょう:

select distinct Id, Name, Address, trim(regexp_substr(Change,'[^,]+', 1, level)) 
from Employee 
connect by regexp_substr(Change, '[^,]+', 1, level) is not null; 

これはあなたのChange列にカンマ区切りの任意の数のために働く必要があります。

ここrexexp_substr機能で見るドキュメント:https://docs.oracle.com/cd/B12037_01/server.101/b10759/functions116.htm

+0

完璧@danielのlangemannが含まれています。 –

1

ここで私はREGEXP_SUBSTRを使用して試してみましたがマルチセットレベルに本当に感謝

with temp as 
    (
     select id, name, address, change from testemp 
    ) 
    select id,name,address,trim(regexp_substr(change, '[^,]+', 1, levels.column_value)) change 
    from temp t, 
    table(cast(multiset(select level from dual 
    connect by level <= length (regexp_replace(change, '[^,]+')) + 1) 
    as sys.OdciNumberList)) levels; 
関連する問題