Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2665
  • Last Modified:

Error ORA-06502 in DBMS_LOB.READ

I am generating XML by use of DBMS_XMLGEN.getxml pakage and the output i am storing into one CLOB. Then i am reading the value from the CLOB by use of DBMS_LOB.READ for every 32767 count of data. Below is my code. My Total LOB length is 450755. In the loop, When it reaches 393205, i am getting the below error.

ORA-06502: PL/SQL: numeric or value error: character string buffer too small

Please let me know what may be the problem

Thanks
DECLARE
    v_xml_clob     CLOB := EMPTY_CLOB();

    v_lob_length   INTEGER;
    v_index        INTEGER := 1;
    v_read_cnt     INTEGER;
    v_chunk        VARCHAR2(32767);

BEGIN
    o_ret_code := 0;

    SELECT  DBMS_XMLGEN.getxml ('SELECT OBJECT_NAME, OBJECT_TYPE FROM DBS_OBJECTS')
        INTO    v_xml_clob
        FROM    DUAL;

    v_lob_length  := NVL(DBMS_LOB.getlength(v_xml_clob),0);
    DBMS_OUTPUT.PUT_LINE('LOB Length : '||v_lob_length);

    v_index       := 1;

    -- Start to read the data from CLOB object
    WHILE v_index <= v_lob_length
    LOOP
        DBMS_OUTPUT.PUT_LINE('IN');
        v_read_cnt   := 32767;
        DBMS_LOB.read (
                    v_xml_clob,
                    v_read_cnt,
                    v_index,
                    v_chunk
                    );

        -- USe fnd_file.put function to place the XML data into concurrent view output
        fnd_file.put(fnd_file.output,v_chunk);
        DBMS_OUTPUT.PUT_LINE('v_index Start: '||v_index);
        v_index := v_index + v_read_cnt;
        DBMS_OUTPUT.PUT_LINE('v_index End: '||v_index);
    END LOOP;

EXCEPTION
WHEN OTHERS
THEN
    ROLLBACK;
    NULL;
END;

Open in new window

0
Suriyaraj_Sudalaiappan
Asked:
Suriyaraj_Sudalaiappan
  • 6
  • 5
  • 2
2 Solutions
 
slightwv (䄆 Netminder) Commented:
What version or Oracle are you using?

Can you use clob2file?
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_xslpro.htm
0
 
Suriyaraj_SudalaiappanAuthor Commented:
i am using Oracle 10.2.0.4.0
0
 
slightwv (䄆 Netminder) Commented:
and, Can you use clob2file?  That was a 10.2 link I posted.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
Suriyaraj_SudalaiappanAuthor Commented:
yes i am trying now. mean while can you please tell me why the loop process is stopped once the read count reaches to 393205. I am not able to get the things here.
0
 
slightwv (䄆 Netminder) Commented:
>>can you please tell me why the loop process is stopped

Sorry, I cannot.  It looks like you only posted a subset of the code so I cannot begin to test on my system.

If you can post stand-alone code I can run on my side, I can test with 10.2.0.3 and see if I can reproduce the error and if so, come up with a work-around.
0
 
johnsoneSenior Oracle DBACommented:
Could it be some sort of character set conversion?  If something in the data is being converted to a multibyte character set, then the 32767 limit would overflow.

This is from the doc:

When calling DBMS_LOB.READ from the client (for example, in a BEGIN/END block from within SQL*Plus), the returned buffer contains data in the client's character set. The database converts the LOB value from the server's character set to the client's character set before it returns the buffer to the user.
0
 
Suriyaraj_SudalaiappanAuthor Commented:
So is there any way to overcome this conversion problem?
0
 
Suriyaraj_SudalaiappanAuthor Commented:
And also it is working when i process the small volume of data. The problem is from only large volume of data
0
 
slightwv (䄆 Netminder) Commented:
If it is a conversion issue, just cut the size of your 'chunk' in half:

v_read_cnt   := 16383;
0
 
Suriyaraj_SudalaiappanAuthor Commented:
hi slightwv,

it is over. Thanks the issue is fixed now after i changed v_read_cnt   := 16383. But How it is possible? My v_chunk accepts till 32767 buffer. That' what i am reading every 32767 data from LOB.

Please explain me clearly.

Thanks
0
 
slightwv (䄆 Netminder) Commented:
As johnsone pointed out (and correctly), it is probably a characterset conversion error.

The issue is when reading a character form the database it can get 'expanded' into two bytes.  The chunk buffer can hold 32767 characters so if you read 16383 multi-byte characters from the database, it takes up twice the room (the 32766, one left over from rounding).
0
 
johnsoneSenior Oracle DBACommented:
Seeing as how the smaller chunk worked, I would bet on the character set conversion.  Based on how far you got through the data, you probably don't have a lot of strange characters, so going to half on the chunk size, while definitely the safe way to do it, probably wasn't necessary.  You could probably bump the size up to more like 30,000, but to prevent it from happening again, half (as slightwv suggested) is the best route.

The other way to do it would be to make sure that the character set on the client is the same as the server.  This would be an alter statement or an environment variable change.  However, if you want to account for every situation, as you cannot control every client, the way you are doing it now is probably best.
0
 
Suriyaraj_SudalaiappanAuthor Commented:
GOOD ONE
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now