Oracle:插入文本< /br>在现有文本之前

ffscu2ro  于 2023-11-17  发布在  Oracle
关注(0)|答案(1)|浏览(194)

我的数据库中有一个CLOB列,包含如下内容:

<?xml version="1.0"?>
<tdfmt sel-start="218">31 05 2022 Rico Strydom<br/>
Op verzoek (zie e-mail) garanties overplaatsen....<br/>
    <br/>
OVERBOEKING CREDITGELDEN:<br/>BANKCODE: 1171<br/>T.L.V.: VERP. NL99BANK999999999999<br/>T.G.V.: RC NL00BANK000000000000<br/>
BEDRAG: EUR 9999999<br/>BESCHRIJVING: Vrijgave verpanding creditgelden AA98987987987 ivm overzetten zekerheid naar BGF<br/>
    <br/>
</tdfmt>

字符串
我想通过在根(tdfmt)后面添加文本来更新此字段,然后再添加另一个</br>
结果是:

<?xml version="1.0"?>
<tdfmt sel-start="218">THIS TEXT SHOULD GO FIRST</br>
31 05 2022 Rico Strydom<br/>
Op verzoek (zie e-mail) garanties overplaatsen....<br/>
    <br/>
OVERBOEKING CREDITGELDEN:<br/>BANKCODE: 1171<br/>T.L.V.: VERP. NL99BANK999999999999<br/>T.G.V.: RC NL00BANK000000000000<br/>
BEDRAG: EUR 9999999<br/>BESCHRIJVING: Vrijgave verpanding creditgelden AA98987987987 ivm overzetten zekerheid naar BGF<br/>
    <br/>
</tdfmt>


我已经尝试更新我的clob与此,但我怀疑的numb(13)是要走的路。

UPDATE OIT SET INFTXT = UPDATEXML(XMLTYPE(OIT.INFTXT),'//tdfmt/text()[1]','THIS TEXT SHOULD GO FIRST' || chr(10)  || EXTRACTVALUE(XMLTYPE(OIT.INFTXT), '//tdfmt/text()[1]', '')).getClobVal()


希望我的愿望是明确的…

lsmd5eda

lsmd5eda1#

您可以使用XMLQuery和FLWOR而不是XMLATEXML:

UPDATE OIT SET INFTXT = XMLQUERY(q'^
      copy $i := $d modify (
        for $j in $i/tdfmt/text()[1]
          return insert node ( $text, $br, '&#xa;' ) before $j
      )
      return $i
    ^'
    PASSING
      XMLTYPE(OIT.INFTXT) AS "d",
      'THIS TEXT SHOULD GO FIRST' AS "text",
      XMLTYPE('<br/>') AS "br"
    RETURNING CONTENT
  ).getClobVal();

字符串
这就给了你:

<?xml version="1.0"?><tdfmt sel-start="218">THIS TEXT SHOULD GO FIRST<br/>
31 05 2022 Rico Strydom<br/>
Op verzoek (zie e-mail) garanties overplaatsen....<br/><br/>
OVERBOEKING CREDITGELDEN:<br/>BANKCODE: 1171<br/>T.L.V.: VERP. NL99BANK999999999999<br/>T.G.V.: RC NL00BANK000000000000<br/>
BEDRAG: EUR 9999999<br/>BESCHRIJVING: Vrijgave verpanding creditgelden AA98987987987 ivm overzetten zekerheid naar BGF<br/><br/></tdfmt>


或者为了保留(我认为,主要是!)你现有的格式,使用XMLSerialise而不是getClobVal:

UPDATE OIT SET INFTXT = XMLSERIALIZE(DOCUMENT XMLQUERY(q'^
      copy $i := $d modify (
        for $j in $i/tdfmt/text()[1]
          return insert node ( $text, $br, '&#xa;' ) before $j
      )
      return $i
    ^'
    PASSING
      XMLTYPE(OIT.INFTXT) AS "d",
      'THIS TEXT SHOULD GO FIRST' AS "text",
      XMLTYPE('<br/>') AS "br"
    RETURNING CONTENT
  ) AS CLOB INDENT SIZE=4);


这就给了你:

<?xml version="1.0"?>
<tdfmt sel-start="218">THIS TEXT SHOULD GO FIRST<br/>
31 05 2022 Rico Strydom<br/>
Op verzoek (zie e-mail) garanties overplaatsen....<br/>
    <br/>
OVERBOEKING CREDITGELDEN:<br/>BANKCODE: 1171<br/>T.L.V.: VERP. NL99BANK999999999999<br/>T.G.V.: RC NL00BANK000000000000<br/>
BEDRAG: EUR 9999999<br/>BESCHRIJVING: Vrijgave verpanding creditgelden AA98987987987 ivm overzetten zekerheid naar BGF<br/>
    <br/>
</tdfmt>


fiddle
我已经传入了文本字符串和<br/>标记作为参数,假设是至少文本部分将是一个变量;如果你愿意,你也可以传入换行符:

UPDATE OIT SET INFTXT = XMLSERIALIZE(DOCUMENT XMLQUERY('
      copy $i := $d modify (
        for $j in $i/tdfmt/text()[1]
          return insert node ( $text, $br, $newline ) before $j
      )
      return $i
    '
    PASSING
      XMLTYPE(OIT.INFTXT) AS "d",
      'THIS TEXT SHOULD GO FIRST' AS "text",
      XMLTYPE('<br/>') AS "br",
      CHR(10) as "newline"
    RETURNING CONTENT
  ) AS CLOB INDENT SIZE=4);


fiddle
虽然我不确定你是否真的想要/需要它。

相关问题