server导出csv文件不去除0 sql_高分!SQL 2000中不通过程序,怎么导出csv文件,或把数据倒进到csv中...

SQL codehttp://blog.csdn.net/picture_1230/archive/2008/02/25/2118217.aspx PL/SQL can do it, it might look like:

create or replace function dump_csv( p_query in varchar2,

p_separator in varchar2

default ', ',

p_dir in varchar2 ,

p_filename in varchar2 )

return number

AUTHID CURRENT_USER

is

l_output utl_file.file_type;

l_theCursor integer default dbms_sql.open_cursor;

l_columnValue varchar2(2000);

l_status integer;

l_colCnt number default 0;

l_separator varchar2(10) default ' ';

l_cnt number default 0;

begin

l_output := utl_file.fopen( p_dir, p_filename, 'w ' );

dbms_sql.parse( l_theCursor, p_query, dbms_sql.native );

for i in 1 .. 255 loop

begin

dbms_sql.define_column( l_theCursor, i,

l_columnValue, 2000 );

l_colCnt := i;

exception

when others then

if ( sqlcode = -1007 ) then exit;

else

raise;

end if;

end;

end loop;

dbms_sql.define_column( l_theCursor, 1, l_columnValue,

2000 );

l_status := dbms_sql.execute(l_theCursor);

loop

exit when ( dbms_sql.fetch_rows(l_theCursor) <= 0 );

l_separator := ' ';

for i in 1 .. l_colCnt loop

dbms_sql.column_value( l_theCursor, i,

l_columnValue );

utl_file.put( l_output, l_separator ||

l_columnValue );

l_separator := p_separator;

end loop;

utl_file.new_line( l_output );

l_cnt := l_cnt+1;

end loop;

dbms_sql.close_cursor(l_theCursor);

utl_file.fclose( l_output );

return l_cnt;

end dump_csv;

/

You would use that for example like this:

create or replace procedure test_dump_csv

as

l_rows number;

begin

l_rows := dump_csv( 'select *

from all_users

where rownum < 25 ',

', ', '/tmp ', 'test.dat ' );

end;

/

Make sure to read about the INIT.ORA parameters (utl_file_dir) you need to setup

!!!

------解决方案--------------------

楼上这个可是ORACLE了。

其实SQL2005比较简单了。

导出数据之后

1.选择数据源,选择要导出的表

2.选择目标,平面文件源----浏览-----文件类型(选CSV文件),确定

3.下一步导出就可以了。

------解决方案--------------------探讨

楼上这个可是ORACLE了。

其实SQL2005比较简单了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值