如果你不确定我的意思,请不要给出反馈.
我在Oracle数据库中有一个表,其中包含数据类型为CLOB的字段.字段名称是XMLString.我正在存储每个记录长度为10,000个字符的XML字符串.我在这张表中有超过10万条记录.
现在我有一种情况,我需要更新特定位置的每条记录上的XML字符串段.例如,我需要使用"我的新文本"等字符串更新第14个位置的每个记录.此替换文本长度为11个字符.所以这只是意味着它将取代从第14个角色开始的11个追逐者.
我尝试过使用CLOB,但这并不是我想要的.
有没有像这样简单的命令
Replace(XMLString, 14, ‘My New text’)
Run Code Online (Sandbox Code Playgroud)
这样我可以做下面的事情?
UPDATE MYTABLE
SET MyClobField = Replace(MyClobField, 14, 'My New text')
WHERE MyTableID>5000
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
SQL使用
UPDATE MYTABLE
SET MyClobField = substr(MyClobField, 1, 10) || to_clob('MyNewtext')||substr(MyClobField, 10+length('MyNewtext')+1)
where..
Run Code Online (Sandbox Code Playgroud)
只需将"10"的2次出现更改为偏移量即可.
或者使用DBMS_LOB.WRITE API在这样的PL/SQL中(这比上面更快)
SQL> create table foo(c clob);
Table created.
SQL> insert into foo values ( 'this is a test string ' || rpad('x', 20, 'x'));
1 row created.
SQL> commit;
Commit complete.
SQL> select * from foo;
C
--------------------------------------------------------------------------------
this is a test string xxxxxxxxxxxxxxxxxxxx
SQL> declare
2 v_lob clob;
3 begin
4
5 for r_lob in (select c
6 from foo
7 for update)
8 loop
9 dbms_lob.write(r_lob.c, 6, 16, 'phrase'); -- ie write at offset 16, 6 bytes
10 end loop;
11 end;
12 /
PL/SQL procedure successfully completed.
SQL> select * from foo;
C
--------------------------------------------------------------------------------
this is a test phrase xxxxxxxxxxxxxxxxxxxx
Run Code Online (Sandbox Code Playgroud)