Update Clob column in Oracle

妖精的绣舞 提交于 2020-01-02 19:26:09

问题


I have an table with name ABC which has CLOB data. I want to update the column to insert string in specific position in this Clob column.

String to be inserted :

<nv_pair>
<name identifier="XYZ"></name>
<value identifier="XYZ"></value>
</nv_pair>

Clob Data :

<form> <nv_pair></nv_pair> <nv_pair></nv_pair><nv_pair></nv_pair><nv_pair></nv_pair></form>

Position to be inserted : Just Before </form>


回答1:


Take a look at DBMS_LOB package.

BTW, it might be worth exploring the possibility of abandoning CLOB and using Oracle's built-in XML capabilities (I'm not familiar with that, though).




回答2:


Depending on which version of Oracle you have, you can use the regexp_replace function:

update abc
set clob_val =
  regexp_replace(clob_val,
                 '^(.+)(</form>)',
                 '\1<nv_pair><name identifier="XYZ"></name><value identifier="XYZ">/value>/nv_pair>\2')
where ...


来源:https://stackoverflow.com/questions/7154011/update-clob-column-in-oracle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!