(To) shell circumstances call sqlplus example

First, in the simplest shell call sqlplus.

$ Vi test1.sh

#! / bin / bash
sqlplus-S / nolog> result.log <set heading off feedback off pagesize 0 verify off echo off
conn u_test / iamwangnc
select * from tab;
exit
EOF

$ Chmod + x test1.sh
$ ./test1.sh

Second, the results of the implementation of sqlplus method passed to a shell

Note the use of the boss key sqlplus `paragraph, and given the variable on both sides of the equal sign can not have spaces.

$ Vi test2.sh

#! / bin / bash
VALUE = `sqlplus-S / nolog <set heading off feedback off pagesize 0 verify off echo off numwidth 4
conn u_test / iamwangnc
select count (*) from tab;
exit
EOF `
if [ "$ VALUE"-gt 0]; then
echo "The number of rows is $ VALUE."
exit 0
else
echo "There is no row in the table."
fi

$ Chmod + x test2.sh
$ ./test2.sh

Third, the results of the implementation of sqlplus method passed to the shell 2

Note the use of sqlplus paragraph col .. new_value .. the definition of the variables and parameters with exit, and then automatically assigned to the shell's $?

$ Vi test3.sh

#! / bin / bash
sqlplus-S / nolog> result.log <set heading off feedback off pagesize 0 verify off echo off numwidth 4
conn u_test / iamwangnc
col coun new_value v_coun
select count (*) coun from tab;
exit v_coun
EOF
VALUE ="$?"
echo "The number of rows is $ VALUE."

$ Chmod + x test3.sh
$ ./test3.sh

Fourth, the parameters passed to the shell procedure sqlplus

$ 1, said first parameter, sqlplus can be used directly, given the variable on both sides of the equal sign must be no space there can be no space.

$ Vi test4.sh

#! / bin / bash
NAME = "$ 1"
sqlplus-S u_test / iamwangnc <select * from tab where tname = upper ( '$ NAME');
exit
EOF

$ Chmod + x test4.sh
$ ./test4.sh Ttt

Five, in order to implement the safety requirements of each shell are hand-enter the password

$ Vi test5.sh

#! / bin / bash
echo-n "Enter password for u_test:"
read PASSWD
sqlplus-S / nolog <conn u_test / $ PASSWD
select * from tab;
exit
EOF

$ Chmod + x test5.sh
$ ./test5.sh

Six, in order to read from the document password security

Set permissions on the password file, only the user can read and write their own.

$ Echo 'iamwangnc'> u_test.txt
$ Chmod g-rwx, o-rwx u_test.txt
$ Vi test6.sh

#! / bin / bash
PASSWD = `cat u_test.txt`
sqlplus-S / nolog <conn u_test / $ PASSWD
select * from tab;
exit
EOF

$ Chmod + x test6.sh
$ ./test6.sh

- End --

Original Address http://hi.baidu.com/edeed/blog/item/291698228a5694f4d7cae2c1.html
Article Source: DIY tribe (http://www.diybl.com/course/3_program/shell/shelljs/20090211/155236.html)

Test the contents of their own:

#! / bin / sh
PATH = $ PATH: $ HOME / bin
export PATH
export ORACLE_SID = oravm
export ORACLE_BASE = / opt / oracle
export ORACLE_HOME = / opt/oracle/9.2.0
export LD_LIBRARY_PATH = / opt/oracle/9.2.0/lib: / lib: / usr / lib: / usr / local / lib: / usr/X11R6/lib
export TNS_ADMIN = / opt/oracle/9.2.0/network/admin
export ORA_NLS33 = / opt/oracle/9.2.0/ocommon/nls/admin/data
export ORACLE_OWNER = oracle
export ORACLE_TERM = xterm
export PATH = / usr / kerberos / sbin: / usr / kerberos / bin: / usr / local / sbin: / usr / local / bin: / sbin: / bin: / usr / sbin: / usr / bin: / root / bin: / opt/oracle/9.2.0/bin
export LANG = zh_CN.gb2312
export NLS_LANG = "Simplified Chinese_china". ZHS16GBK
export NLS_DATE_FORMAT = 'YYYY-MM-DD HH24: MI: SS'

/ * To / home / oracle / archlog / of all the documents (actually, archive log files) is read into system, combined with the data dictionary, and then write system.logmnr table) * /
for fname in / home / oracle / archlog / *; do
echo "Processing $ fname!"
echo "connect / as sysdba"> / home / oracle / temp.sql
echo "EXECUTE dbms_logmnr.add_logfile ( '$ fname', dbms_logmnr.addfile);">> / home / oracle / temp.sql
echo "EXECUTE dbms_logmnr.start_logmnr (DictFileName => '/ opt/oracle/9.2.0/Oraclelogs/v816dict.ora')">> / home / oracle / temp.sql
echo "insert into system.logmnr (" SCN "," CSCN "," TIMESTAMP "," COMMIT_TIMESTAMP "," THREAD # "," LOG_ID "," XIDUSN "," XIDSLT "," XIDSQN "," PXIDUSN "," PXIDSLT "," PXIDSQN "," RBASQN "," RBABLK "," RBABYTE "," UBAFIL "," UBABLK "," UBAREC "," UBASQN "," ABS_FILE # "," REL_FILE # "," DATA_BLK # ", "DATA_OBJ #", "DATA_OBJD #", "SEG_OWNER", "SEG_NAME", "SEG_TYPE", "SEG_TYPE_NAME", "TABLE_SPACE", "ROW_ID", "SESSION #", "SERIAL #", "USERNAME", "SESSION_INFO "," TX_NAME "," ROLLBACK "," OPERATION "," OPERATION_CODE "," SQL_REDO "," SQL_UNDO "," RS_ID "," SEQUENCE # "," SSN "," CSF "," INFO "," STATUS " , "REDO_VALUE", "UNDO_VALUE", "SQL_COLUMN_TYPE", "SQL_COLUMN_NAME", "REDO_LENGTH", "REDO_OFFSET", "UNDO_LENGTH", "UNDO_OFFSET") (select * from v \ $ logmnr_contents); ">> / home / oracle / temp.sql
echo "exit;">> / home / oracle / temp.sql
/ opt/oracle/9.2.0/bin/sqlplus / nolog @ / home / oracle / temp.sql
echo The SQL file $ fname finished!
echo ------------------------------------------------- --------------
done

Document: get_arch.rar
Size: 1KB
Download: Download
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of (To) shell circumstances call sqlplus example

  • ORACLE10G full version centos5 installed (the installation has passed)

    ORACLE10G full version centos5 installed (the installation has passed) 1. Centos 5.0 install rn GUI must be installed, it is best not to start selinux rn rn rn 2. . Ready to install the software: (this is very important, is the first installation fai ...

  • Merge the use of (1)

    Merge to select from a table update or insert some data to another table. And finally is used to update or insert depends on the conditions of the statement. rn Here's our easy to cite an example: rn rn SQL> create table merge_test1 (a number, ...

  • SQL optimization (1) - full table scan and index the test

    Test Objective: To test CBO and RBO, as well as full table scan than index the situation quickly. 1. To create a test environment SQL> select * from v $ version; BANNER -------------------------------------------------- -------------- Oracle Datab ...

  • Oracle10g with cross-platform endian transfer

    In Oracle10g, the same endianness the first cross-platform file information Oracle will automatically re-evaluated, the conversion is no longer necessary. We watch the following tests: [oracle @ danaly oradata] $ sqlplus "/ as sysdba" SQL * ...

  • An example of the use of TKPROF

    First, view and edit parameters SQL> show parameter max_dump_file_size NAME TYPE VALUE ------------------------------------ ----------- --- --------------------------- max_dump_file_size string UNLIMITED SQL> show parameter user_dump_dest NAME TYPE

  • Diagnosis and principles of order

    SQL> select disk.value "Disk", mem.value "Mem", 2 (disk.value / mem.value) * 100 "Ratio" 3 from v $ sysstat mem, v $ sysstat disk 4 where mem.name = 'sorts (memory)' 5 and disk.name = 'sorts (disk)'; D ...

Leave a Reply

Recent
Recent Entries
Tag Cloud
Random Entries
Latest Comments