阿木伯 著 |
|
在Developer/2000中如何讀寫文本型操作系統(tǒng)文件? |
|
- 軟件環(huán)境:
1、服務(wù)器端:Windows NT4.0+ORACLE 8.0.4,ORACLE安裝路徑為:C:\ORANT
2、客戶端:Windows 98、Developer/2000客戶端安裝(版本2.1)
- 實(shí)現(xiàn)方法:
PL/SQL 3.3以上的版本中,UTL_FILE包允許用戶通過PL/SQL讀寫操作系統(tǒng)文件。如下:
declare
file_handle utl_file.file_type;
begin
file_handle:=utl_file.fopen('C:\','TEST.TXT','A'); --TEST.TXT是文件名
utl_file.put_line(file_handle,'寫入的信息');
utl_file.fclose(file_handle);
END;
Developer/2000中,可以用Text_IO讀寫操作系統(tǒng)文件。如下:
DECALRE
in_file Text_IO.File_Type;
out_file Text_IO.File_Type;
BEGIN
in_file:=Text_IO.Fopen('文件名', 'R');
Text_IO.Get_Line(in_file,linebuf);
Text_IO.Fclose(in_file);
out_file:=Text_IO.Fopen('文件名', 'W');
Text_IO.Put_Line(out_file,'寫入信息');
Text_IO.Fclose(out_file);
END;
--常用TEXT_IO
Declare
out_file text_io.file_type; --定義
Begin
out_file:=text_io.fopen('prn','w'); --打開文件prn
text_io.new_line(out_file,' '); --新建一行
text_io.put_line(out_file,' ') --寫入一行
text_io.fclose(out_file); --關(guān)閉文件
End;
---文本輸入輸出
TEXT_IO
TEXT_IO.PACKAGE
TEXT_IO.FCLOSE
TEXT_IO.FILE_TYPE
TEXT_IO.FOPEN
TEXT_IO.IS_OPEN
TEXT_IO.GET_LINE
TEXT_IO.NEW_LINE
TEXT_IO.PUT
TEXT_IO.PUTF
TEXT_IO.PUT_LINE
----------------------------
Declare
Out_file Text_io.file_type;
L Varchar2(100);
L1 Varchar2(100);
L2 Varchar2(100);
Begin
Out_file :=text_io.fopen('c:\ll\login.txt','r');
If text_io.is_open(Out_file) then
text_io.get_line(Out_file,L);
text_io.get_line(Out_file,L1);
text_io.get_line(Out_file,L2);
Else
Null;
End if;
End;
|
【最后更新:】 |
|