Article Directory
Since a consistent, standard SQL * Plus command-line tools are the Oracle database. Now, however, Oracle introduced a new command-line interface Interface tools: Oracle SQL Developer Command Line (SQLcl).
SQLcl is a free Java-based tools, positioning is SQL Plus successor. SQLcl support interactive or batch execute SQL and PL / SQL, offers inline editing, statement completion, command history feature-rich, and can invoke SQL Plus scripts.
Key Features
- Built-in editor , interactive editing SQLcl prompt multi-line statements and scripts.
- Command history , cycle storage support 100 history command / script.
- Command completion , use the TAB key to auto-complete object names or keywords.
- New commands , an increase in SQL * Plus does not support CTAS, DLL, Repeat, ALIAS, SCRIPT, FORMAT , and many new commands.
- Client-side scripting , query results by javascript operation command to create dynamic, interactive execution session and so on.
- SQL * Plus support , support for SQL * Plus environment settings, command and function.
Installation SQLcl
SQLcl based on Java, just to have JRE, no need to install the Oracle client. We can log on Oracle OTN direct download SQLcl tool . After the download is complete decompression can, bin directory contains the executable files under Windows and sql.exe tools sql command under Unix / Linux.
Connect to the database
SQLcl way to connect to the database with SQL * Plus is similar supports EZConnect, TNS, LDAP, TWO_TASK, etc., pay attention to early configured Java environment. The following is an example of EZConnect connection to the database using the Windows environment:
C:\Users\tony>java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
C:\Users\tony>D:\Applications\sqlcl\bin\sql.exe tony/[email protected]:1521/orcl
SQLcl: 发行版 19.1 Production, 发行日期 星期二 六月 11 10:41:41 2019
版权所有 (c) 1982, 2019, Oracle。保留所有权利。
Last Successful login time: 星期二 6月 11 2019 10:41:42 +08:00
已连接到:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> SELECT user FROM dual;
USER
--------------------------------------------------------------------------------
TONY
Use Introduction
SQLcl use with SQL * Plus is very similar, but adds many new features, we simply introduce the next several main characteristics of them.
View Help
After logging in, use the HELP
command or ?
view commands SQLcl provide help.
Part of which is highlighted SQLcl newly added commands. And then view a specific command, such as CTAS
:
SQL> help ctas;
CTAS
ctas table new_table
使用 DBMS_METADATA 可以提取现有表的 DDL,
然后修改为 create table as select * from
The command is based on an existing table, create a new table to generate DDL statements, but does not execute the statement.
Built-in editor
For SQL * Plus, you need to call an external editor to edit files or SQL buffer. SQLcl aims to provide a built-in editor, use the DEFINE _EDITOR
set:
SQL> define _EDITOR;
DEFINE _EDITOR = "notepad" (CHAR)
SQL> define _EDITOR="inline";
SQL> define _EDITOR;
DEFINE _EDITOR = "inline" (CHAR)
Built-in editor supports the following shortcut:
- R + Ctrl - to run the statement in the current buffer
- W is + ctrl - Move the cursor to the top of the buffer
- S + ctrl - Move the cursor to the bottom of the buffer
- A + ctrl - move the cursor to the beginning
- E + ctrl - Move the cursor to the end of the line
Are editing the current line will show an asterisk (*), but can also use the arrow controls to move the cursor, use the delete key and the Backspace key to delete the content.
Command History
When using SQL * Plus, history can not access the command has been executed, unless the installation rlwrap. SQLcl solve this problem, check HISTORY
the help command:
SQL> help history;
HISTORY
---------
history [<index> | FULL | USAGE | SCRIPT | TIME | CLEAR (SESSION)?]
SQL>history full
1 select 1 from dual;
2 select 2
> from dual;
3 select 3 from dual
> where 1=1;
SQL>history usage
1 (2) select 1 from dual;
2 (11) select 2 from dual;
3 (2) select 3 from dual where 1=1;
SQL>history script
select 1 from dual;
select 2 from dual;
select 3 from dual where 1=1;
SQL>history 3
1 select 3 from dual
2* where 1=1;
SQL>his time
1 clear
2 cl bre
3 (00.201) select 1 from dual
Help command parameters, and examples are given. After a history command lists, enter a slash (/) to run the command. This feature has the following characteristics:
- Use the up and down arrow and then click View history commands.
- Use
HISTORY
the command to display the command history. - Default save the last 100 historical statement.
- Use
SET HISTORY LIMIT N
modify the default number of saved history limit command. - Command history support sessions across SQLcl save.
- By default,
SHOW
,HISTORY
,CONNECT
andSET
commands are not saved to the history. SET HISTORY BLACKLIST
Command can be used to set the command blacklist does not want to save.
Command Completion
SQLcl support the use of the Tab key completion input function, you can fill the whole object names and commands, increase input speed.
Formatted output
SQL * Plus default output format usually appear chaotic, through a series of commands to set seemed more humane. SQLcl variety of pre-common output formats, including CSV, JSON, XML and the like.
SQL> help set sqlformat;
SET SQLFORMAT
SET SQLFORMAT { csv,html,xml,json,ansiconsole,insert,loader,fixed,default}
The following are the default format and output in CSV format example:
SQL> SELECT *
2 FROM
3 EMPLOYEES
4* WHERE rownum <= 2;
EMPLOYEE_ID FIRST_NAME LAST_NAME
----------- -------------------- -------------------------
EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY
------------------------- -------------------- --------- ---------- ----------
COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
-------------- ---------- -------------
207 Tony Dong
TonyDong 515.123.8000 15-1月 -10 IT_PROG 8800
102 60
100 Steven King
SKING 515.123.4567 17-6月 -03 AD_PRES 24000
90
SQL> set sqlformat csv;
SQL> SELECT *
2 FROM
3 EMPLOYEES
4* WHERE rownum <= 2;
"EMPLOYEE_ID","FIRST_NAME","LAST_NAME","EMAIL","PHONE_NUMBER","HIRE_DATE","JOB_ID","SALARY","COMMISSION_PCT","MANAGER_ID","DEPARTMENT_ID"
207,"Tony","Dong","TonyDong","515.123.8000",15-1月-10,"IT_PROG",8800,,,102,60
100,"Steven","King","SKING","515.123.4567",17-6月-03,"AD_PRES",24000,,,90