Oracle-SHELL程式設計
MicrosoftInternetExplorer402DocumentNotSpecified7.8Normal0
This article presents some basic techniques for creating Windows batch files and UNIX/Linux shell scripts that connect to SQL*Plus and RMAN.
Windows
To run an SQL script using SQL*Plus, place the SQL along with any SQL*Plus commands in a file and save it on your operating system. For example, save the following script in a file called "C:\emp.sql".
CONNECT scott/tiger
SPOOL C:\emp.lst
SET LINESIZE 100
SET PAGESIZE 50
SELECT *
FROM emp;
SPOOL OFF
EXIT;
Next, create a batch file called "C:\get_emp.bat" containing the following command.
sqlplus /nolog @C:\emp.sql
The resulting batch file can be run manually, by double-clicking on it, or scheduled using the Scheduled Tasks Wizard (Start > Programs > Accessories > System Tools > Scheduled Tasks) or the AT scheduler.
The method is very similar when using Recovery Manager (RMAN). As an example, place the following RMAN commands in a file called "C:\cmdfile.txt".
RUN {
ALLOCATE CHANNEL ch1 TYPE
DISK FORMAT 'C:\oracle\backup\DB10G%d_DB_%u_%s_%p';
BACKUP DATABASE PLUS ARCHIVELOG;
RELEASE CHANNEL ch1;
}
EXIT;
Next create a batch file called "C:\backup.bat" containing the following command.
rman target=/ @cmdfile.txt
This command can include a catalog= entry if a recovery catalog is used. Once again, resulting batch file can be run manually or scheduled.
UNIX and Linux (Method 1)
The previous methods works equally well in UNIX and Linux environments. For example, save the following script in a file called "/u01/emp.sql".
CONNECT scott/tiger
SPOOL /u01/emp.lst
SET LINESIZE 100
SET PAGESIZE 50
SELECT *
FROM emp;
SPOOL OFF
EXIT;
Next, create a shell script called "/u01/get_emp.ksh" containing the following lines.
#!/bin/ksh
sqlplus /nolog @/u01/emp.sql
The following command makes the file executable for the file owner.
chmod u+x /u01/get_emp.ksh
The resulting shell script can be run manually from the command line, or scheduled using CRON.
For RMAN, place the following RMAN commands in a file called "/u01/cmdfile.txt".
RUN {
ALLOCATE CHANNEL ch1 TYPE
DISK FORMAT '/u01/backup/DB10G/%d_DB_%u_%s_%p';
BACKUP DATABASE PLUS ARCHIVELOG;
RELEASE CHANNEL ch1;
}
EXIT;
Next create a batch file called "/u01/backup.ksh" containing the following lines.
#!/bin/ksh
rman target=/ @/u01/cmdfile.txt
This command can include a catalog= entry if a recovery catalog is used. Once again, resulting shell script must be made executable using the following command.
chmod u+x /u01/backup.ksh
The shell script is now ready to run.
UNIX and Linux (Method 2)
UNIX and Linux environments also allow the SQL*Plus and RMAN commands to be piped directly from the command line. For example, save the following commands in a file called "/u01/get_emp.ksh".
#!/bin/ksh
sqlplus /nolog <
CONNECT scott/tiger
SPOOL /u01/emp.lst
SET LINESIZE 100
SET PAGESIZE 50
SELECT *
FROM emp;
SPOOL OFF
EXIT;
EOF
Notice the "<
chmod u+x /u01/get_emp.ksh
The shell script is ready to be run manually from the command line or scheduled using CRON.
The following example shows how RMAN can use the same method. Create a file called "/u01/backup.ksh" with the following contents.
#!/bin/ksh
rman target=/ <
RUN {
ALLOCATE CHANNEL ch1 TYPE
DISK FORMAT '/u01/backup/DB10G/%d_DB_%u_%s_%p';
BACKUP DATABASE PLUS ARCHIVELOG;
RELEASE CHANNEL ch1;
}
EXIT;
EOF
Once again, the script can be made executable using the following command.
chmod u+x /u01/backup.ksh
The shell script is now ready to run.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26194851/viewspace-723327/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Java 網路程式設計(TCP程式設計 和 UDP程式設計)Java程式設計TCPUDP
- 程式設計思想 面向切面程式設計程式設計
- 【go網路程式設計】-HTTP程式設計Go程式設計HTTP
- 程式語言設計,程式設計哲學程式設計
- 程式設計小記-程式設計規範程式設計
- 從程式設計到養生程式設計程式設計
- 程式設計模式-表驅動程式設計程式設計設計模式
- 程式設計師何苦為難程式設計師?程式設計師
- 【程式設計素質】程式設計思想總結程式設計
- 程式設計和網路程式設計入門程式設計
- 十、GO程式設計模式 : 泛型程式設計Go程式設計設計模式泛型
- JAVA網路程式設計(2)TCP程式設計Java程式設計TCP
- 美女程式設計師觀點:程式設計師最重要的非程式設計技巧程式設計師
- 玩轉 PHP 網路程式設計全套之多程式程式設計PHP程式設計
- 【1024程式設計師節】程式設計師,你學程式設計的初衷是什麼?程式設計師
- 程式設計思想之冪等性 | 程式設計之道程式設計
- Windows程式設計系列:圖形程式設計基礎Windows程式設計
- Java 網路程式設計 —— 非阻塞式程式設計Java程式設計
- 程式設計師如何獲取新程式設計技能程式設計師
- 幽默:程式設計師成功完成程式設計的眼睛程式設計師
- Python程式設計:探索有趣的程式碼設計模式Python程式設計設計模式
- Java程式設計師學習Rust程式設計 - infoworldJava程式設計師Rust
- 五種Java程式設計高效程式設計方法 - BablaJava程式設計
- 【網路程式設計】阻塞IO程式設計的坑程式設計
- 無程式碼程式設計程式設計
- [python] 多程式程式設計Python程式設計
- Python多程式程式設計Python程式設計
- windows核心程式設計--程式Windows程式設計
- 程式設計師程式設計入門一定知道!程式設計師需要學什麼?程式設計師
- python程式設計Python程式設計
- 程式設計心得程式設計
- SOCKET程式設計程式設計
- JUC 程式設計程式設計
- 程式設計路由程式設計路由
- 高效程式設計程式設計
- bat程式設計BAT程式設計
- Python 程式設計Python程式設計
- OraclePLSQL程式設計OracleSQL程式設計
- GUI程式設計GUI程式設計