|
|

楼主 |
发表于 2006/10/20 16:01:19
|
显示全部楼层
- CREATE OR REPLACE PROCEDURE read_demo (file_name VARCHAR2) IS
- vSFile utl_file.file_type;
- vNewLine VARCHAR2(200);
- BEGIN
- vSFile := utl_file.fopen('ORALOAD', 'test.txt','r');
- IF utl_file.is_open(vSFile) THEN
- LOOP
- BEGIN
- utl_file.get_line(vSFile, vNewLine);
- IF vNewLine IS NULL THEN
- EXIT;
- END IF;
- INSERT INTO test
- (fld1, fld2)
- VALUES
- (vNewLine, file_name);
- EXCEPTION
- WHEN NO_DATA_FOUND THEN
- EXIT;
- END;
- END LOOP;
- COMMIT;
- END IF;
- utl_file.fclose(vSFile);
- utl_file.frename('ORALOAD', 'test.txt', 'ORALOAD', 'x.txt', TRUE);
- EXCEPTION
- WHEN utl_file.invalid_mode THEN
- RAISE_APPLICATION_ERROR (-20051, 'Invalid Mode Parameter');
- WHEN utl_file.invalid_path THEN
- RAISE_APPLICATION_ERROR (-20052, 'Invalid File Location');
- WHEN utl_file.invalid_filehandle THEN
- RAISE_APPLICATION_ERROR (-20053, 'Invalid Filehandle');
- WHEN utl_file.invalid_operation THEN
- RAISE_APPLICATION_ERROR (-20054, 'Invalid Operation');
- WHEN utl_file.read_error THEN
- RAISE_APPLICATION_ERROR (-20055, 'Read Error');
- WHEN utl_file.internal_error THEN
- RAISE_APPLICATION_ERROR (-20057, 'Internal Error');
- WHEN utl_file.charsetmismatch THEN
- RAISE_APPLICATION_ERROR (-20058, 'Opened With FOPEN_NCHAR
- But Later I/O Inconsistent');
- WHEN utl_file.file_open THEN
- RAISE_APPLICATION_ERROR (-20059, 'File Already Opened');
- WHEN utl_file.invalid_maxlinesize THEN
- RAISE_APPLICATION_ERROR(-20060,'Line Size Exceeds 32K');
- WHEN utl_file.invalid_filename THEN
- RAISE_APPLICATION_ERROR (-20061, 'Invalid File Name');
- WHEN utl_file.access_denied THEN
- RAISE_APPLICATION_ERROR (-20062, 'File Access Denied By');
- WHEN utl_file.invalid_offset THEN
- RAISE_APPLICATION_ERROR (-20063,'FSEEK Param Less Than 0');
- WHEN others THEN
- RAISE_APPLICATION_ERROR (-20099, 'Unknown UTL_FILE Error');
- END read_demo;
- /
复制代码 |
|