Você está na página 1de 2

/* Formatted on 2018/06/27 13:50 (Formatter Plus v4.8.

8) */
--/* Formatted on 2018/06/27 13:33 (Formatter Plus v4.8.8) */
--CREATE OR REPLACE PROCEDURE xxft_wise_test (
-- errbuf OUT VARCHAR,
-- retcode OUT NUMBER
--)
--IS

DECLARE
CURSOR c1
IS
SELECT segment1, vendor_name
FROM ap_suppliers
WHERE ROWNUM < 10;

lc_dir VARCHAR2 (100);


lc_fname VARCHAR2 (500)
:= 'XYZ_OUT_' || TO_CHAR (SYSDATE, 'DDMMYYHHMISS')
|| '.csv';
lc_fhandler UTL_FILE.file_type;
lc_rbuffer VARCHAR2 (30000);
BEGIN
-- SELECT directory_path
-- INTO lc_dir
-- FROM dba_directories
-- WHERE UPPER (directory_name) = 'XXFT_TEST_PATH';
SELECT directory_path
-- INTO lc_dir
FROM dba_directories
WHERE UPPER (directory_name) = 'APPS_DATA_FILE_DIR';

--/disk1/orapps/prd/oraprd/prddb/9.2.0/appsutil/outbound/PRD_kenolprd;
DBMS_OUTPUT.put_line ('before fopen');
lc_fhandler := UTL_FILE.fopen (lc_dir, lc_fname, 'w');
DBMS_OUTPUT.put_line ('after fopen');
UTL_FILE.put_line (lc_fhandler, 'SEGMENT1' || ',' || 'VENDOR_NAME');

FOR i IN c1
LOOP
UTL_FILE.put_line (lc_fhandler, i.segment1 || ',' || i.vendor_name);
COMMIT;
END LOOP;

UTL_FILE.fclose (lc_fhandler);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
apps.fnd_file.put_line (apps.fnd_file.LOG,
'No Data Found in the File ==> ' || SQLERRM
);
DBMS_OUTPUT.put_line ('NO DATA FOUND');
UTL_FILE.fclose (lc_fhandler);
WHEN UTL_FILE.invalid_path
THEN
apps.fnd_file.put_line (apps.fnd_file.LOG,
'Invalid Path for the file ==> ' || SQLERRM
);
DBMS_OUTPUT.put_line ('INVALID_PATH' || SQLERRM);
UTL_FILE.fclose (lc_fhandler);
WHEN UTL_FILE.write_error
THEN
apps.fnd_file.put_line (apps.fnd_file.LOG,
'Error Occured while Writing Mode ==> '
|| SQLERRM
);
DBMS_OUTPUT.put_line ('WRITE ERROR');
UTL_FILE.fclose (lc_fhandler);
WHEN UTL_FILE.read_error
THEN
apps.fnd_file.put_line (apps.fnd_file.LOG,
'Error Occured while Reading Mode ==> '
|| SQLERRM
);
DBMS_OUTPUT.put_line ('READ ERROR');
UTL_FILE.fclose (lc_fhandler);
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('Exception Occured ' || SQLERRM);
UTL_FILE.fclose (lc_fhandler);
END;

Você também pode gostar