如何优化在UPDATE中附加到CLOB的性能?

江西

我有一个表需要更新:

create table test_tab(id number, first varchar2(100), second clob);
insert into test_tab values (1, 'john', 'kowalski');
insert into test_tab values (2, 'michael', 'surname');

现在,我的表中的每个记录,我想追加一个字符串到CLOB字段。我可以使用通常的串联运算符:

update test_tab set second = second || 'some_string,';

而这个工作,但因为我的实际表就像80K行,更新过程持续太久。

我正在考虑使用DBMS_LOB.APPEND(),但我不知道如何在UPDATE中使用它,以及它是否会对性能有所帮助。

有任何想法吗?提前致谢。

生锈的

当您需要更新表中的每个记录时,以select(CTAS)的方式重新创建表总是更快。无论哪种方法要更新LOB列。

例:

create table temp
as
select id, first, second||' some_string' as second
  from test_tab;

rename test_tab to old_test_tab; -- you can drop it later
rename temp to test_tab;

-- then you need to move all indexes, grants and etc from old_test_tab to test_tab;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章