PLSQL如何在

PLSQL如何在,sql,oracle,parsing,plsql,Sql,Oracle,Parsing,Plsql,在DB中,我有如下数据: "text moretext <#include "notification.bar.account.locked.body.ftl" /> sda text moretext moretext <#include "notification.bar.account.unlocked.body.ftl" /> fsd text." 如果可能的话,每一行都有一个 select substr(text,instr(text,chr(34),1,1)

在DB中,我有如下数据:

"text moretext <#include "notification.bar.account.locked.body.ftl" /> sda text
moretext moretext <#include "notification.bar.account.unlocked.body.ftl" /> fsd text."
如果可能的话,每一行都有一个

select substr(text,instr(text,chr(34),1,1)+1, instr(text,chr(34),1,2) - instr(text,chr(34),1,1)-1  ) from temp
编辑:

如果您需要更智能的东西,并且不知道包含块在文本中的位置,那么我们可以首先搜索包含块并从中挑选主要内容

SELECT SUBSTR(SUBSTR(text,instr(text, '<#',1), instr(text, '>',1) ),instr(text,chr(34),1,1)+1, instr(text,chr(34),1,2) - instr(text,chr(34),1,1)-1 )
FROM temp;
如果不是你想要的,请告诉我

再次编辑以返回两个不同的列

SELECT SUBSTR(SUBSTR(text,instr(text, '<#',1,1), instr(text, '/>',1,1) ),instr(text,chr(34),1,1)+1, instr(text,chr(34),1,2) - instr(text,chr(34),1,1)-1 ),
, SUBSTR(SUBSTR(text,instr(text, '<#',1,2), instr(text, '/>',1,2) ),instr(SUBSTR(text,instr(text, '<#',1,2), instr(text, '/>',1,2) ),chr(34),1,1) + 1, instr(SUBSTR(text,instr(text, '<#',1,2), instr(text, '/>',1,2) ),chr(34),1,2) - instr(SUBSTR(text,instr(text, '<#',1,2), instr(text, '/>',1,2) ),chr(34),1,1)-1 )
FROM temp;
现在它将返回两个不同的列 我知道这有点复杂,但如果你使用union,你会在不同的行中得到这些结果,前提是这些文本在一列中

试试这个

select substr(text,instr(text,chr(34),1,1)+1, instr(text,chr(34),1,2) - instr(text,chr(34),1,1)-1  ) from temp
编辑:

如果您需要更智能的东西,并且不知道包含块在文本中的位置,那么我们可以首先搜索包含块并从中挑选主要内容

SELECT SUBSTR(SUBSTR(text,instr(text, '<#',1), instr(text, '>',1) ),instr(text,chr(34),1,1)+1, instr(text,chr(34),1,2) - instr(text,chr(34),1,1)-1 )
FROM temp;
如果不是你想要的,请告诉我

再次编辑以返回两个不同的列

SELECT SUBSTR(SUBSTR(text,instr(text, '<#',1,1), instr(text, '/>',1,1) ),instr(text,chr(34),1,1)+1, instr(text,chr(34),1,2) - instr(text,chr(34),1,1)-1 ),
, SUBSTR(SUBSTR(text,instr(text, '<#',1,2), instr(text, '/>',1,2) ),instr(SUBSTR(text,instr(text, '<#',1,2), instr(text, '/>',1,2) ),chr(34),1,1) + 1, instr(SUBSTR(text,instr(text, '<#',1,2), instr(text, '/>',1,2) ),chr(34),1,2) - instr(SUBSTR(text,instr(text, '<#',1,2), instr(text, '/>',1,2) ),chr(34),1,1)-1 )
FROM temp;
现在它将返回两个不同的列
我知道这有点复杂,但如果你使用union,你会在不同的行中得到这些结果,前提是这些文本在一列中

正则表达式似乎是解决这个特定字符串的显而易见的答案。在本例中,我将使用替换字符串中不符合您要求的所有部分:

SQL> with the_data as (
  2  select '"text moretext <#include "notification.bar.account.locked.body.ftl" /> sda text
  3  moretext moretext <#include "notification.bar.account.unlocked.body.ftl" /> fsd text."' as str
  4    from dual
  5         )
  6  select regexp_replace(str, '(.*<#include\s")(.*)("\s/>.*)', '\2')
  7    from the_data;

REGEXP_REPLACE(STR,'(.*<#INCLUDE\S")(.*)("/>.*)','\2')
--------------------------------------------------------------------------------
notification.bar.account.locked.body.ftl
notification.bar.account.unlocked.body.ftl

唯一真正的区别是,您必须运行两次,以便通过将n替换为字符串中此模式的匹配项来查找这两个匹配项。如果您事先不知道发生的次数,那么这可能会导致一些问题。如果这样做,那么它比使用REGEXP\u REPLACE稍微干净一些。

正则表达式似乎是解决这个特定字符串的明显答案。在本例中,我将使用替换字符串中不符合您要求的所有部分:

SQL> with the_data as (
  2  select '"text moretext <#include "notification.bar.account.locked.body.ftl" /> sda text
  3  moretext moretext <#include "notification.bar.account.unlocked.body.ftl" /> fsd text."' as str
  4    from dual
  5         )
  6  select regexp_replace(str, '(.*<#include\s")(.*)("\s/>.*)', '\2')
  7    from the_data;

REGEXP_REPLACE(STR,'(.*<#INCLUDE\S")(.*)("/>.*)','\2')
--------------------------------------------------------------------------------
notification.bar.account.locked.body.ftl
notification.bar.account.unlocked.body.ftl

唯一真正的区别是,您必须运行两次,以便通过将n替换为字符串中此模式的匹配项来查找这两个匹配项。如果您事先不知道发生的次数,那么这可能会导致一些问题。如果您这样做,那么它比使用REGEXP\u REPLACE稍微干净。

REGEXP\u substry您的文本,1,1,1@EgorSkriptunoff它应该得到一个答案Ithink@EgorSkriptunoff非常感谢。这是可行的,但我只得到第一个,而不是两个。我能两个都要吗,每一排?Thx@senzacionale-既然您已经获得了90%的解决方案,我建议您将此视为一种挑战,仔细阅读一下正则表达式,然后自己找出如何实现这一点。祝你好运。是的,regexp\u substry你的文本,1,n,1 regexp\u substry你的文本,1,1,1@EgorSkriptunoff它应该得到一个答案think@EgorSkriptunoff非常感谢。这是可行的,但我只得到第一个,而不是两个。我能两个都要吗,每一排?Thx@senzacionale-既然您已经获得了90%的解决方案,我建议您将此视为一种挑战,仔细阅读一下正则表达式,然后自己找出如何实现这一点。祝您好运。是的,regexp\u substry您的文本,1,n,1 Hello,第一个示例非常好,但也返回notification.bar.account.locked.body.ftl,而不返回notification.bar.account.unlocked.body.ftl。您可以将其更改为返回多个结果吗?首先,第一个示例非常好,但也只返回notification.bar.account.locked.body.ftl,而不返回notification.bar.account.unlocked.body.ftl。您能将其更改为返回多个结果查询结果一些不需要的结果查询结果一些不需要的垃圾吗