- 论坛徽章:
- 0
|
如何将Oracle中表的数据转换成一个文本文件
楼上的风云兄说的不错,方式很多。
不知你是在什么操作系统下。unix or win.?
下面我写的几句粗浅的shell可以解决unix下的问题。
#!/bin/ksh
###################################################################
## 名称:unloadtable##
## 功能:本shell用于将数据库表导入.dat数据文件中,以备loadtable用.##
##.dat文件各个字段值用分隔符'|'分开。##
## 编者:LJX ##
## 日期: 2003.01.18 ##
###################################################################
if [ $# -ne 1 ]
then
echo "usage:unloadtable tablename."
exit 0
fi
##准备工作
echo "set heading off " >;/tmp/$1.col
echo "set pagesize 10000" >;>;/tmp/$1.col
echo "set linesize 800 " >;>;/tmp/$1.col
echo "set feedback off " >;>;/tmp/$1.col
echo "set tab off " >;>;/tmp/$1.col
echo "select column_name||',' from user_tab_columns where lower(table_name)='$1'; " >;>; /tmp/$1.col
##产生select语句
echo "set heading off " >;/tmp/$1.sel
echo "set pagesize 10000" >;>;/tmp/$1.sel
echo "set linesize 800 " >;>;/tmp/$1.sel
echo "set feedback off " >;>;/tmp/$1.sel
echo "set tab off " >;>;/tmp/$1.sel
echo "select " >;>;/tmp/$1.sel
echo `sqlplus -s sc/sc < /tmp/$1.col` |sed "s/,/||'|'||/g" |sed "s/||$//g" >;>;/tmp/$1.sel
##生成dat文件
echo "from $1;" >;>;/tmp/$1.sel
sqlplus -s sc/sc < /tmp/$1.sel >;$1.dat |
|