#!/bin/sh

sqlplus "用户名/密码@数据库"<<EOF  或者只有一个库的 :sqlplus "用户名/密码"<<EOF

sqlplus "用户名/密码"<<EOF     显示连接详情,查询语句 ,查询结果;

sqlplus -S "用户名/密码" <<EOF  只显示sql语句查询结果;

sqlplus "用户名/密码"<<EOF>> xx.log  将信息增量添加到 xx.log 文件中;

#!/bin/sh
sqlplus -S "用户名/密码" <<EOF>> xss.log
set heading off
set feedback off
set pagesize 0
set verify off
set echo off
select username from all_users;
exit;
EOF

第一种:

#!/bin/sh
sqlplus "用户名/密码"<<EOF>> xx.log
select username from all_users;
exit;
EOF

上诉语句产生一个xx.log 文件,文件内容如下:内容详尽

SQL*Plus: Release 11.2.0.1.0 Production on Fri Dec 19 14:46:43 2014

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> USERNAME ------------------------------

SCOTT

OWBSYS_AUDIT

OWBSYS

APEX_030200

APEX_PUBLIC_USER

FLOWS_FILES

MGMT_VIEW

SYSMAN

SPATIAL_CSW_ADMIN_USR

SPATIAL_WFS_ADMIN_USR

MDDATA

USERNAME ------------------------------

MDSYS

SI_INFORMTN_SCHEMA

ORDPLUGINS

ORDDATA

ORDSYS

OLAPSYS

ANONYMOUS

XDB

CTXSYS

EXFSYS

XS$NULL

USERNAME ------------------------------

WMSYS

APPQOSSYS

DBSNMP

ORACLE_OCM

DIP

OUTLN

SYSTEM

SYS

30 rows selected.

SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options

第二种:

#!/bin/sh
sqlplus -S "用户名/密码" <<EOF
set heading off
set feedback off
set pagesize 0
set verify off
set echo off
spool spool_file
select username from all_users;
spool off
exit;
EOF

上诉语句产生一个spool_file.lst文件,文件内容如下:文件只显示sql语句的查询结果

SCOTT                                                                          
OWBSYS_AUDIT                                                                   
OWBSYS                                                                         
APEX_030200                                                                    
APEX_PUBLIC_USER                                                               
FLOWS_FILES                                                                    
MGMT_VIEW                                                                      
SYSMAN                                                                         
SPATIAL_CSW_ADMIN_USR                                                          
SPATIAL_WFS_ADMIN_USR                                                          
MDDATA                                                                         
MDSYS                                                                          
SI_INFORMTN_SCHEMA                                                             
ORDPLUGINS                                                                     
ORDDATA                                                                        
ORDSYS                                                                         
OLAPSYS                                                                        
ANONYMOUS                                                                      
XDB                                                                            
CTXSYS                                                                         
EXFSYS                                                                         
XS$NULL                                                                        
WMSYS                                                                          
APPQOSSYS                                                                      
DBSNMP                                                                         
ORACLE_OCM                                                                     
DIP                                                                            
OUTLN                                                                          
SYSTEM                                                                         
SYS

上诉语句去掉 -S  输出到文件上的内容会增加2行,如下:

SQL> select username from all_users;
SCOTT                                                                          
OWBSYS_AUDIT                                                                   
OWBSYS                                                                         
APEX_030200                                                                    
APEX_PUBLIC_USER                                                               
FLOWS_FILES                                                                    
MGMT_VIEW                                                                      
SYSMAN                                                                         
SPATIAL_CSW_ADMIN_USR                                                          
SPATIAL_WFS_ADMIN_USR                                                          
MDDATA                                                                         
MDSYS                                                                          
SI_INFORMTN_SCHEMA                                                             
ORDPLUGINS                                                                     
ORDDATA                                                                        
ORDSYS                                                                         
OLAPSYS                                                                        
ANONYMOUS                                                                      
XDB                                                                            
CTXSYS                                                                         
EXFSYS                                                                         
XS$NULL                                                                        
WMSYS                                                                          
APPQOSSYS                                                                      
DBSNMP                                                                         
ORACLE_OCM                                                                     
DIP                                                                            
OUTLN                                                                          
SYSTEM                                                                         
SYS                                                                            
SQL> spool off

#!/bin/sh
sqlplus  "用户名/密码" <<EOF>> x.log
set heading off
set feedback off
set pagesize 0
set verify off
set echo off
spool spool_file
select username from all_users;
spool off
exit;
EOF

上诉语句会产生一个x.log文件 一个spool_file.lst文件,多次运行会增量添加到x.log文件中,会重新生成spool_file.lst文件

x.log文件内容如下:

SQL*Plus: Release 11.2.0.1.0 Production on Fri Dec 19 15:01:33 2014

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> SQL> SQL> SQL> SQL> SQL> SQL> SCOTT OWBSYS_AUDIT OWBSYS APEX_030200 APEX_PUBLIC_USER FLOWS_FILES MGMT_VIEW SYSMAN SPATIAL_CSW_ADMIN_USR SPATIAL_WFS_ADMIN_USR MDDATA MDSYS SI_INFORMTN_SCHEMA ORDPLUGINS ORDDATA ORDSYS OLAPSYS ANONYMOUS XDB CTXSYS EXFSYS XS$NULL WMSYS APPQOSSYS DBSNMP ORACLE_OCM DIP OUTLN SYSTEM SYS SQL> SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options

spool_file.lst文件内容如下:

SQL> select username from all_users;
SCOTT                                                                          
OWBSYS_AUDIT                                                                   
OWBSYS                                                                         
APEX_030200                                                                    
APEX_PUBLIC_USER                                                               
FLOWS_FILES                                                                    
MGMT_VIEW                                                                      
SYSMAN                                                                         
SPATIAL_CSW_ADMIN_USR                                                          
SPATIAL_WFS_ADMIN_USR                                                          
MDDATA                                                                         
MDSYS                                                                          
SI_INFORMTN_SCHEMA                                                             
ORDPLUGINS                                                                     
ORDDATA                                                                        
ORDSYS                                                                         
OLAPSYS                                                                        
ANONYMOUS                                                                      
XDB                                                                            
CTXSYS                                                                         
EXFSYS                                                                         
XS$NULL                                                                        
WMSYS                                                                          
APPQOSSYS                                                                      
DBSNMP                                                                         
ORACLE_OCM                                                                     
DIP                                                                            
OUTLN                                                                          
SYSTEM                                                                         
SYS                                                                            
SQL> spool off

linux shell脚本连接oracle查询数据插入文件和日志文件中的更多相关文章

  1. shell脚本实现自动压缩一天前的日志文件 ,并传到ftp服务器上

    shell脚本实现自动压缩一天前的日志文件 ,并传到ftp服务器上 naonao_127关注2人评论19401人阅读2012-06-08 11:26:16         生产环境下脚本自动备份脚本是 ...

  2. linux shell 脚本攻略学习10--生成任意大小的文件和文本文件的交集与差集详解

    一.生成任意大小的文件(dd命令): 举例: amosli@amosli-pc:~/learn/example$ ; + records in + records out bytes ( MB/s a ...

  3. SSH Secure Shell Client连接Linux 命令行显示中文乱码问题 和oracle 查询数据中文乱码问题

    一.SSH Secure Shell Client连接Linux 命令行显示中文乱码问题 linux 设置系统语言 修改 /etc/sysconfig/i18n 文件,如 LANG="en_ ...

  4. 学习Linux shell脚本中连接字符串的方法

    这篇文章主要介绍了Linux shell脚本中连接字符串的方法,如果想要在变量后面添加一个字符,可以用一下方法: 代码如下: $value1=home $value2=${value1}"= ...

  5. LINUX SHELL脚本攻略笔记[速查]

    Linux Shell脚本攻略笔记[速查] 资源 shell script run shell script echo printf 环境变量和变量 pgrep shell数学运算 命令状态 文件描述 ...

  6. Linux Shell脚本入门--wget 命令用法详解

    Linux Shell脚本入门--wget 命令用法详解 wget是在Linux下开发的开放源代码的软件,作者是Hrvoje Niksic,后来被移植到包括Windows在内的各个平台上.它有以下功能 ...

  7. linux shell 脚本攻略学习20--awk命令入门详解

    awk生于1977年,创始人有三个,分别为 Alfred Aho,Peter Weinberger, 和 Brian Kernighan,名称源于三个创始人的姓的首字母. 作用:处理文本文件. awk ...

  8. Linux shell脚本编程(一)

    Linux shell脚本编程: 守护进程,服务进程:启动?开机时自动启动: 交互式进程:shell应用程序 广义:GUI,CLI GUI: CLI: 词法分析:命令,选项,参数 内建命令: 外部命令 ...

  9. 阿里Linux Shell脚本面试25个经典问答

    转载: 阿里Linux Shell脚本面试25个经典问答 Q:1 Shell脚本是什么.它是必需的吗? 答:一个Shell脚本是一个文本文件,包含一个或多个命令.作为系统管理员,我们经常需要使用多个命 ...

随机推荐

  1. Heroku 部署时 time out 错误,对GFW无力吐槽!!!

    整理自:http://ruby-china.org/topics/10813 部署到Heroku时输入 git push heroku master. 然后就开始漫长的等待了,最终报错: ssh: c ...

  2. 15--Box2D使用(一、创建物理世界)

    创建工程Box2DTest,去掉背景和精灵对象等.首先在HelloWorldScene.h头文件定义一个屏幕像素与物理世界长度转换宏,并引入box2D头文件 #define PIXEL_TO_METE ...

  3. Ajax调用返回json,xml数据类型(0517--pm)

    一.返回Json型数据: 1.主页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ...

  4. [python]百度语音rest api

    百度语音识别提供的api范例只有java, c, php. 如果使用Python, 需要注意: 语音文件长度是指bytes大小 可以通过len(file.read())获得 使用requests.po ...

  5. Activiti工作流学习-----基于5.19.0版本(7)

    八.BPMN 2.0流程图详解 BPMN 2.0的标准的出现是好事,用户不在被某个工作流开发商绑架或者在工作流中开发妥协,Activiti作为BPMN标准的一套解决方案,使得用户在选择工作流框架时可以 ...

  6. Swift学习之常用UI的使用

    Swift学习之常用UI的使用 最近笔者在开始学习苹果最新的编程语言,因为笔者认为,苹果既然出了这门语言就绝对不会放弃,除非苹果倒闭了(当然这里知识一个玩笑). 所以在不久的将来,swift绝对是iO ...

  7. 从点击Button到弹出一个MessageBox, 背后发生了什么(每个UI线程都有一个ThreadInfo结构, 里面包含4个队列和一些标志位)

    思考一个最简单的程序行为:我们的Dialog上有一个Button, 当用户用鼠标点击这个Button时, 我们弹出一个MessageBox.   这个看似简单的行为, 谁能说清楚它是如何运行起来的,背 ...

  8. Use OWIN to Self-Host ASP.NET Web API 2

      Open Web Interface for .NET (OWIN)在Web服务器和Web应用程序之间建立一个抽象层.OWIN将网页应用程序从网页服务器分离出来,然后将应用程序托管于OWIN的程序 ...

  9. STL 查找vector容器中的指定对象:find()与find_if()算法

    1 从vector容器中查找指定对象:find()算法 STL的通用算法find()和find_if()可以查找指定对象,参数1,即首iterator指着开始的位置,参数2,即次iterator指着停 ...

  10. CoreData Multiple Context性能分析-读书笔记

    From: http://floriankugler.com/blog/2013/4/29/concurrent-core-data-stack-performance-shootout  http: ...