Du kan bruge regexp_substr
at opdele dine inputdata i linjer og derefter se efter de relevante strenge, for eksempel:
SQL> SELECT regexp_substr(line, 'aXYZApple[^,]*') subtxt
2 FROM (SELECT regexp_substr(:x, '[^|]*\|', 1, rownum + 1) line
3 FROM dual
4 CONNECT BY LEVEL <= length(:x) - length(REPLACE(:x, '|', '')))
5 WHERE regexp_substr(line || ',', '[^,]*,', 1, 2) = 'OU=Managed,'
6 AND line LIKE '%aXYZApple%';
SUBTXT
--------------------------------------------------------------------------------
aXYZApple-Au
aXYZApple-Readonly
aXYZApple-Write
Her er en lille forklaring. Du skal gennemgå forespørgslen trin for trin.
Den indre del af forespørgslen vil gennemgå dine data (for hver |
). ):
SQL> SELECT regexp_substr(:x, '[^|]*\|', 1, rownum + 1) line
2 FROM dual
3 CONNECT BY LEVEL <= length(:x) - length(REPLACE(:x, '|', ''));
LINE
--------------------------------------------------------------------------------
CN=aXYZApple-Au,OU=Managed,OU=Groups,DC=core,DC=dir,DC=abc,DC=com |
CN=31107427,OU=Distribution Lists,OU=Shared Mailboxes,DC=core,DC=dir,DC=abc,DC=
CN=ea90045052,OU=Groups,OU=eProfile,DC=core,DC=dir,DC=abc,DC=com |
CN=S0901448,OU=Distribution Lists,OU=Shared Mailboxes,DC=core,DC=dir,DC=abc,DC=
CN=00900887,OU=Distribution Lists,OU=Shared Mailboxes,DC=core,DC=dir,DC=abc,DC=
CN=NSMMMM,OU=LRP,OU=Groups,DC=core,DC=dir,DC=abc,DC=com |
CN=aXYZApple-Readonly,OU=Managed,OU=Groups,DC=core,DC=dir,DC=abc,DC=com |
CN=WWSWW-Au,OU=LRP,OU=Groups,DC=core,DC=dir,DC=abc,DC=com |
CN=aLogical_RW,OU=Managed,OU=Groups,DC=core,DC=dir,DC=abc,DC=com |
CN=aXYZApple-Write,OU=Managed,OU=Groups,DC=core,DC=dir,DC=abc,DC=com |
Du ville derefter loope for OU=Managed
streng i anden position:
SQL> SELECT regexp_substr(line || ',', '[^,]*,', 1, 2) second_part
2 FROM (SELECT regexp_substr(:x, '[^|]*\|', 1, rownum + 1) line
3 FROM dual
4 CONNECT BY LEVEL <= length(:x) - length(REPLACE(:x, '|', '')));
SECOND_PART
--------------------------------------------------------------------------------
OU=Managed,
OU=Distribution Lists,
OU=Groups,
OU=Distribution Lists,
OU=Distribution Lists,
OU=LRP,
OU=Managed,
OU=LRP,
OU=Managed,
OU=Managed,
Til sidst skal du vælge den relevante del med en sidste regexp_substr
.