Using SQLPlus on MacOS

Once you have the client installed, go ahead and create tnsnames.oraΒ for your server connection under '/Applications/oracle/product/instantclient_64/network/admin'


ORACLE12C =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = myoracle12c.senecacollege.ca)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = oracle12c)
)
)

view raw

tnsnames.ora

hosted with ❤ by GitHub

Modify your .bash_profileΒ to store environment variables:


export ORACLE_HOME="/Applications/oracle/product/instantclient_64"
export PATH=$ORACLE_HOME/bin:$PATH
export DYLD_LIBRARY_PATH=$ORACLE_HOME/lib
# Set ORACLE_PATH to the location where you store your custom "login.sql"
export ORACLE_PATH="/Applications/oracle/product/instantclient_64/sqlplus/admin"
alias sqlplus='rlwrap sqlplus'

view raw

.bash_profile

hosted with ❤ by GitHub

Then you can create your own startup script, e.g.


SET PAGESIZE 100;
SET LINESIZE 100;
define_editor='vi';
SET SERVEROUTPUT ON;
SET VERIFY OFF;

view raw

login.sql

hosted with ❤ by GitHub

Last, add the following command to your .bashrc to skip error command not found: sqlplus


# Add it to the end of your .bashrc as start-up command
source ~/.bash_profile

view raw

.bashrc

hosted with ❤ by GitHub

Note:
If you face Error ORA-21561: OID generation failed when connecting to Oracle with a Mac, edit your hosts file to append local computer name to the end of the 127.0.0.1 line.


##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost <local_computer_name>
255.255.255.255 broadcasthost

view raw

hosts

hosted with ❤ by GitHub

😌