Write oracle select query in shell script with oracle docker
I am using the docker oracle 12.2.0.1 and I want to write shell script which contains select query. And without sqlplus image I always get
"sqlplus command not found"
this why I added an image to my docker which is made it possible to run sqlplus command. Now my images are here
[email protected]:/home/yusufs# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
store/oracle/database-enterprise 12.2.0.1 12a359cd0528 3 years ago 3.44GB
guywithnose/sqlplus latest 292fea16b54c 6 years ago 550MB
And I have the following script
#! /bin/bash
docker run --interactive guywithnose/sqlplus sqlplus "yusuf/[email protected](description=(address_list=(address=(protocol=TCP)(host=localhost)(port=1521)))(connect_data=(service_name=ORCLCDB.localdomain)))" << EOF
spool results.out
select count(*) from recycling where status=0;
spool off
exit;
EOF
When I execute the script I have the following output even I didn’t write any user name
[email protected]:/home/yusufs/Desktop# ./query3.sh
SQL*Plus: Release 12.1.0.1.0 Production on Wed Dec 16 11:05:41 2020
Copyright (c) 1982, 2013, Oracle. All rights reserved.
ERROR:
ORA-12541: TNS:no listener
Enter user-name: ERROR:
ORA-12162: TNS:net service name is incorrectly specified
Enter user-name: ERROR:
ORA-12162: TNS:net service name is incorrectly specified
SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
Source: Docker Questions