因此,实践中我建议大家使用方法二手工去控制spool文件的格式,这样可以减小出错的可能性,避免走很多弯路(为什么会这样呢,没有说明..)
后面还有LINUX的shell脚本写的导出,(LINUX战时没有深入,待学习..)
结合之前的HTML导出的方式,看下面一段代码导出比较公整的EXCEL文件:
conn SCOTT/TIGER@FZLGFM
set heading off
Set pagesize 0
Set term off
Set feedback off
set linesize 99999
set trimspool off
set term off verify off feedback off pagesize 99999
spool D:/b.xls
set markup html on entmap ON spool on preformat off
select '工号','姓名','薪水','部门号' from dual
union all
select to_char(sal), ename, to_char(sal), to_char(sal) from emp;
spool off
PS:注意,UNION ALL字段类型要匹配
select '工号','姓名','薪水','部门号' from dual
union all
select to_char(sal), ename, to_char(sal), to_char(sal) from emp;
以上是通过客户端实现的导出,再来看看服务器的导出的存储过程:
第一步:创建目录和赋权限
--*********************************************************************
--***
--***首先以dba或者是其他具有create directory的用户创建directory,然后授权
--***
--*********************************************************************
CREATE OR REPLACE DIRECTORY dir_export AS 'd:/oracle';
GRANT read,write ON directory dir_export TO scott;
第二步:建立导出存储过程:
--*********************************************************************
--***
--***执行导出文本文件的存储过程:p_exp
--***p_tname:要导出的表明;p_query:where条件,根据这个条件导出,如果为null,则全表导出
--***
--***
--*********************************************************************
create or replace procedure p_exp(p_tname varchar2)
as
v_line varchar2(2000); --记录的数据
v_sql varchar2(2000); --动态sql变量
v_fname varchar2(40); --导出数据的文件名字
cursor cursor_column --游标:通过数据字典查找出表有哪些字段
is select column_name,data_type
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-51831-2.html
必将稳步向前
魂牵梦萦
三大无才