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
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With