问题: 1、shell 连接数据库操作
dbtools.sh 数据库名 用户名 密码 操作语句 输出文件 操作日志
例: dbtools.sh "CHNDB1" "dbchnadm" "dbpwd" "select rownum as rn from dual connect by rownum<=3" "myfile.txt" "mydb.log"
作用:连接数据库执行语句,执行结果生成文件myfile.txt
myfile.txt 文件内容:
1
2
3
----------源码--------------
#!/bin/sh
username=$1
pwd=$2
database=$3
sql=$4
outputfile=$5
sqlplus
mydb.log
-----------运行界面--------------------
HHL-690-2:chnapp:/chnapp/liujqc/study>dbtools.sh "dbrwdadm" "dbrwdadm" "crmkfdb" "desc dagentpayhisopr" "myfile.txt">mydb.log
-----------查看mydb.log----------------
HHL-690-2:chnapp:/chnapp/liujqc/study/database>cat mydb.log
--------------内容---------------------------
SQL*Plus: Release 10.2.0.4.0 - Production on Tue Dec 13 10:53:45 2011
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> SQL> Name Null? Type
----------------------------------------- -------- ----------------------------
AGENT_PHONE_NO CHAR(15)
PAY_MONEY NUMBER(14,2)
PHONE_NO CHAR(15)
OP_TIME DATE
GROUP_ID VARCHAR2(10)
LOGIN_ACCEPT NUMBER(14)
SQL> SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
--------------查看myfile.txt--------------------
HHL-690-2:chnapp:/chnapp/liujqc/study/database>cat myfile.txt
--------------------内容----------------------
SQL> desc dagentpayhisopr
Name Null? Type
----------------------------------------- -------- ----------------------------
AGENT_PHONE_NO CHAR(15)
PAY_MONEY NUMBER(14,2)
PHONE_NO CHAR(15)
OP_TIME DATE
GROUP_ID VARCHAR2(10)
LOGIN_ACCEPT NUMBER(14)
SQL> spool off
阅读(7062) | 评论(0) | 转发(0) |