Thursday 20 August 2020

The Oracle DB Developer VM: Upgrade SQLcl to latest version

This post is part of my Oracle DB Developers VM series. Based on the previous postings on how to set up the Oracle DB on Linux 8 in VirtualBox, this post will show how to upgrade the VM to use the latest SQLcl.

First we need to install java:

dnf in java-11-openjdk.x86_64
java -version

That should give you the info on OpenJDK:
Download the lastest SQLcl from https://download.oracle.com/otn_software/java/sqldeveloper/sqlcl-latest.zip and unzip it to a directory for all your executables under your home directory. In my case:

cd ~/bin
wget https://download.oracle.com/otn_software/java/sqldeveloper/sqlcl-latest.zip
unzip sqlcl-latest.zip

Test it with

sqlcl/bin/sql

and type version. That should return
Add the following line to your .bashrc:

export PATH=/home/oracle/bin/sqlcl/bin
export SQLPATH=~/sql

Create a directory ~/sql and inside a file named login.sql with the above content.

set statusbar on
set highlighting on

This will enable some of the cool features of SQLcl. It is so easy, this is probably my shortest posting ever. 

But wait, there is more. As you already have downloaded the latest platform independent SQLcl, you can also use it to connect from your host OS to the database in your VM.

So in my case, use Windows Explorer to extract sqlcl to a folder on your drive, eg. D:\Oracle . Put the bin directory into your path. Of course, this SQLcl installation also needs a compatible Java runtime. So if you don't have one, install it first. On Windows better use the installer based version (jdk-11.0.8_windows-x64_bin.exe). I had issues with the JDK zip distributions, probably I have installed and uninstalled so many JDK's, that my Windows Registry is messed up. But the installer based version ran flawless.

sql.exe system@orcldevvm-ol8:1521/orclpdb

Try it with an easy connect string.
You can also connect via TNS. Create a directory like D:\Oracle\network\admin and an environment variable to point to it like

set TNS_ADMIN=D:\Oracle\network\admin

And better make that permanent. Create a tnsnames.ora file in that directory, here is an example to adapt:

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = orcldevvm-ol8)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

ORCLPDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = orcldevvm-ol8)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orclpdb)
    )
  )

Now try it with TNS connect

sql.exe system@orclpdb

and that should work too.
SQLcl is a super fast and easy way to talk to your Oracle DB.