SQLcl is a command line tool for working with Oracle Database. It’s available on many major operating systems, including MacOS.
Here’s a quick rundown on the steps I used to install SQLcl on a Mac.
Note: If you also plan on installing SQL Developer, then you won’t need to install SQLcl separately. SQL Developer comes with a copy of SQLcl. In that case, you can run SQLcl as soon as you’ve installed SQL Developer. However, the version may be different – you’ll need to check the version against the latest available.
You might also want to add its folder to your PATH variable (see the “Add to Path” heading below).
Prerequisite
SQLcl requires that you have at least Java Runtime Engine (JRE) 8.
If you’re not sure whether you have it or what version it is, open a Terminal window and run the following command:
java -version
In my case, it returns the following:
java version "1.8.0_291" Java(TM) SE Runtime Environment (build 1.8.0_291-b10) Java HotSpot(TM) 64-Bit Server VM (build 25.291-b10, mixed mode)
If your Java version starts with 1.8
, you’re good to go.
If not, you can download the JRE from the Java website.
Download SQLcl
First, download SQLcl from the Oracle Website.
Once downloaded, open the .zip file:
This extracts a folder called sqlcl that contains various other folders and files.
If the sqlcl folder is in your Downloads folder, feel free to move it to another location. For example, you could move it to your Applications folder.
Once you’ve done that, you can launch SQLcl by opening a Terminal window and entering the full path, followed by the default username and password:
/Applications/sqlcl/bin/sql hr/oracle
In this case, /Applications/sqlcl/bin/sql
is the full path, hr
is the username, and oracle
is the password. Those credentials were created when I installed Oracle on my Mac using the Oracle DB Developer VM.
If it connects successfully, you should see something like this:
SQLcl: Release 21.2 Production on Sun Jul 11 11:22:20 2021 Copyright (c) 1982, 2021, Oracle. All rights reserved. Last Successful login time: Sun Jul 11 2021 11:22:21 +10:00 Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.3.0.0.0 SQL>
You can now start using SQLcl by typing SQL statements and other commands at the prompt.
However, if you plan on using SQLcl a lot, you will probably want to add it to the PATH variable, so that you can launch it without needing to include the full path.
Add to PATH
This part is optional, but it will make it much easier to launch SQLcl.
Most modern Macs use ZSH when you open the Terminal. In this case, you can add to your PATH variable like this:
code ~/.zshrc
This uses my Visual Studio Code application to open the file called zshrc
in my home directory. If it doesn’t already exist, it will be created.
If you don’t have VS Code, try the following instead:
vi ~/.zshrc
This opens the file in the vi editor.
Alternatively, use an editor of your choice.
Once open, add the following on its own line:
export PATH="/Applications/sqlcl/bin:$PATH"
If you have it in a different folder, change the path accordingly.
Once the file has been saved, you can now launch SQLcl by opening a Terminal window, and typing the following:
sql hr/oracle
Actually, you can even just use the following:
sql
In which case you’ll be prompted for the username and password.
You can also change the name of the sql file to sqlcl or anything else if you prefer.
If you use an older mac, or you prefer to use BASH instead of ZSH, then you’ll probably need to edit the .bash_profile
file instead of .zshrc
.
In that case, use the following command to open the .bash_profile
file:
code ~/.bash_profile
Or use vi or other editor if you prefer.
Add the path and save the changes.
Once that’s done, you can open SQLcl as indicated above.