一個(gè)簡(jiǎn)單的Oracle寫(xiě)文件例子
初學(xué)Oracle時(shí),你可能對(duì)Oracle寫(xiě)文件的作用不慎了解,下面小編就提供一個(gè)寫(xiě)字符串到文件中的例子。當(dāng)然你也可以通過(guò)Oracle中提供的一個(gè)utl_file的包可以將字符串讀寫(xiě)到文件中。下面請(qǐng)看具體的步驟:
1:修改INIT.ORA文件,加上UTL_FILE_PATH = <要?jiǎng)?chuàng)建文件的路徑名>
2:
- create or replace procedure sp_write_to_file(Path in varchar2, FileName in varchar2, Contents in varchar2) is
- handle utl_file.file_type;
- nrow number;
- nindex number;
- begin
- handle := utl_file.fopen(Path, FileName, ''a'');
- nrow := length(Contents) /1023;
- nindex := 0;
- if (nrow > 1)
- then
- LOOP
- if (nindex <= nrow -1)
- then
- utl_file.put(handle, substr(Contents, nindex*1023, 1023));
- utl_file.fflush(handle);
- else
- utl_file.put(handle, substr(Contents, nindex*1023, length(Contents) - nindex*1023));
- utl_file.fflush(handle);
- end if;
- if (nindex = floor(nrow))
- then
- exit;
- end if;
- nindex := nindex + 1;
- end loop;
- end if;
- utl_file.fclose(handle);
- end sp_write_to_file;
這個(gè)存儲(chǔ)過(guò)程實(shí)現(xiàn)將字符串寫(xiě)到文件中的過(guò)程。注意varchar2最長(zhǎng)好像是32767吧!
以上就Oracle寫(xiě)文件編寫(xiě)的一個(gè)例子,要想了解的更多相關(guān)知識(shí),請(qǐng)留意51cto.com站上的相關(guān)帖子.。
【編輯推薦】