Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replacing characters in a CLOB column (db2)

Tags:

db2

clob

I have a CLOB(2000000) field in a db2 (v10) database, and I would like to run a simple UPDATE query on it to replace each occurances of "foo" to "baaz".

Since the contents of the field is more then 32k, I get the following error:

"{some char data from field}" is too long.. SQLCODE=-433, SQLSTATE=22001

How can I replace the values?

UPDATE: The query was the following (changed UPDATE into SELECT for easier testing):

SELECT REPLACE(my_clob_column, 'foo', 'baaz') FROM my_table WHERE id = 10726

UPDATE 2 As mustaccio pointed out, REPLACE does not work on CLOB fields (or at least not without doing a cast to VARCHAR on the data entered - which in my case is not possible since the size of the data is more than 32k) - the question is about finding an alternative way to acchive the REPLACE functionallity for CLOB fields.

Thanks, krisy

like image 296
krisy Avatar asked Jul 21 '15 12:07

krisy


People also ask

How do I replace a string in a CLOB in Oracle?

DECLARE result CLOB; BEGIN result:='I need to replace this <my_tag>Everything can be here </my_tag>'; -- Some operation to replace '<my_tag>Everything can be here </my_tag>' with '<It works/>' DBMS_OUTPUT.

What is replace in DB2?

DB2 replace is a function provided by IBM in the DB2 database management system which helps us to replace a particular string present inside the original string with any other required string. By using this function, all the occurrences of the mentioned string in the supplied string are being replaced.

What is CLOB in DB2?

CLOB. A character large object (CLOB) is a varying-length string with a maximum length of 2,147,483,647 bytes (2 gigabytes minus 1 byte). A CLOB is designed to store large SBCS data or mixed data, such as lengthy documents.


1 Answers

Finally, since I have found no way to this by an SQL query, I ended up exporting the table, editing its lob content in Notepad++, and importing the table back again.

like image 188
krisy Avatar answered Sep 17 '22 15:09

krisy