|
|
发表于 2007/4/2 17:57:29
|
显示全部楼层
一直在用过程直接读CSV/TXT文件数据
PROCEDURE read_costmain_file(file_name varchar2,.......)
IS
vSFile utl_file.file_type;
vNewLine VARCHAR2(2000);
l_separate_sign varchar2(10); 分割符
BEGIN
l_separate_sign := 'chr(9)';
vSFile:=utl_file.fopen('/usr/tmp',file_name,'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 ........
EXCEPTION
WHEN NO_DATA_FOUND THEN
EXIT;
END;
END LOOP;
COMMIT;
END IF;
utl_file.fclose(vSFile);
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.invalid_maxlinesize THEN
RAISE_APPLICATION_ERROR(-20060,'Line Size Exceeds 32K');
WHEN others THEN
RAISE_APPLICATION_ERROR(-20002, sqlerrm); --(-20099, 'Unknown UTL_FILE Error');
END ; |
|