Clob字段中字符替换求助(注意,大于32K)
我需要替换一个clob字段中的部分字符串,然后在网上找了个存储过程,如下:
CREATE OR REPLACE PROCEDURE CATAN.replaceClob_new (
srcClob IN CLOB,
replaceStr IN VARCHAR2,
replaceWith IN VARCHAR2,
newClob OUT CLOB
)
IS
vBuffer VARCHAR2 (32767);
l_amount BINARY_INTEGER := 32767;
l_pos PLS_INTEGER := 1;
l_clob_len PLS_INTEGER;
BEGIN
newClob := EMPTY_CLOB;
-- initalize the new clob
dbms_lob.createtemporary(newClob,TRUE);
--newClob := EMPTY_CLOB;
--srcClob := EMPTY_CLOB;
l_clob_len := dbms_lob.getlength(srcClob);
WHILE l_pos < l_clob_len
LOOP
dbms_lob.read(srcClob, l_amount, l_pos, vBuffer);
IF vBuffer IS NOT NULL THEN
-- replace the text
vBuffer := replace(vBuffer, replaceStr, replaceWith);
-- write it to the new clob
dbms_lob.writeappend(newClob, LENGTH(vBuffer), vBuffer);
END IF;
l_pos := l_pos + l_amount;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
RAISE;
END;
/
然后测试了一下,对于小于32k(32767)的clob字段,可以正常工作,但是一旦大于32k,这个存储过程似乎就不行了,超出了buffer的范围,请教各位大侠有何办法解决?
------解决方案--------------------
o,dbms_lob没有replace方法。你把l_amount的值改为20000试试。