Chinaunix首页 | 论坛 | 博客
  • 博客访问: 57951
  • 博文数量: 13
  • 博客积分: 318
  • 博客等级: 二等列兵
  • 技术积分: 185
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-01 19:17
文章分类

全部博文(13)

文章存档

2012年(13)

我的朋友

分类: LINUX

2012-04-26 22:39:36

问题: 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) |
0

上一篇:oracle 性能监控

下一篇:Shell FTP 文件

给主人留下些什么吧!~~