以下のクエリが機能します。これは、where 句で指定したキーに対応する n 番目の文字列を名前として提供します (セパレータは ## です)。
select names from (
select
regexp_substr('a##b##c##d##e##f','[^##]+', 1, level) as names,
rownum as nth
from dual
connect by regexp_substr('a##b##c##d##e##f', '[^##]+', 1, level) is not null
)
where nth in (
select nth from (
select
regexp_substr('150##200##13##8##51##61','[^##]+', 1, level) as names,
rownum as nth
from dual
connect by regexp_substr('150##200##13##8##51##61', '[^##]+', 1, level) is not null
)
where names = '200'
)
ここで、x、y、z の 3 つの列を持つテーブル temp があります。ここで、x には a##b##c##d##e##f のような文字列があり、y には 1##2##3##4##5## があります。 6 と z は 1 のような数字になります。
次のような行がある場合
- a##b##c##d##e##f 150##200##13##8##51##61 200
- a##b##c##d##e##f 1##2##3##4##5##6 2
- g##h##i##j##k##l 1##2##3##4##5##99 99
次のような出力が必要です
- a##b##c##d##e##f 150##200##13##8##51##61 200 b
- a##b##c##d##e##f 1##2##3##4##5##6 2 b
- g##h##i##j##k##l 1##2##3##4##5##99 99 l
上記のクエリでデュアルの代わりに「temp」を単に差し込むだけでは、db に 50k 行を超える行があるため、時間がかかります。より良い解決策、またはこれを修正するにはどうすればよいですか?