I'm writing a script that allows a user to select an option from a menu (which is done), and return from database which is stored in oracle11g.
pause(){
read -p "Press [Enter Key To Continue]"
}
connect(){
export LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client64/lib
sqlplus64 '******@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=oracle.***********)(Port=****))(CONNECT_DATA=(*******)))'
}
show_menu() {
clear
echo "~~~~~~~~~~~~~~~~~~"
echo " M A I N - M E N U"
echo "~~~~~~~~~~~~~~~~~~"
echo "1. Connect to Database"
echo "2. Query Table"
echo "3. Exit"
echo "_____________________"
}
one() {
connect
pause
}
I'm using astericks in the code snippet to save some of the personal information. My question is, how would I go about, for example, having the user select 2, and making the database return, for example
SELECT * FROM *
Directly back to command line? Is this far more difficult than I think? The connect() function allows me to log into the database server, but I need to manually enter my password and then I'm logged into oracle until I close the script.
You can execute it as below in shell
OUTPUT=/path/to/sqlplus64 user/password\@sid << EOF
select * from table;
EOF
echo $OUTPUT;
You can replace the query with what you get from user.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.