Oracle笔记 十四、查询XML操作、操作系统文件
生活随笔
收集整理的這篇文章主要介紹了
Oracle笔记 十四、查询XML操作、操作系统文件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
--1.隨機數select dbms_random.value from dual;select mod(dbms_random.random, 10) from dual;--0-9隨機數select abs(mod(dbms_random.random, 10)) from dual;--40-49隨機數select 40 + abs(mod(dbms_random.random, 10)) from dual;?--2.Xmldeclare words clob; xmlStr varchar2(32767); line varchar2(2000); line_no number := 1;begin words := dbms_xmlquery.getXML('select * from scott.emp'); xmlStr := dbms_lob.substr(words, 32767); loop exit when (xmlStr is null); line := substr(xmlStr, 1, instr(xmlStr, chr(10)) - 1); dbms_output.put_line(line_no || ':' || line); xmlStr := substr(xmlStr, instr(xmlStr, chr(10)) + 1); line_no := line_no + 1; end loop;end;?--3.文件--定義文件夾 命名必須大寫create directory MY_DIR as 'D:\TEMP';--讀文件declare inputfile UTL_FILE.file_type; --文件對象 input varchar2(2000);begin --指定文件 --3個參數依次為:文件夾 文件 打開方式[r(讀) w(寫) a(追加)] inputfile := UTL_FILE.fopen('MY_DIR', 'demo.txt', 'r'); loop UTL_FILE.get_line(inputfile, input); dbms_output.put_line(input); end loop; --關閉文件 UTL_FILE.fclose(inputfile); exception when no_data_found then dbms_output.put_line('文件末尾!');end;?--寫文件declare inputfile UTL_FILE.file_type; --文件對象 input varchar2(2000) := 'Hello World!';begin --指定文件 --3個參數依次為:文件夾 文件 打開方式[r(讀) w(寫) a(追加)] inputfile := UTL_FILE.fopen('MY_DIR', 'mydemo.txt', 'a'); --寫入數據 UTL_FILE.put_line(inputfile, input); --關閉文件 UTL_FILE.fclose(inputfile); exception when no_data_found then dbms_output.put_line('文件末尾!');end;
轉載于:https://www.cnblogs.com/hoojo/archive/2011/05/03/2035427.html
總結
以上是生活随笔為你收集整理的Oracle笔记 十四、查询XML操作、操作系统文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 这是优雅还是变态?
- 下一篇: DiscuzToolkit