Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1182628
  • 博文数量: 398
  • 博客积分: 10110
  • 博客等级: 上将
  • 技术积分: 4055
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-23 20:01
个人简介

新博客http://www.cnblogs.com/zhjh256 欢迎访问

文章分类

全部博文(398)

文章存档

2012年(1)

2011年(41)

2010年(16)

2009年(98)

2008年(142)

2007年(100)

我的朋友

分类: Oracle

2007-12-23 21:59:14

create or replace directory exp_dir as 'e:\oracle';
/
create or replace procedure table2xml(result   in out nocopy clob,
                                         filename in varchar2) is
  xmlstr  varchar2(32767);
  line    varchar2(2000);
  fhandle utl_file.file_type;
begin
  fhandle := utl_file.fopen('EXP_DIR', filename, 'w');
  xmlstr  := dbms_lob.substr(result, 32767);
  loop
    exit when xmlstr is null;
    line := substr(xmlstr, 1, instr(xmlstr, chr(10)) - 1);
    dbms_output.put_line('| ' || line);
    utl_file.put_line(fhandle, line);
    xmlstr := substr(xmlstr, instr(xmlstr, chr(10)) + 1);
  end loop;
  utl_file.fclose(fhandle);
end;
/
declare
  queryctx dbms_xmlquery.ctxType;
  result   clob;
begin
  queryctx := dbms_xmlquery.newContext('select username from all_users where username<>''SYSTEM'' and username<>''SCOTT''');
  result   := dbms_xmlquery.getXML(queryctx);
  table2xml(result, 'table2xml.xml');
  dbms_xmlquery.closeContext(queryctx);
end;
阅读(900) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~