Solved

Error ORA-06502 in DBMS_LOB.READ

Posted on 2011-03-23
13
2,355 Views
Last Modified: 2012-05-11
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
Comment
  • 6
  • 5
  • 2
13 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35197812
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
 

Author Comment

by:Suriyaraj_Sudalaiappan
ID: 35197899
i am using Oracle 10.2.0.4.0
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35197946
and, Can you use clob2file?  That was a 10.2 link I posted.
0
 

Author Comment

by:Suriyaraj_Sudalaiappan
ID: 35198357
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
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35198447
>>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
 
LVL 34

Accepted Solution

by:
johnsone earned 250 total points
ID: 35198482
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:Suriyaraj_Sudalaiappan
ID: 35198894
So is there any way to overcome this conversion problem?
0
 

Author Comment

by:Suriyaraj_Sudalaiappan
ID: 35198959
And also it is working when i process the small volume of data. The problem is from only large volume of data
0
 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 250 total points
ID: 35198974
If it is a conversion issue, just cut the size of your 'chunk' in half:

v_read_cnt   := 16383;
0
 

Author Comment

by:Suriyaraj_Sudalaiappan
ID: 35199216
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
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35199246
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
 
LVL 34

Expert Comment

by:johnsone
ID: 35199736
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
 

Author Closing Comment

by:Suriyaraj_Sudalaiappan
ID: 35468118
GOOD ONE
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now