I am a beginner PL/SQL programmer. I am trying obtain fields from a cursor, fetch them into a record and write the record out using UTL_FILE.PUT_LINE(filehandle,string)
I can't compile the below without getting an error: PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'.
Where do I convert the numeric fields to character ? In the record definition in the SELECT statement ? Can I use the record in the UTL_file.PUT_LINE command ? Should I use UTL_file.PUTF and convert the fields on the way to the file ? The code is below:
CREATE OR REPLACE PROCEDURE APRP100_Requisition_Unload(p_filedir in varchar2,p_filename varchar2)
--Enter parameters for the procedure in the brackets above.
IS
BEGIN
--------- PLANT 4235 LOGIC -------------
DECLARE
v_filehandle UTL_file.file_type;
v_unload_count_4235 integer := 0;
Type plant_4235_rec is record (
plant_4235_requistion_num varchar2(13),
plant_4235_expense_element varchar2(4),
plant_4235_nomeclature varchar2(28),
plant_4235_orginator varchar2(12),
plant_4235_pcc varchar2(6),
plant_4235_deliver_to_bldg varchar2(10),
plant_4235_jon varchar2(6),
plant_4235_fiscal_year varchar2(2),
plant_4235_total_amount number(9,2));
plant_4235_out_rec plant_4235_rec;
--CURSOR
Cursor UNLOAD_plant_4235 IS
Select substr(art_requisition_number,2,13),
art_expense_element,art_nomenclature,art_originator,
substr(art_pcc,2,5), art_deliver_to_bldg,
ajt_jon, ajt_jon,art_fy,art_total_document,
From v_apr_unload_req
where art_plant_flag = 'Y' and art_fy_type = 'C'
and art_requisition_type = '1';
BEGIN
open UNLOAD_plant_4235;
LOOP
FETCH UNLOAD_plant_4235
INTO plant_4235_out_rec;
EXIT WHEN UNLOAD_plant_4235%NOTFOUND;
IF SQL%FOUND THEN
v_unload_count_4235 :=
v_unload_count_4235 + 1;
v_filehandle :=UTL_file.FOPEN
(p_filedir,p_filename,'w');
END IF;
-- WRITE RECORD
FOR record_plant_4235 in unload_plant_4235 LOOP
UTL_file.PUT_line(v_filehandle,plant_4235_out_rec);
END LOOP;
END LOOP;
close UNLOAD_plant_4235;
UTL_file.FClose(v_filehandle);
EXCEPTION
-- EXPAND EXCEPTION LOGIC !!!
WHEN OTHERS THEN
If SQL%NOTFOUND then
DBMS_OUTPUT.PUT_LINE ('NO PLANT 4235 DATA FOUND');
End if;
END;
I can't compile the below without getting an error: PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'.
Where do I convert the numeric fields to character ? In the record definition in the SELECT statement ? Can I use the record in the UTL_file.PUT_LINE command ? Should I use UTL_file.PUTF and convert the fields on the way to the file ? The code is below:
CREATE OR REPLACE PROCEDURE APRP100_Requisition_Unload(p_filedir in varchar2,p_filename varchar2)
--Enter parameters for the procedure in the brackets above.
IS
BEGIN
--------- PLANT 4235 LOGIC -------------
DECLARE
v_filehandle UTL_file.file_type;
v_unload_count_4235 integer := 0;
Type plant_4235_rec is record (
plant_4235_requistion_num varchar2(13),
plant_4235_expense_element varchar2(4),
plant_4235_nomeclature varchar2(28),
plant_4235_orginator varchar2(12),
plant_4235_pcc varchar2(6),
plant_4235_deliver_to_bldg varchar2(10),
plant_4235_jon varchar2(6),
plant_4235_fiscal_year varchar2(2),
plant_4235_total_amount number(9,2));
plant_4235_out_rec plant_4235_rec;
--CURSOR
Cursor UNLOAD_plant_4235 IS
Select substr(art_requisition_number,2,13),
art_expense_element,art_nomenclature,art_originator,
substr(art_pcc,2,5), art_deliver_to_bldg,
ajt_jon, ajt_jon,art_fy,art_total_document,
From v_apr_unload_req
where art_plant_flag = 'Y' and art_fy_type = 'C'
and art_requisition_type = '1';
BEGIN
open UNLOAD_plant_4235;
LOOP
FETCH UNLOAD_plant_4235
INTO plant_4235_out_rec;
EXIT WHEN UNLOAD_plant_4235%NOTFOUND;
IF SQL%FOUND THEN
v_unload_count_4235 :=
v_unload_count_4235 + 1;
v_filehandle :=UTL_file.FOPEN
(p_filedir,p_filename,'w');
END IF;
-- WRITE RECORD
FOR record_plant_4235 in unload_plant_4235 LOOP
UTL_file.PUT_line(v_filehandle,plant_4235_out_rec);
END LOOP;
END LOOP;
close UNLOAD_plant_4235;
UTL_file.FClose(v_filehandle);
EXCEPTION
-- EXPAND EXCEPTION LOGIC !!!
WHEN OTHERS THEN
If SQL%NOTFOUND then
DBMS_OUTPUT.PUT_LINE ('NO PLANT 4235 DATA FOUND');
End if;
END;