校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識庫 > oracle中utl_file包讀寫文件操作實例學(xué)習(xí)

oracle中utl_file包讀寫文件操作實例學(xué)習(xí)

熱門標(biāo)簽:開封智能外呼系統(tǒng)廠家 美圖秀秀地圖標(biāo)注 人工智能地圖標(biāo)注自己能做嗎 征服者火車站地圖標(biāo)注 外呼線路外顯本地號碼 阿爾巴尼亞地圖標(biāo)注app 百度地圖標(biāo)注素材 征服眼公司地圖標(biāo)注 word地圖標(biāo)注方向
在oracle中utl_file包提供了一些操作文本文件的函數(shù)和過程,學(xué)習(xí)了一下他的基本操作
1.創(chuàng)建directory,并給用戶授權(quán)
復(fù)制代碼 代碼如下:

--創(chuàng)建directory
create or replace directory TESTFILE as '/home/oracle/zxx/test';
--給用戶授權(quán)
grant read, write on directory TESTFILE to zxx;

詳細(xì)介紹
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm
2.寫入操作
復(fù)制代碼 代碼如下:

---測試寫入
DECLARE
filehandle utl_file.file_type; --句柄
begin
filehandle := utl_file.fopen('TESTFILE','hello.txt','w'); --打開文件
utl_file.put_line(filehandle,'Hello Oracle!');--寫入一行記錄
utl_file.put_line(filehandle,'Hello World!');
utl_file.put_line(filehandle,'你好,胖子!');
utl_file.fclose(filehandle);--關(guān)閉句柄
end;

備注:
fopen有一個參數(shù)max_linesize,下面是原文解釋
Maximum number of characters for each line, including the newline character, for this file (minimum value 1, maximum value 32767). If unspecified, Oracle supplies a default value of 1024.
3.讀取操作
復(fù)制代碼 代碼如下:

--測試讀取
set serveroutput on;
DECLARE
filehandle utl_file.file_type;
filebuffer varchar2(500);
begin
filehandle := utl_file.fopen('TESTFILE','hello.txt','R');
IF utl_file.is_open(filehandle) THEN
dbms_output.put_line('file is open!');
END IF;
loop
begin
utl_file.get_line(filehandle,filebuffer);
dbms_output.put_line(filebuffer);
EXCEPTION
WHEN no_data_found THEN
exit ;
WHEN OTHERS THEN
dbms_output.put_line('EXCEPTION1:'||SUBSTR(SQLERRM, 1, 100)) ;
end;
end loop;
utl_file.fclose(filehandle);
IF utl_file.is_open(filehandle) THEN
dbms_output.put_line('file is open!');
else
dbms_output.put_line('file is close!');
END IF;
utl_file.fcopy('TESTFILE', 'hello.txt', 'TESTFILE', 'hello.dat');--復(fù)制
utl_file.fcopy('TESTFILE', 'hello.txt', 'TESTFILE', 'hello2.dat');
utl_file.fcopy('TESTFILE', 'hello.txt', 'TESTFILE', 'hello.xls');
utl_file.frename('TESTFILE','hello.xls','TESTFILE','frenamehello.xls',TRUE);--重命名
utl_file.fremove('TESTFILE', 'hello2.dat');--刪除文件
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('EXCEPTION2:'||SUBSTR(SQLERRM, 1, 100)) ;
end;

4.判斷文件是否存在(讀,重命名,復(fù)制,刪除都要判斷文件是否存在)
復(fù)制代碼 代碼如下:

--判斷文件是否存在
DECLARE
ex BOOLEAN;--文件是否存在
flen NUMBER;--文件長度? 這個地方不知道怎么理 (原文 file_length The length of the file in bytes. NULL if file does not exist.)
bsize NUMBER;--文件大小
BEGIN
utl_file.fgetattr('TESTFILE', 'hello.txt', ex, flen, bsize);
IF ex THEN
dbms_output.put_line('File Exists');
ELSE
dbms_output.put_line('File Does Not Exist');
END IF;
dbms_output.put_line('File Length: ' || TO_CHAR(flen));
dbms_output.put_line('Block Size: ' || TO_CHAR(bsize));
END fgetattr;
您可能感興趣的文章:
  • PHP中讀寫文件實現(xiàn)代碼
  • java 讀寫文件[多種方法]
  • Python open讀寫文件實現(xiàn)腳本
  • vb.net讀寫文件代碼
  • PHP讀寫文件的方法(生成HTML)

標(biāo)簽:酒泉 六安 泰安 宜春 孝感 海北 葫蘆島 淮南

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《oracle中utl_file包讀寫文件操作實例學(xué)習(xí)》,本文關(guān)鍵詞  oracle,中,utl,file,包讀寫,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《oracle中utl_file包讀寫文件操作實例學(xué)習(xí)》相關(guān)的同類信息!
  • 本頁收集關(guān)于oracle中utl_file包讀寫文件操作實例學(xué)習(xí)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 沙雅县| 日照市| 武隆县| 安福县| 安岳县| 泸西县| 微山县| 博乐市| 江门市| 新巴尔虎左旗| 昌邑市| 北宁市| 民权县| 汕尾市| 犍为县| 水富县| 台北市| 吐鲁番市| 长治县| 米林县| 宁明县| 阳信县| 怀远县| 宜良县| 横峰县| 壶关县| 高密市| 兴城市| 辰溪县| 青田县| 湘乡市| 女性| 百色市| 和政县| 滨州市| 南昌县| 石狮市| 永定县| 淅川县| 溧阳市| 二连浩特市|