tab
completes table, view and column names)
argument
, cd
,ctas
, ddl
, repeat
, liquibase
$ wget https://download.oracle.com/otn_software/java/sqldeveloper/sqlcl-latest.zip -O /tmp/sqlcl.zip
~/bin/sqlcl
(all files in the zip file are located under sqlcl
): $ unzip -d ~/bin /tmp/sqlcl.zip
java
is installed (otherwise, it needs to be installed). $ java --version
~/bin/sqlcl
, it can be started like so: $ ~/bin/sqlcl/bin/sql rene/rene@localhost/freepdb1
$PATH
variable to the executable: mv ~/bin/sqlcl ~/bin/sqlcl_ ln -s ~/bin/sqlcl_/bin/sql ~/bin/sqlcl
yum install sqlcl
brew install sqlcl
getsqlcl.sh
seems to download and install SQLcl (I've not tested it). script
and ended (like also an anonymous PL/SQL block) with a slash (/
) ctx.write
prints text. The new line "\n"
is necessary for the text to be flushed: script ctx.write("hello world\n"); /
print(…)
in which case the new line is not required. script print('The number is 42'); /
print()
writes to a different output stream than ctx.write()
. It seems that when using such scripts in SQL Developer, the stream that print()
writes to cannot be captured (that is: if it is possible, I don't know how). script
can also execute the content of a script file. The file's suffix .js
can be omitted: script some_file_with_javascript
sqlcl.setStmt(…)
and sqlcl.run()
: script var tabName = 'all_users'; sqlcl.setStmt('select count(*) from ' + tabName); sqlcl.run(); /
sql
. -H | Display SQLcl version (as -V does) and usage help. |
-V | Display SQLcl version |
-R level | Set restricted level. Level = 1, 2, 3 or 4, 4 being the most restrictve. The restriction level determines how much a use can mess up the file system. |
-S | Silent mode: no output of SQLcl banner, prompts and commands. |
-verbose | Show logging messages inline. |
-nohistory | No history logging. |
-noupdates | No check if update is available |
-oci | By default, SQLcl uses Oracle's JDBC driver to connect to the database. With -oci , it is instructed to use the Oracle client. |
-L | Don't reprompt for username/password if entered wrongly (ORA-01017: invalid username/password; logon denied). |
sqlcl rene/mySecret@localhost:1533/freepdb1
?tns_admin=…
to a connect string, the location of a directory with a tnsnames.ora
file can be specified: mkdir ~/tns-admin echo 'ora23=(description=(address_list=(address=(protocol=tcp)(host=localhost)(port=1533)))(connect_data=(service_name=freepdb1)))' > ~/tns-admin/tnsnames.ora sqlcl rene/mySecret@ora23?tns_admin=/home/rene/tns-admin
rene@ORA19> alias usr=select username, account_status, default_tablespace from dba_users;
rene@ORA19> usr
dbms_metadata
to get a table's create statement or to produce a create table as select…
statement. info
and info+
describe tables and views select /*ansiconsole*/ * from …; -- Best appearance for ANSI terminal display select /*csv*/ * from …; -- Comma-separated values select /*delimited*/ * from …; -- same as csv select /*fixed*/ * from …; -- Fixed-width fields with trailing blanks select /*html*/ * from …; -- Marked-up HTML table select /*insert*/ * from …; -- Return INSERT statements select /*json*/ * from …; -- Returns JSON object format select /*loader*/ * from …; -- Pipe-delimited format suitable for SQL*Loader select /*text*/ * from …; -- Plain text select /*xml*/ * from …; -- Tagged XML
F5
for the «hint» to have an effect. set sqlformat …
$ printf 'set verify off\ndefine num=42\n%-10000s;\nexit\n' 'select &num as num from dual' > /tmp/long-line.sql $ ~/bin/sqlcl/bin/sql rene/rene@localhost/freepdb1 @/tmp/long-line.sql
rene@SYS$USERS> create or replace procedure drop_me as 2 begin 3 no_such_procedure; 4 end; 5 /
no_such_procedure
does not exist. rene@SYS$USERS> show errors Errors for PROCEDURE RENE.DROP_ME: LINE/COL ERROR -------- ----------------------------------------------------------------- 3/4 PL/SQL: Statement ignored 3/4 PLS-00201: identifier 'NO_SUCH_PROCEDURE' must be declared
set define off verify off feedback on
ocijdbc19.dll
is 64-bit while SQLcl (sql.exe
) is 32-bit. This causes the error message C:\Oracle\19\bin\ocijdbc19.dll: Can't load AMD 64-bit .dll on a IA 32-bit platform .\sql.exe rene/rene@jdbc:oracle:thin:@192.168.0.227:1521:ORA19
ocijdbc19
to java.library.path
? PS:\> sql /@ORA19 SQLcl: Release 19.4 Production on Thu Nov 05 08:46:33 2020 Copyright (c) 1982, 2020, Oracle. All rights reserved. USER = URL = jdbc:oracle:oci8:@ora19 Error Message = no ocijdbc19 in java.library.path USER = URL = jdbc:oracle:thin:… Error Message = ORA-01017: invalid username/password; logon denied Username? (RETRYING) ('/@db.uat.xy'?) ^
%ORACLE_HOME%\bin\sql.bat
is a batch file that is supposed to start SQLcl (but doesn't seem to work). $ORACLE_HOME/sqldeveloper/sqldeveloper/bin/sql
however does seem to work. oracle-db-tools
has SQLcl examples