打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
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.Xml
declare
       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;

本文出自:http://www.cnblogs.com/hoojo/archive/2011/05/03/2035427.html

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
如何在PL/SQL中读写文件
UTL
Oracle批量导出表数据到CSV文件
关于在Oracle中读写文件的操作
输出oracle 对象源码
oracle varchar2类型不能用 s='' 进行判断
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服