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;