把表中数据导成TXT文件脚本

把表中数据导成TXT文件脚本.

Creating a ascii text file of oracle table data with pipe delimited columns.

Code:
#!/bin/ksh
#First line in the .txt file is column names
USR=username/password
echo "set feedback off\n set pagesize 0\n
select 'XXTT' || table_name from user_tables ;" | sqlplus -s $USR | grep '^XXTT' | cut -c5- |
while read TABL
do
STR="nothing"
STR1="nothing"
echo "desc $TABL\n" | sqlplus -s $USR | tail +3 | grep "^[A-Z,a-z]" | awk '{print $1}' |
while read COLUM
do
if [ "$STR" = "nothing" ] then
STR=$COLUM
STR1=$COLUM
else
STR="$STR || '|' || $COLUM"
STR1="$STR1|$COLUM"
fi
Done
echo "$STR1" > $TABL.txt
echo "set feedback off\nset pagesize 0\nset linesize 2000\nselect $STR from $TABL;"| sqlplus -s $USR >> $TABL.txt
Done

第二种方法:利用Oracle中spool

  新建一个sql脚本 d:\czrk.sql,代码如下:

  SET echo off

  SET feedback off

  SET newpage none

  SET pagesize 50000

  SET linesize 20000

  SET verify off

  SET pagesize 0

  SET term off

  SET trims ON

  SET heading off

  SET trimspool ON

  SET trimout ON

  SET timing off

  SET verify off

  SET colsep |

  spool d:\czrk.txt

  SELECT sfzh || ',' || xm || ',' || xb || ',' || csrq || ',' || mz|| ',' || xzqh|| ',' || jzdz FROM m_czrk WHERE rownum<=10000;

  spool off

  sqlplus连接上数据库,执行脚本 sqlplus dc/dc@mydb;

  sqlplus>@d:\czrk.sql

  这样就在d盘下生成了一万条数据了。


学习了,好好研究一下。

原文来自:

http://www.itpub.net/thread-75552-1-1.html

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/21835737/viewspace-711778/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/21835737/viewspace-711778/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值