Shell calls Sqlplus query Oracle

Source: Internet
Author: User
Tags sqlplus


Cat echo_time #!/bin/sh"sys/unimas as Sysdba" <<! Select to_char (sysdate,'yyyy-mm-dd') today from Dual;exit;! [email protected] shell_test]$.

Operation Result:

TODAY-----------Geneva-

-S is silent mode, does not output similar "sql>", connect the database, close the database and other information.

Eof

EOF can be any string such as "Laldf" then when you enter a single line Laldf "The shell thinks the input ends, but must indicate that the block must start with <<;
Start and end to match this symbol "<<" after the content
Example:

" Sys/unimas as Sysdba " << ABCselect to_char (sysdate,'yyyy-mm-dd') today from dual; > exit; > ABC

Run results

TODAY-----------Geneva-
Two. Sqlplus results passed to the Shell method one

[Email protected] shell_test]$CatTest2.SH #!/bin/Bashvalue= ' Sqlplus-s"Test/unimas"<<!set heading offset feedback offset pagesize0Set Verify offsetEchooffSelectTo_char (Sysdate,'YYYY-MM-DD') today from Dual;exit!`Echo$VALUEif[-N"$VALUE"]; ThenEcho "The rows is $VALUE"Exit0ElseEcho "There is no row"fi

three. Sqlplus results passed to the Shell method two

[Email protected] shell_test]$CatTest1.SH #!/bin/Bashsqlplus-S"Test/unimas"<<!set heading offset feedback offset pagesize0Set Verify offsetEchoOffcol coun new_value V_counSelectCOUNT (*) Coun from Lesson;exit V_coun!VALUE="$?"Echo "Show row: $VALUE"

Col coun New_value V_coun V_coun is the number type. Because exit can only return numeric types.
four. Pass the shell parameters to the Sqlplu

#!/bin/basht_id="$" "test/unimas " < <!  0echo  offselectid=$t _id;exit !

Five. Sqlplus results are stored in the file

#!/bin/sh"test/unimas"<<  0  echo* from teacher;spool offexit; EOF

Shell calls Sqlplus query Oracle

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.