result of string concatenation is too long
MOHAN, April 27, 2004 - 11:23 am UTC
Hi Tom,
I am currently facing the same issue. As it has been indicated make it as 32k. Where to do it and which one has to be done..
My Oracle database version is 9i. Is there any solution in 9i since i am currently facing this issue..
the following is my code..
PROCEDURE build_customer_file (p_error_text OUT VARCHAR2)
IS
TYPE cdi_cust_rectyp IS REF CURSOR;
c_cdi_cust_recs_cur cdi_cust_rectyp;
TYPE cdi_cust_temp_typ IS TABLE OF VARCHAR2 (32766) INDEX BY BINARY_INTEGER;
c_cdi_cust_temp_rec cdi_cust_temp_typ;
ROWS NATURAL := 5;
l_location VARCHAR2(200) := 'IN BUILD_CUSTOMER_FILE';
l_method VARCHAR2(255) := 'BUILD_CUSTOMER_FILE';
l_file_location VARCHAR2(500) := '/var/spool/erp/DMDW/logfiles';
l_file_name VARCHAR2(100) := 'CU'|| TO_CHAR (SYSDATE, 'MMDDYY');
l_file_open_mode VARCHAR2(1) := 'W';
l_cust_buffer_rec VARCHAR2(1000);
l_file_id UTL_FILE.file_type;
BEGIN
l_location := 'IN OPEN_CUSTOMER_FILE';
mdw_cdi_interface.open_file (l_file_location,
l_file_name,
l_file_open_mode,
l_file_id
);
l_location := 'IN WRITE_CUSTOMER_FILE';
OPEN c_cdi_cust_recs_cur
FOR ('SELECT LPAD (NVL (TO_CHAR(account_id), '' ''), 15, '' '')
||LPAD (NVL (TO_CHAR (household_id), '' ''), 15, '' '')
||RPAD (NVL (customer_number, '' ''), 30, '' '')
||RPAD (NVL (customer_name, '' ''), 130, '' '')
||RPAD (NVL (street_line_one, '' ''), 240, '' '')
||RPAD (NVL (street_line_two, '' ''), 240, '' '')
||RPAD (NVL (city, '' ''), 60, '' '')
||RPAD (NVL (state, '' ''), 2, '' '')
||RPAD (SUBSTR (REPLACE (REPLACE (NVL (postal_code, '' ''), '' '',''''), ''-'',''''),1,9),15, '' '')
||RPAD (NVL (primary_phone, '' ''), 35, '' '')
||RPAD (NVL (do_not_rent_flag, '' ''), 1, '' '')
||RPAD (NVL (mail_preference_code, '' ''), 5, '' '')
||RPAD (NVL (category_code, '' ''), 30, '' '')
||RPAD (NVL (TO_CHAR (update_date,''YYYYMMDD''), '' ''), 8, '' '')
||RPAD (NVL (customer_status, '' ''), 1, '' '')
||RPAD (NVL (TO_CHAR (acquisition_date,''YYYYMMDD''), '' ''), 8, '' '')
||RPAD (NVL (external_source_key_id,'' ''), 10, '' '')
||RPAD (NVL (TO_CHAR (first_order_date,''YYYYMMDD''), '' ''), 8, '' '')
||RPAD (NVL (TO_CHAR (last_order_date, ''YYYYMMDD''), '' ''), 8, '' '')
||LPAD (NVL (TO_CHAR (total_order_amt), '' ''), 9, '' '')
||LPAD (NVL (TO_CHAR (total_refund_amt), '' ''), 9, '' '')
||LPAD (NVL (TO_CHAR (total_order_qty), '' ''), 8, '' '')
||RPAD (NVL (TO_CHAR (last_marketing_date,''YYYYMMDD''),'' ''), 8, '' '')
||RPAD (NVL (agc_club_member_flag, '' ''), 1, '' '')
||RPAD (NVL (country_code, '' ''), 60, '' '')
||RPAD (NVL (province, '' ''), 60, '' '')
||RPAD (NVL (in_care_of_name, '' ''), 15, '' '')
||RPAD (NVL (organization_code, '' ''), 10, '' '') cust_record
FROM pc_mdw_cdi_customer_temp'
);
LOOP
FETCH c_cdi_cust_recs_cur
BULK COLLECT INTO c_cdi_cust_temp_rec LIMIT ROWS;
FOR i IN c_cdi_cust_temp_rec.FIRST .. c_cdi_cust_temp_rec.LAST
LOOP
BEGIN
mdw_cdi_interface.write_file (l_file_id, c_cdi_cust_temp_rec (i));
EXCEPTION
WHEN OTHERS
THEN
null;
END;
END LOOP;
EXIT WHEN c_cdi_cust_recs_cur%NOTFOUND;
END LOOP;
CLOSE c_cdi_cust_recs_cur;
l_location := 'IN CLOSE_CUST_FILE';
mdw_cdi_interface.close_file (l_file_id);
EXCEPTION
WHEN OTHERS
THEN
p_error_text := l_method || l_location || SQLCODE || SQLERRM;
END build_customer_file;
April 28, 2004 - 1:13 pm UTC
if the result of your concat in sql is > 32k, just don't do it there.
instead of
for x in ( select c1 || c2 || ... || cn data from ... )
loop
write( x.data )
do this
for x in ( select c1, c2,...., cn from .... )
loop
write ( x.c1 || x.c2 || .... || x.cn );
plsql can do 32k.
sql can do 4000 bytes only.