Как получить значение между 2 символами в Oracle SQL - PullRequest
0 голосов
/ 11 марта 2019

Привет всем, у меня есть это значение в моем столбце:

<?xml version="1.0" encoding="UTF-8"?><?dsk-revision 1.0?><Descriptor><pde><a><dov>784512</dov></a></pde></Descriptor>

Я бы получил только:

<dov>784512</dov>

У вас есть идеи?

Спасибо!

Ответы [ 3 ]

0 голосов
/ 11 марта 2019

Вы можете использовать regexp_replace():

select x.*,
       regexp_replace(str, '<pde><a>(.*)</a></pde>', '\1')
from (select '<pde><a><dov>784512</dov></a></pde>' as str from dual) x;

Или regexp_substr():

select x.*,
       regexp_substr(str, '<dov>.*</dov>')
from (select '<pde><a><dov>784512</dov></a></pde>' as str from dual) x;

Мне неясно, хотите ли вы строку, потому что "dov" или между "pde / a".

0 голосов
/ 11 марта 2019

Использовать REGEXP_REPLACE с указанной маской:

select x.*,
       regexp_replace(str, '.*<a>(.*)</a>.*', '\1'), -- anything between <a> </a>
       regexp_replace(str, '.*(<dov>.*</dov>).*', '\1'), -- anything between <dov> </dov> tag (tag included)
       regexp_replace(str, '.*<pde><a>(.*)</a></pde>.*', '\1'), -- anything between <pde><a> </a></pde>
       regexp_replace(str, '.*<pde><a>(<dov>.*</dov>)</a></pde>.*', '\1') -- anything between <pde><a> </a></pde> that is inside <dov> </dov> tag (tag included)
from (select '<pde><a><dov>784512</dov></a></pde>' as str from dual) x;
0 голосов
/ 11 марта 2019

С SUBSTR + INSTR:

SQL> with test (col) as
  2  (select '<pde><a><dov>784512</dov></a></pde>' from dual)
  3  select substr(col, instr(col, '<dov>', 1, 1),
  4                     instr(col, '</dov>', 1, 1) + 6 - instr(col, '<dov>')) result
  5  from test;

RESULT
-----------------
<dov>784512</dov>

SQL>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...