linux下通過sql檔案批量操作指令碼樣本
大部分真實生產環境中的伺服器都是linux,oracle DBA工作過程中有時會遇到通過shell指令碼批量執行sql指令碼完成某一項任務,最典型的例子是oracle DBCA建立的資料庫指令碼就是這種模式,適宜環境下稍加修改便可完全通過指令碼完成新庫的安裝,小編在這裡將簡單兩種應用樣例列舉如下,方便以後工作.
---------------------------------------shell檔案和sql檔案組合樣例---------------------------------------------
---------linux中的執行shell檔案中包含了sql內容:
[oracle@CentOS5 ~]$ cat spool.sh
#!/bin/sh
OLD_UMASK=`umask`
umask 0027
umask ${OLD_UMASK}
ORACLE_SID=taxi; export ORACLE_SID
PATH=$ORACLE_HOME/bin:$PATH; export PATH
/oracle/product/10.2.0/db_1/bin/sqlplus / as sysdba <
set linesize 120
set pagesize 100
spool /home/oracle/spool.txt
select * from scott.dept;
spool off
exit;
EOF
[oracle@CentOS5 ~]$
------->>執行情況:
[oracle@CentOS5 ~]$ sh spool.sh
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Oct 23 17:43:00 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> SQL> SQL> SQL>
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
---------------------------------------shell檔案和sql檔案分開樣例---------------------------------------------
---------linux中的執行shell檔案內容:
[oracle@CentOS5 ~]$ cat test.sh
#!/bin/sh
OLD_UMASK=`umask`
umask 0027
umask ${OLD_UMASK}
ORACLE_SID=taxi; export ORACLE_SID
PATH=$ORACLE_HOME/bin:$PATH; export PATH
/oracle/product/10.2.0/db_1/bin/sqlplus / as sysdba @/home/oracle/test.sql
[oracle@CentOS5 ~]$
---------sql檔案中內容:
[oracle@CentOS5 ~]$ cat test.sql
set linesize 120
set pagesize 120
spool /home/oracle/test.txt
select * from scott.emp;
spool off;
exit;
--------->>執行情況:
[oracle@CentOS5 ~]$ sh test.sh
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Oct 23 17:43:06 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected.
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@CentOS5 ~]$
DBCA建立新庫指令碼追蹤學習案例請參見我的另外一篇博文:http://blog.itpub.net/29119536/viewspace-1300706/
---------------------------------------shell檔案和sql檔案組合樣例---------------------------------------------
---------linux中的執行shell檔案中包含了sql內容:
[oracle@CentOS5 ~]$ cat spool.sh
#!/bin/sh
OLD_UMASK=`umask`
umask 0027
umask ${OLD_UMASK}
ORACLE_SID=taxi; export ORACLE_SID
PATH=$ORACLE_HOME/bin:$PATH; export PATH
/oracle/product/10.2.0/db_1/bin/sqlplus / as sysdba <
set pagesize 100
spool /home/oracle/spool.txt
select * from scott.dept;
spool off
exit;
EOF
[oracle@CentOS5 ~]$
------->>執行情況:
[oracle@CentOS5 ~]$ sh spool.sh
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Oct 23 17:43:00 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> SQL> SQL> SQL>
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
---------------------------------------shell檔案和sql檔案分開樣例---------------------------------------------
---------linux中的執行shell檔案內容:
[oracle@CentOS5 ~]$ cat test.sh
#!/bin/sh
OLD_UMASK=`umask`
umask 0027
umask ${OLD_UMASK}
ORACLE_SID=taxi; export ORACLE_SID
PATH=$ORACLE_HOME/bin:$PATH; export PATH
/oracle/product/10.2.0/db_1/bin/sqlplus / as sysdba @/home/oracle/test.sql
[oracle@CentOS5 ~]$
---------sql檔案中內容:
[oracle@CentOS5 ~]$ cat test.sql
set linesize 120
set pagesize 120
spool /home/oracle/test.txt
select * from scott.emp;
spool off;
exit;
--------->>執行情況:
[oracle@CentOS5 ~]$ sh test.sh
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Oct 23 17:43:06 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected.
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@CentOS5 ~]$
DBCA建立新庫指令碼追蹤學習案例請參見我的另外一篇博文:http://blog.itpub.net/29119536/viewspace-1300706/
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29119536/viewspace-1308290/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 通過shell指令碼批量操作mysql資料庫指令碼MySql資料庫
- hadoop_批量命令指令碼&同步檔案指令碼Hadoop指令碼
- 通過shell指令碼 批量新增使用者指令碼
- [ Shell ] 通過 Shell 指令碼匯出 GDSII/OASIS 檔案指令碼
- IDA批量處理VirusShare樣本獲得asm檔案與bytes檔案ASM
- CMD 執行大檔案SQL指令碼SQL指令碼
- Linux下批量ping某個網段ip的指令碼Linux指令碼
- Linux批量刪除檔案Linux
- PowerDesigner: 利用sql指令碼檔案逆生成模型SQL指令碼模型
- 批量修改檔名的bash指令碼指令碼
- ExcelWeb指令碼助手,自定義指令碼,批量操作Excel與網頁ExcelWeb指令碼網頁
- SpringBoot(18)---通過Lua指令碼批量插入資料到Redis布隆過濾器Spring Boot指令碼Redis過濾器
- 前端通過 post 下載檔案前端
- Linux下使用Ansible處理批量操作Linux
- linux 模糊批量刪除檔案Linux
- linux shell 命令下批量新增檔案的字尾 和批量刪除 擁有某字尾的檔案Linux
- linux 檔案操作Linux
- Windows環境下實現批量執行Sql檔案勒鴛WindowsSQL
- linux 查詢某個日期以後修改過哪些檔案 shell指令碼Linux指令碼
- linux下通過原始碼安裝gitLinux原始碼Git
- Linux 批量修改檔案字尾名Linux
- 如何在 Linux下進行檔案切割操作?Linux
- 檔案操作(下)
- Linux檔案IO操作Linux
- Linux通過Shell指令碼命令修改密碼不需要互動Linux指令碼密碼
- 如何用 Python 指令碼批量下載 Google 影象?Python指令碼Go
- Linux----12 檔案與檔案操作Linux
- Linux指令入門-檔案管理Linux
- Linux下日誌檔案過大解決方案Linux
- sqoop指令碼批量生成OOP指令碼
- Linux常用檔案操作命令Linux
- Bash從GoogleDrive下載大檔案時繞過病毒驗證頁面的指令碼Go指令碼
- Linux批量刪除同一型別檔案Linux型別
- Linux批量刪除指定型別的檔案Linux型別
- Linux系統配置檔案簡易shell備份指令碼Linux指令碼
- php百萬資料透過指令碼檔案寫入csvPHP指令碼
- Flutter 下載檔案操作Flutter
- 如何批量複製多個檔案到多個目錄中(批量複製檔案,多對多檔案高效操作的方法)
- Linux學習之檔案操作Linux