导出.bat sqlplus prize/prize@orcl1 @d:\aa.sqlaa.sql set trimspool on set linesize 120 set pagesize 2000 set newpage 1 set heading off set term off set num 18 set feedback off spool d:\test.txt select (case when length('0000' || to_char(9001 + rownum)) > 8 then substr('0000' || to_char(9001 + rownum), 2) else '0000' || to_char(9001 + rownum) end) 人员编码, p_name 人员姓名, p_code 工号, '20090801' 开始日期 from ps_person t, ps_dpt p, person_newfields s where t.dpt_id = p.dpt_id and t.p_personid = s.fields_id(+) and p_personid like '%10900%' and p_isout = 'F' AND p_isable = 'T' and t.p_name is not null order by to_number(substr(p.dpt_id, 7)) asc, rownum asc; spool OFF eof 用这种方法,本来是一行的数据,现在不在一行,而且一行里的两列的数据又没办法在excel里显示成2列,只能在一个列里显示
楼主可以用 col来设置显示的列的长度. 比如col 人员编码 for a4 col 人员姓名 for a10 等等可以确保所有的数据在一行.如果按照1楼所说,把结果按照,分割开来, select (case when length('0000' || to_char(9001 + rownum)) > 8 then substr('0000' || to_char(9001 + rownum), 2) else '0000' || to_char(9001 + rownum) end) 人员编码||','|| p_name 人员姓名||','|| p_code 工号||','|| '20090801' 开始日期 执行的结果,删除掉其他无效的行之后,保存为cvs格式. 然后用文本编辑器把"替换为空格,保存之后,再打开就可以正常显示了.
sqlplus prize/prize@orcl1 @d:\aa.sqlaa.sql
set trimspool on
set linesize 120
set pagesize 2000
set newpage 1
set heading off
set term off
set num 18
set feedback off
spool d:\test.txt
select (case
when length('0000' || to_char(9001 + rownum)) > 8 then
substr('0000' || to_char(9001 + rownum), 2)
else
'0000' || to_char(9001 + rownum)
end) 人员编码,
p_name 人员姓名,
p_code 工号,
'20090801' 开始日期
from ps_person t, ps_dpt p, person_newfields s
where t.dpt_id = p.dpt_id
and t.p_personid = s.fields_id(+)
and p_personid like '%10900%'
and p_isout = 'F'
AND p_isable = 'T'
and t.p_name is not null
order by to_number(substr(p.dpt_id, 7)) asc, rownum asc;
spool OFF
eof
用这种方法,本来是一行的数据,现在不在一行,而且一行里的两列的数据又没办法在excel里显示成2列,只能在一个列里显示
col来设置显示的列的长度.
比如col 人员编码 for a4
col 人员姓名 for a10
等等可以确保所有的数据在一行.如果按照1楼所说,把结果按照,分割开来,
select (case
when length('0000' || to_char(9001 + rownum)) > 8 then
substr('0000' || to_char(9001 + rownum), 2)
else
'0000' || to_char(9001 + rownum)
end) 人员编码||','||
p_name 人员姓名||','||
p_code 工号||','||
'20090801' 开始日期 执行的结果,删除掉其他无效的行之后,保存为cvs格式.
然后用文本编辑器把"替换为空格,保存之后,再打开就可以正常显示了.
SQL>set colsep ','; ---输出分隔符为, 这样result可以直接用execl打开,然后再用execl另存为xls文件就可以叻。
好像用excel还是打不开想要的格式。
这里不是直接打开,要直接打开,把文件名改成.csv, 打开后,save as成excel的格式就行。
把文件名改成.csv, 打开后,还需要用文本编辑器打开,将"替换成空格,才行的,我试过了。