3

I want to insert the same long string into all cells in certain column, which is CLOB type.

It said I should use "bind variables" to do it. So i Googled this:

variable xmlstuff CLOB;
exec :xmlstuff := '<?xml version="1.0"?> ... really long xml...';

UPDATE TABLE_NAME SET COLUMN_NAME = '&&xmlstuff';

Now it still says

The string literal is longer than 4000 characters.

What is the proper use of bind variable in this case?

3
  • &&xmlstuff is not a bind variable, by the way. Commented Apr 1, 2014 at 14:03
  • Why are you working with XML as a CLOB and not as XMLType? Commented Apr 1, 2014 at 14:06
  • @evenro: Because of previous programmers. Commented Apr 1, 2014 at 14:10

1 Answer 1

1

If you are programming using C# or Java - just use the OracleCLOB object, and it will do all the necessary steps.

If you want to use a CLOB in SQL or PL/SQL, you need to allocate it, and release it after using.
search for DBMS_LOB information.

Regarding the 4000 bytes limit - this is a varchar2 limit within SQL.
to bypass this - you can use PL/SQL - which limits you to a varchar of 32KB, which is not as near to the 4GB that you can hold in a CLOB, but that is the limit for "automatic" creation of a CLOB.
if your string is longer than 32K - you'll have to use a DBMS_LOB to load the data into the clog object, by using append on the clob object.

this is the fastest link I found about how to do it: http://geekswithblogs.net/robertphyatt/archive/2010/03/24/write-read-and-update-oracle-clobs-with-plsql.aspx

I wanted to answer fast, so please let me know if you cannot solve your issue after getting this information - and I'll try to explain it better.

Sign up to request clarification or add additional context in comments.

4 Comments

Whoa, that looks hard. I thought the answer is gonna be something like "Just add this line into the SQL script and it will work."
Sorry :( For short strings it works - but for things that are bigger than the limits- you need to work harder...
Thanks anyway. This may help somebody who thinks the same as i did.
Just for clarification - it is 4000 bytes limit (just fixed it above) - for languages that each character is 2 bytes, it'll be 2000 chars... (important to be accurate..)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.