utl file包的應用

2021-03-31 08:56:30 字數 1027 閱讀 4843

第一步:以管理員使用者登陸

如:conn

sys/password@sid as sysdba

第二步:設定可操作目錄

需要指定utl_file包可以操作的目錄。在oracle 10g以前,可以用以下方法:

1、alter system set utl_file_dir='e:/utl' scope=spfile;

2、在init.ora檔案中,配置如下:

utl_file=e:/utl或者utl_file_dir=e:/utl

在oracle 10g中建議用以下方法配置:create directory utl as 'e:/utl';

參見oracle online:

grant execute on utl_file to scott;

第四步:conn scott/tiger

就可以正常使用utl_file了。

具體使用例項:

create or replace procedure test_data_txt

islog_file utl_file.file_type;

curr_time varchar2(25);

begin

--開啟日誌檔案

log_file := utl_file.fopen('e:/utl','test.log','a');

--獲取當前時間

select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') into curr_time from dual;

--輸入資訊

utl_file.putf(log_file, '-- start_time: %s --/nauthor=%s/n', curr_time, 'tom');

--輸出快取

utl_file.fflush(log_file);

--關閉

utl_file.fclose(log_file);

--utl_file.fclose_all;

end test_data_txt;

utl file包進行OS檔案操作

利用 oracle utl file 1 建立檔案目錄 首先在資料庫伺服器上建立相應的檔案目錄。1 1方法 在初始化檔案配置檔案 init.ora 的配置中將 utl file dir e temp 指定路徑 1.2 方法 建立路徑物件 create directory test dir as e ...

利用UTL FILE包實現檔案I O操作

檔案i o對於資料庫的開發來說顯得很重要,比如如果資料庫中的一部分資料來自於磁碟檔案,那麼就需要使用i o介面把資料匯入到資料庫中來。在pl sql中沒有直接的i o介面,一般在除錯程式時可以使用oracle自帶的dbms output包的put line函式 即向螢幕進行i o操作 即可,但是對於...

oracle利用utl file包來讀寫檔案

oracle利用使用utl file包 create or replace procedure loadfiledata p path varchar2,p filename varchar2 is v filehandle utl file.file type 定義一個檔案控制代碼 v text ...

oracle中utl file包讀寫檔案操作學習

oracle中utl file包讀寫檔案操作學習 在oracle中utl file包提供了一些操作文字檔案的函式和過程,學習了一下他的基本操作 www.2cto.com 1.建立directory,並給使用者授權 建立directory create or replace directory tes...

關於utl file的初步使用

首先對utl file的執行授權 grant execute on utl file to penol 然後在本地建立了一個儲存過程 create or replace procedure datatotxt as tmpfile handle utl file.file type begin tm...