网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > 数据库 > Oracle教程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
数据库:数据库教程,数据库技巧,Oracle教程,MySQL教程,Sybase教程,Access教程,DB2教程,数据库安全,数据库文摘
本月文章推荐
.一个oracle调优的好玩经历.
.什么是 Linux.
.100个ORACLE相关的网址大全.
.Oracle 10G数据库的特性简介(收藏.
.在Windows上命令行如何手工起停O.
.ORA-25153: 临时表空间为空.
.Oracle的自动数据库诊断监控程序.
.名字中包含了什么?:改善的表空.
.如何在sqlserver2000中实现oracl.
.详细介绍ORACLE sqlplus命令.
.Oracle9i初始化参数中文说明14.
.如何掌握 Oracle 中的时间间隔型.
.ORACLE常用Script.
.建立实验数据库模型.
.在字符集移值之前使用CSSCAN工具.
.Oracle数据库.
.ORACLE在HP-UX下的系列问题处理(.
.ORACLE 10.1.0.2 FOR LINUX86 .
.oracle 转换函数的使用.
.Oracle9i初始化参数中文说明(16).

将数据导出成为文本格式的备份的shell脚本

发表日期:2008-2-9



#将数据库中表的内容导出成为一个文本格式的shell脚本
#有两种使用方法(假设这个脚本的名字叫做unload):
# 1.将一个用户中所有的数据库表的内容到出来:
             unload userid/passwd[@connection]
# 2.只导出一个表的内容:
#            unload userid/passwd[@connection]  table_name
#这里要感谢you的帖子,是他让我学会了如何设置sqlplus环境,从而
#将数据库数据分解出来。
#
#我还想写出一个根据数据库中的数据字典的内容自动生成ctl文件的脚本,
#以便于将文本的数据库内容使用sqlldr导入到数据库中
#请各位提示我可能要涉及的数据字典是哪些 :)
#             

sep=','   # --分隔符,可以修改成自己想要的分隔符,如''
load_table( ){
rm -f table1.txt
echo " set colsep $sep;
set echo off;
set feedback off;
set heading off;
set pagesize 0;
set linesize 1000;
set numwidth 12;
set termout off;
set trimout on;
set trimspool on;
spool table1.txt;
select table_name from user_tables;
spool off;
"   sqlplus $userid   >/dev/null
if [ "$?" -ne 0 ] ; then
echo  sqlplus $userid error in get table name <"$?">!!
echo please check userid and passwd or database.
exit 
fi

if [[ -f table1.txt ]]
then
cat table1.txt  grep -v "^SQL>"  tr -d ' ' >table.txt
rm -f table1.txt
tables=`cat table.txt`
rm table.txt
else
echo "get table name error"
exit
fi
}

if [ "X$1" = "X" ]; then
echo "Usage: $0 <userid/passwd@connection> <table_name>"
exit
echo \c "Userid:"
read userid1
echo \c "Passwd:"
echo off
read passwd
userid=$userid1$passwd
echo on
else
userid=$1
fi

if [ "X$2" = "X" ]; then 
load_table;
if [[ "X$tables" = "X" ]];then
echo "no table in user $userid"
exit
fi
else 
tables=$2
fi

for table in $tables
do
rm -f wk_$table.txt
echo " set colsep $sep;
set echo off;
set feedback off;

set heading off;
set pagesize 0;
set linesize 1000;
set numwidth 12;
set termout off;
set trimout on;
set trimspool on;
spool wk_$table.txt; 
select * from $table; 
spool off; 
"   sqlplus $userid  >/dev/null
if [ "$?" -ne 0 ] ; then
echo  error:sqlplus $userid error in unload table $table!!
echo please check userid and passwd or database.
exit 
fi

if [[ -f wk_$table.txt ]]
then
cat wk_$table.txt  grep -v "^SQL>" >$table.txt
sed -e "s/ *$//g" $table.txt >wk_$table.txt
mv  wk_$table.txt $table.txt
if [[ `grep "ORA-" $table.txt`  = "" ]]; then
echo "unload table $table....\t\t\t\t\t\t ok"
else 
cat $table.txt
err="$err $table"
fi

else 
echo $0 error
fi
done
if [[  "X$err" = "X" ]];then
echo unload complete!
else
echo "unload table $err error, please check it!"
fi
上一篇:ODBC API常用函数诠释 人气:970
下一篇:Oracle9iR2在ReahatAS3上的升级导致exp不正常的问题 人气:590
浏览全部Oracle教程的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐