How to save big data in Oracle to CLOB

Source: Internet
Author: User

If the data is too large, we cannot directly assign values to the clob variable. In this case, we can use the dbms_lob.read and dbms_lob.write methods to read and write clob variables in stages. However, we should set up a cache for the clob variable. The first sentence is as follows. Here is an example program. You can change the order of dbms_lob.read and dbms_lob.write so that the program can not only write big data but also read big data.

Dbms_lob.createtemporary (lob_loc => x_clob,
Cache => TRUE );
PROCEDURE load_clob (p_clob_in CLOB,
X_clob in out nocopy clob) IS

L_clob_len NUMBER: = dbms_lob.getlength (p_clob_in );
Rochelle data VARCHAR2 (32756 );
Rochelle buf_len_std NUMBER: = 4000;
Rochelle buf_len_cur NUMBER;
Rochelle seg_count NUMBER;
Rochelle write_offset NUMBER;
BEGIN
IF p_clob_in IS NOT NULL THEN
Rochelle seg_count: = floor (l_clob_len/Rochelle buf_len_std );
FOR I IN 0 .. l_seg_count
LOOP

IF I = l_seg_count THEN
Rochelle buf_len_cur: = l_clob_len-I * Rochelle buf_len_std;
ELSE
Rochelle buf_len_cur: = l_buf_len_std;
End if;

IF l_buf_len_cur> 0 THEN
Dbms_lob.read (lob_loc => p_clob_in,
Amount => l_buf_len_cur,
Offset => I * l_buf_len_std + 1,
Buffer => l_data );
Rochelle write_offset: = nvl (dbms_lob.getlength (lob_loc => x_clob ),
0) + 1;
Dbms_lob.write (lob_loc => x_clob,
Amount => l_buf_len_cur,
Offset => l_write_offset,
Buffer => l_data );
End if;
End loop;
End if;
END load_clob;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.