Pages

Friday, May 21, 2010

My Quick PL/SQL

Read a File:

Create Directory TMP_DIR As 'xxxxxxxx';

Declare
input_file utl_file.file_type;
input_buffer varchar2(98);
pos NUMBER := 0;

Begin
input_file := utl_file.fopen ('TMP_DIR','aaaa.bbb', 'R');

If utl_file.is_open(input_file) Then
Loop
Begin
utl_file.get_line(input_file, input_buffer);

If input_buffer Is Null Then
EXIT;
End If;

Select instr(input_buffer, 'NUMBER OF ROWS FETCHED') Into pos From dual;

If pos > 0
Then
Select to_number(substr(input_buffer, 92,7)) Into inrcgl_cnt From dual;
dbms_output.put_line('INRCGL:'|| inrcgl_cnt);
End If;

Exception
When NO_DATA_FOUND Then
EXIT;
End;
End Loop;

End If;

utl_file.fclose(input_file);*/