Home » SQL & PL/SQL » SQL & PL/SQL » returning dbms_xmlgen.getxml into a varchar2 (10g)
returning dbms_xmlgen.getxml into a varchar2 [message #452232] |
Tue, 20 April 2010 16:11  |
apollo
Messages: 20 Registered: September 2007
|
Junior Member |
|
|
I know that dbms_xmlgen.getxml returns a CLOB, however it can be returned into a VARCHAR2 as long as the returned value is not "too big". The thing that confuses me is the "too big" value seems to be 4043 characters rather than the expected 32768 characters. Does anyone know why this is? Thanks in advance.
Below are two code examples, one that works and one that doesn't. (note that we are in a multibyte environment).
This example successfully returns a 4042 character string into variable "s2". "function_gen_4000_characters" is just a function that returns 4000 characters as a VARCHAR2. The extra 42 characters are XML tags.
DECLARE
TYPE rc IS ref CURSOR;
s rc;
s2 VARCHAR2(32767);
ctx DBMS_XMLGEN.ctxHandle;
BEGIN
OPEN s FOR
SELECT xmlforest(function_gen_4000_characters "a")"b"
FROM dual;
ctx := dbms_xmlgen.newcontext( s );
dbms_xmlgen.setrowsettag( ctx, NULL );
dbms_xmlgen.setrowtag( ctx, NULL );
s2 := dbms_xmlgen.getxml( ctx );
END;
Now this next example, which should return 4043 characters, raises error "PL/SQL: numeric or value error: character string buffer too small".
DECLARE
TYPE rc IS ref CURSOR;
s rc;
s2 VARCHAR2(32767);
ctx DBMS_XMLGEN.ctxHandle;
BEGIN
OPEN s FOR
SELECT xmlforest(function_gen_4001_characters "a")"b"
FROM dual;
ctx := dbms_xmlgen.newcontext( s );
dbms_xmlgen.setrowsettag( ctx, NULL );
dbms_xmlgen.setrowtag( ctx, NULL );
s2 := dbms_xmlgen.getxml( ctx );
END;
|
|
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Sat Jul 05 09:52:09 CDT 2025
|