導航:首頁 > 文件教程 > 存儲過程上傳文件

存儲過程上傳文件

發布時間:2025-01-05 11:52:03

A. 如何把oracle 存儲過程 輸出到文本

分幾個步驟
1,創建輸出路徑,比如你要在c盤test目錄下輸出,你就先要建立好這個test路徑

2,sqlplus下以sysdba登錄,執行以下語句

3,create or replace directory TMP as 'c: est'

4,grant read,write on directory TMP to 你要生成文件的用戶;

5,alter system set utl_file_dir='c: est' scope=spfile;
以上步驟執行完,需要重啟資料庫

6,最重要的一步開始了,創建存儲過程

createorreplacePROCEDURESP_OUTPUT
is
file_handleutl_file.file_type;
Write_contentVARCHAR2(1024);
Write_file_nameVARCHAR2(50);
v_idint;
v_formvarchar2(10);
cursorcur_sp_out
is
selectid,formfroma;
begin
opencur_sp_out;
loop
fetchcur_sp_outintov_id,v_form;
exitwhencur_sp_out%notfound;
write_file_name:=to_char(SYSDATE,'MMDD')||'.txt'
file_handle:=utl_file.fopen('TMP',write_file_name,'a');
write_content:=v_id||''||v_form;
--writefile
IFutl_file.is_open(file_handle)THEN
utl_file.put_line(file_handle,write_content);
ENDIF;
--closefile
utl_file.fclose(file_handle);
endloop;
closecur_sp_out;
end;


我建立了一個跟你一樣的測試表,數據如下
createtablea(idint,
formvarchar2(10));

insertintoavalues(1,'你好');
insertintoavalues(2,'你很好');


然後執行存儲過程
begin
SP_OUTPUT;
end;


執行完畢後,你在c盤test路徑下會發現已經有新文件生成


文件內容


存儲過程的話,如果表名和欄位名跟你一致的話,你無須修改

閱讀全文

與存儲過程上傳文件相關的資料

熱點內容
常州採集物聯網大數據平台有哪些 瀏覽:950
win10休眠文件改到d盤 瀏覽:626
如何編程手機app軟體 瀏覽:656
node獲取文件名 瀏覽:367
iphoneios7怎麼設置鈴聲 瀏覽:52
手機qq激活星鑽 瀏覽:302
html中引入js文件路徑 瀏覽:83
0基礎自學編程可以看什麼書 瀏覽:860
javapoi導出excel 瀏覽:212
迷你編程迷小酷為什麼郵箱里沒有 瀏覽:33
ipadqq接收的文件在哪裡 瀏覽:15
拼多多初級看哪些數據 瀏覽:848
win10開機密碼屏幕鍵盤 瀏覽:162
文件夾樂高 瀏覽:914
外置文件夾掛載 瀏覽:304
人人視頻本地緩存文件 瀏覽:194
java俄羅斯方塊項目描述 瀏覽:354
win10系統被凍結 瀏覽:460
excel文件批量合並 瀏覽:948
linuxxmind 瀏覽:93

友情鏈接