Skip to content

Latest commit

 

History

History
201 lines (139 loc) · 4.88 KB

README.md

File metadata and controls

201 lines (139 loc) · 4.88 KB

Oracle SQLcl

From oracle.com:

SQLcl is a command-line interface for Oracle Database that combines the power of SQL*Plus and SQL Developer.

SQLcl is now under the Oracle Free Use Terms and Conditions license, which makes automated installation much easier.

Java

Java is required, so ensure an appropriate version is installed.

macOS

Use Homebrew as follows or use the shell script.

brew install --cask sqlcl

Note that this may not add the bin folder to PATH, so try the command on the Homebrew page and restart the shell.
Alternatively, add the command to ~/.zshrc:

# Set path variables.
path+=$(brew --prefix)/Caskroom/sqlcl/<version>/sqlcl/bin
export path
typeset -U path

Linux

Use yum as follows or use the shell script.

See the Oracle Linux Yum Server for assistance with yum repositories.

sudo yum install sqlcl

Shell script

Use at your own risk. It is advisable to review the script before executing it.

  1. Clone this repository and treat the root as the working directory.

    cd ~
    mkdir git
    cd git
    git clone <url>
  2. The script may ask for the current user's password, as it will attempt to install SQLcl to /opt.

    $ sh install.sh
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 39.4M  100 39.4M    0     0  8721k      0  0:00:04  0:00:04 --:--:-- 8900k
    
    Installation complete
  3. Restart the shell. E.g. zsh:

    exec zsh
  4. Check the SQLcl install.

    $ which sql
    /usr/local/bin/sql
    
    $ echo $SQLPATH
    /Users/<user>/.sqlcl
    
    $ echo $TNS_ADMIN
    /Users/<user>/.sqlcl

Connections

Container

For example, using an instance of Oracle XE in a container:

  1. Check the container is running.

    $ podman ps -a                                                             
    CONTAINER ID  IMAGE                            COMMAND     CREATED        STATUS            PORTS                   NAMES
    6c5800535262  docker.io/gvenzl/oracle-xe:slim              8 seconds ago  Up 8 seconds ago  0.0.0.0:1521->1521/tcp  pensive_khorana
  2. Connect to database as system user.

    $ sql system@localhost:1521/XEPDB1
    
    
    SQLcl: Release 22.2 Production on Sat Jul 09 12:34:00 2022
    
    Copyright (c) 1982, 2022, Oracle.  All rights reserved.
    
    Password? (**********?) *****
    Last Successful login time: Sat Jul 09 2022 12:34:05 +01:00
    
    Connected to:
    Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production
    Version 21.3.0.0.0
    
    SQL>
  3. Optionally create a TNS entry in $TNS_ADMIN/tnsnames.ora.

    XEPDB1 =
        (DESCRIPTION =
            (ADDRESS = 
                (PROTOCOL = TCP)
                (HOST = localhost)
                (PORT = 1521)
            )
            (CONNECT_DATA =
                (SERVER = DEDICATED)
                (SERVICE_NAME = XEPDB1)
            )
        )

    Then connect using the entry:

    sql system@XEPDB1

Oracle Cloud Infrastructure (OCI)

Create an account and an Autonomous Transaction Processing (ATP) database at https://cloud.oracle.com.

  1. Select the database instance from the Autonomous Database dashboard.

  2. Click DB Connection and download the Instance Wallet to ~/.sqlcl.
    E.g. ~/.sqlcl/Wallet_demo.zip.

  3. Open SQLcl:

    sql /nolog
  4. Load wallet:

    SQL> SET CLOUDCONFIG Wallet_demo.zip
    
    Operation is successfully completed.
    Using temp directory:/var/folders/2v/jfse9ffs3sdfdfhde431dgge0000fr/T/oracle_cloud_config8573768666928582556
    
  5. Check TNS entries:

    SQL> SHOW TNS
    
    TNS_ADMIN set to: /var/folders/2v/jfse9ffs3sdfdfhde431dgge0000fr/T/oracle_cloud_config8573768666928582556
    
    
    Available TNS Entries
    ---------------------
    demo_high
    demo_low
    demo_medium
    demo_tp
    demo_tpurgent
    
  6. Connect to database using a TNS entry:

    SQL> CONNECT admin@demo_medium
    
    Password? (**********?) *********************
    Connected.
    
  7. Execute some SQL:

    SQL> SELECT SYSDATE
      2  FROM dual;
    
         SYSDATE
    ____________ 
    01-JUL-22