Dear readers of our blog, we'd like to recommend you to visit the main page of our website, where you can learn about our product SQLS*Plus and its advantages.
 
SQLS*Plus - best SQL Server command line reporting and automation tool! SQLS*Plus is several orders of magnitude better than SQL Server sqlcmd and osql command line tools.
 

REQUEST COMPLIMENTARY SQLS*PLUS LICENCE

Enteros UpBeat offers a patented database performance management SaaS platform. It proactively identifies root causes of complex revenue-impacting database performance issues across a growing number of RDBMS, NoSQL, and deep/machine learning database platforms. We support Oracle, SQL Server, IBM DB2, MongoDB, Casandra, MySQL, Amazon Aurora, and other database systems.

Chapter 4: List of SQLS*Plus Commands

2 July 2020

Chapter 4: List of SQLS*Plus Commands

List of Commands:

 
 

Command

 

 

Usage

 

 

Description

 

&&<variable name>  Use substitution variable
&&&&<variable name>  Use substitution variable
/  Executes the SQL command or batch currently stored in     the SQL buffer
ACCEPT|ACC ACC[EPT] variable [DEF[AULT] default] [PROMPT text| NOPR[OMPT]] [HIDE]  Reads keyboard input and stores it into the SQLS*Plus variable (listed by DEFINE command)

  variable
Name of the variable If variable does not exist, SQLS*Plus creates it.

  DEF[AULT]
Use set default value if a reply is not provided.

  PROMPT text
Skip a line and display text before accepting the variable value.

  NOPR[OMPT]
Skip a line and wait for an input without prompt.

  HIDE
Suppress the display of the typed characters.

AGAIN |!!Again | !!<number>  Rerun latest matching entry or command from history
BREAK|BREBREAK [ON <COLUMN|REPORT|ROW>] <DUP|NODUP> ON specifies on what
<SKI[P] N|PAGE>
  column to track value changes that occur in the report and the formatting action to perform

ON REPORT specifies that break related action (SKIP lines or calculate COMP values) will be done at the
end of the report

ON ROW executes SKIP action (if specified) after every row

DUP|NODUP

NODUP prints blanks for duplicate values in break column

DUP prints the value of a break column in every row

SKIP skips specified number of lines or whole page on break

BREAK is needed for COMP statements to work

COMP expects to have BREAK columns defined for ON part of the COMP statement

BTITLE

BTI[TLE] [printspec [text | variable] …] | [ON | OFF]

Syntax

where printspec represents one or more of the following clauses used to place and format the text:

CE[NTER]

LE[FT]

S[KIP] [n]

COL [n]

TAB [n]

Enter BTITLE with no clauses to list the current BTITLE definition.

Options

See the TTITLE command for information on terms and clauses in the BTITLE command syntax.

Examples

BTITLE LEFT ‘REPORT ‘ RIGHT ‘PAGE:’
SQL.PNO

  Places and formats a specified title at the bottom of each report page, or lists the current BTITLE definition.

See the TTITLE command syntax for information on terms and clauses in the R[IGHT] BTITLE command syntax.

CATcat <table_name> -a  Synonym for “select * from

<table/view name”

Cat <table/view name>

Selects first 3000 rows Options: -a – select all rows

CDcd <directory_name>  Change current directory location
CLEARclear <BREAKS|COMPUTES|SCREEN>  BRE[AKS] – clears all defined breaks

COMP[UTES] – clears all defined computes

SCR[EEN] – clear screen

COLUMN | COLCOLUMN | COL col <name> heading <name> format
<format> <ON|OFF>
<PRINT|NOPRINT>Supported Character Formats To change the width of a character field to n, use FORMAT An. (“A” for alphabetic.)Supported Num ber Formats
ElementsExampleDescription
, (comma)9,999Displays a comma
. (period)99.99Displays a period  (decimal point) to separate the integral and fraction of a number.
$$9999Displays a leading dollar sign.
00999 9990Displays leading zeros and trailing zeros.
99999Displays a value with the number of digits specified by the number of 9s.
 Set column format

ON|OFF – turn off/on column format attributes

PRINT|NOPRINT – show or hide column from the query output

COMPUTE|COMP

 COMP[UTE] [function [LAB[EL] text]  … OF {column } … ON {column}

Supported functions:

Function DescriptionDatatypes
AVGNon-null values averageNumeric
COUNT|COUNon-null values countAll
MINIMU M|MINMinimum valueNumeric &  character
MAXIMU M|MAXMaximum valueNumeric &  character
NUMBER|NUMRow countAll
SUMNon-null
values sum
Numeric
STDNon-null
values standard deviation (for population)
Numeric
VARIANC E|VARNon-null
values standard variance (for population)
Numeric
  COMP in combination with the BREAK, calculates and prints summary function values, based on groups defined by BREAK.

COMP with no parameters lists all current COMPUTE  definitions.

LABEL Defines the label for the computed function value

OF {column}

OF defines columns that is used to calculate value summary of function

ON {column}

ON defines columns that is used to group values summary functions around.

Corresponding BREAK ON columns must exists for ON clause in COMP to work

If multiple
COMPUTE commands use the same ON column, only the last ON column would

CONNECT | CONN

 connect user/password@ip[\\instance_name][:db_name]

-acreate additional session, don’t disconnect
-lList all sessions, don’t disconnect
-s <sess_num> switch to session (as reported by -l)
  Create a new session

Connect creates a database session. Multiple sessions can exists at the same time

Instance name and database names are optional

Instead of db_name it is possible to use below environmental variables to set up default database for connection:

a) SQLSDBNAME

b) SQLCMDDBNAM E (standard sqlcmd variable)

COUNT
  Count rows in the tables
DEFINEDEF[INE] [variable]|[variable = text]

-l list defines

Below are the pre-defined variables

_CONNECT_IDENTIFIER Connection identifier used to make connection.

_CONNECT_DATABASE Database used to make connection, where available.

_EDITOR
Editor used by the EDIT command.

_S_VERSION
Version of the connected SQL Server Database.

_S_LEVEL
Level of the connected SQL Server Database.

_USER
User name used to make connection.

  Define a variable and assigns a value to it, or lists the value and variable type of a single variable or all variables
CTAS
CTAS source_table destination_table empty_flag  Create destination table as select from the source table
DEPS
DEPS [NAME]

-r list dependencies recursively

  Object dependencies and references
DESCRIBE | DESC | DEDESCRIBE [OBJECT_NAME|SCHEMA.OBJECT_ NAME] [detail]  Describe a table, view or a stored procedure

“detail” option provides detailed describe information

DIR  List file directory
DISCONNECT  Disconnect session
EDIT | EDED | ED <sql_file_name>   Edit current statement or sql script file

Default editor is “notepad”

Environment variable SQLSEDIT can be used to set custom editor

EXEC  Execute T-SQL procedure
FIND  Find a line in T-SQL procedure source
GREPgrep <pattern table [extra clause]>

-v show rows that don’t match pattern -I ignore case

Search pattern across all table columns

  Show rows that match pattern
HEAD  Show first rows of table
HELP  Provide help for a command
HISTORY | HIST | HI  Show history items matching pattern (or all)
HOST | HOS | HO  Execute host OS command
ID  Display current user and login
LIST  List last sql statement
LS  List all objects matching pattern
PAUSESET PAUSE <TEXT> SET PAUSE [ON|OFF]  Enables to control scrolling of terminal when executing reports. First step is to “SET PAUSE text”, and then “SET PAUSE ON” to make text to appear each time SQLS*Plus pauses.
PRINTVAR  Print bind variables
PROMPT  Sends the specified message or a blank line to the user’s screen
PURGEpurge <table where …>

-c print table count at the end -n 1000 chunk size
-i 1000 max iterations -q be quiet

You can specify an additional “where” clause:

purge Table where id=23

  Delete from (large) table in chunks

Purge executes a series (-i) of delete statements, where each statement deletes (-n) rows at a time and commits.

PWD  Show current directory
QUIT  Leave SQLS*Plus
RECOMPILE  Recompile objects
REFS  Display referential integrity dependencies
REM
RERUN | !!rerun <history_number>  Run history item number
SET AUTOCOMMITset auto[commit] <on|imm[ediate]|off>  Controls when SQL Server  commits changes to the database after SQL commands or T-SQL call. ON commits changes to the database after SQL Server executes successful DML or T-SQL call. OFF turns off automatic committing so commit changes has to be done explicitly. IMMEDIATE is a synonym of ON.
SET AUTOFORMATset autoformat <table_name> maxsize <N> sample <N>

maxsize default is 40 characters sample default is 10% of table size

  Automatically generates optimal format definitions for table %char% and %int% columns based of sampling of table data

Maxsize defines maximum column size for long character columns

Sample defines what percent of the table data to scan to create optimal format definitions

SET COLSEP  Set column separator character
SET FEEDBACKset feedback <on|off|N>  Display number of records returned by a query when a query selects at least n records

N – when number of selected records is over N, number of records returned will be shown

SET HEADING  Set heading value
SET HEADSEP  Set heading separator
SET LINESIZE | LINESset linesize <size>  Set

Table of Contents
Type chapter title (level 1) – 1 Type chapter title (level 2) – 2 Type chapter title (level 3) – 3
Type chapter title (level 1) – 4 Type chapter title (level 2) – 5 Type chapter title (level 3) – 6
output line size

SET NEWPAGE|NEWPset newpage <0|n|none>  Sets number of blank lines to print from the page top to the top title

If newpage is set to 0, form feed character is printed at the beginning of each page

SET MARKUP HTML | SET MARK HTMLSET MARK[UP] HTML [ON | OFF]
[HEAD text] [BODY text] [TABLE text]
[ENTMAP {ON | OFF}] [SPOOL {ON | OFF}] [PRE[FORMAT] {ON | OFF}]
  Set output to HTML

  HTML [ON|OFF]

HTML is a mandatory argument which specifies that HTML output is to be generated.

HTML arguments, ON and OFF, specify whether or not to generate HTML output. The default is OFF.

  HEAD text

The HEAD text option enables to specify content for the <HEAD> tag. By default, text includes a default in-line CSS and title. If text includes spaces, it must be enclosed in quotes.

  BODY text

The BODY text option enables to specify attributes for the <BODY> tag. By default, there are no attributes. If text includes spaces, it must be enclosed in quotes.

  TABLE text

The TABLE text option enables to enter attributes for the <TABLE> tag. By default, the <TABLE> WIDTH attribute is set to 90% and the BORDER attribute is set to 1. If text includes spaces, it must be enclosed in quotes.

  ENTMAP {ON|OFF}

ENTMAP ON or OFF specifies whether or not SQL*Plus replaces special characters <, >, ” and & with the HTML entities &lt;, &gt;, &quot; and &amp; respectively. ENTMAP is set ON by default.

  SPOOL {ON|OFF}

SPOOL ON or OFF specifies whether or not SQLS*Plus writes the HTML opening tags, <HTML> and <BODY>, and the closing tags, </BODY> and </HTML>, to the start and end of each file created by the SQLS*Plus SPOOL filename command. The default is OFF.

Header and footer tags enabled by the SET MARKUP HTML SPOOL ON option are not written to the spool file until “SPOOL filename” command is not issued

  PRE[FORMAT] {ON|OFF}

PREFORMAT ON or OFF specifies whether or not SQLS*Plus writes output to the <PRE> tag or to an HTML table. The default is OFF, so output is written to a HTML table by default.

SET OUTPUTset output <csv | json | default>  Set output to CSV (commas separated values), to JSON or to default output.

Supported CSV and JSON format outputs all fields surrounded by double quotes

SET PAGESIZE | PAGESset pagesize <size>  Set output page size
SET SQLPROMPT| SQLPset sqlprompt <message> | reset  Sets the SQLS*Plus command prompt. SET SQLPROMPT can use define variables in the message
SET TERMOUT|TERMset termout on|off  Controls the display of output generated by commands in a script that is executed with @, @@ or START. OFF stops output to screen to enable output to a file without displaying it on a screen. ON displays the output on screen.

TERMOUT OFF does not affect output from commands entered interactively or directed to SQLS*Plus from the OS.

SET UNDERLINESET UND[ERLINE] {‘-‘ | c | ON | OFF}  Set the character to underline column headings. The underline character cannot be an alphanumeric or a white space. ON or OFF turns underlining on or off.
SET VERIFY  Print ampersand replacing
SET VOUTset vout on|off  Set vertical output mode
SETVARSETVAR <variable> <value>  Set value of bind variable
SHO[W]SHOW <set parameter name>  Show value of the named SET parameter
SHOW DB|DATABASE  Show current database
SHOW DBS|DATABASES  Show available databases
SHOW ERRORS  Show SQL Server error log
SHOW LICENSE  Show license information and license days to expiration
SHOW PARAMETER|PARMshow parameter <pattern>  Show database parameters
SHOW SERVERS  Show names of SQL Server instances located on a servers that broadcast on local domain network
SHOW TABLES|TAB  Show database tables
SHOW USER  Show the current username
SPOOLSPO[OL] [file_name[.ext]
[CRE[ATE] | REP[LACE] | APP[END]] | OFF |]
  Write output to file

APPEND – add output to the file

CREATE – would not allow to overwrite existing file

REPLACE (default) – replace existing file

OFF – stop spooling

START | @  Execute sql script
STARTREL | @@  Execute sql script relative / nested to a running script
TTITLESyntax

TTI[TLE] [printspec [text | variable] …] [ON | OFF]

where printspec represents one or more of the following clauses used to place and format the text:

CE[NTER]

LE[FT]

R[IGHT]

S[KIP] [n]

COL [n]

TAB [n]

Options:

These options also apply to the BTITLE command.

text

The ttitle text. Enter text in single quotes if you want to place more than one word on a single line.

variable

A substitution variable or any of the following system-
maintained values, SQL.LNO (the current report line
number), SQL.PNO (the current report page number) ,
SQL.SYSDATE (the current report timestamp),
SQL.USER (the current connected user)

To print one of these values, reference the appropriate variable in the title. You can format variable with the FORMAT clause.

SQLS*Plus substitution variables (& variables) are
expanded before TTITLE is executed. The resulting
string is stored as the TTITLE text.

OFF

Turns the ttitle off (suppresses its display) without affecting its definition.

ON

Turns the title on (restores its display). When you
define a top title, SQLS*Plus automatically sets TTITLE
to ON.

S[KIP] [n], n>=1

Skips to the start of a new line n times; if you omit n,
one time;

COL [N]

Moves to the line column n. N can be negative.

TAB [n]

Moves forward n columns (line columns, not database
table columns) or backwards if n is a negative number

LE[FT] | CE[NTER] | R[IGHT]

Left-align, center, and right-align data on the current
line respectively. CENTER and RIGHT use current
LINESIZE value to calculate the relative position of the
data items

TTITLE with no clauses lists current TTITLE definition.

Examples

To define “Monthly Report” as the top title and to left-
align it, to center the current date, to right-align the
page number, and to display “Data in Millions” in the
center of the next line, enter

TTITLE LEFT 'Monthly Report' CENTER
SQL.SYSDATE
RIGHT 'Page:' SQL.PNO SKIP CENTER
'Data in Millions'

  Places and formats a specified title at the top of each report page.

Enter TTITLE with no clauses to list its current definition.

TSQL   Display t-sql procedure code
VARIABLEVARIABLE <name> <type> -s <value>  declare a bind variable

Download SQLS*Plus manual in PDF format


 
Tags: , , , ,

MORE NEWS

 

Preamble​​NoSql is not a replacement for SQL databases but is a valid alternative for many situations where standard SQL is not the best approach for...

Preamble​​MongoDB Conditional operators specify a condition to which the value of the document field shall correspond.Comparison Query Operators $eq...

5 Database management trends impacting database administrationIn the realm of database management systems, moreover half (52%) of your competitors feel...

The data type is defined as the type of data that any column or variable can store in MS SQL Server. What is the data type? When you create any table or...

Preamble​​MS SQL Server is a client-server architecture. MS SQL Server process starts with the client application sending a query.SQL Server accepts,...

First the basics: what is the master/slave?One database server (“master”) responds and can do anything. A lot of other database servers store copies of all...

Preamble​​Atom Hopper (based on Apache Abdera) for those who may not know is an open-source project sponsored by Rackspace. Today we will figure out how to...

Preamble​​MongoDB recently introduced its new aggregation structure. This structure provides a simpler solution for calculating aggregated values rather...

FlexibilityOne of the most advertised features of MongoDB is its flexibility.  Flexibility, however, is a double-edged sword. More flexibility means more...

Preamble​​SQLShell is a cross-platform command-line tool for SQL, similar to psql for PostgreSQL or MySQL command-line tool for MySQL.Why use it?If you...

Preamble​​Writing an application on top of the framework on top of the driver on top of the database is a bit like a game on the phone: you say “insert...

Preamble​​Oracle Coherence is a distributed cache that is functionally comparable with Memcached. In addition to the basic function of the API cache, it...

Preamble​​IBM pureXML, a proprietary XML database built on a relational mechanism (designed for puns) that offers both relational ( SQL / XML ) and...

  What is PostgreSQL array? In PostgreSQL we can define a column as an array of valid data types. The data type can be built-in, custom or enumerated....

Preamble​​If you are a Linux sysadmin or developer, there comes a time when you need to manage an Oracle database that can work in your environment.In this...

Preamble​​Starting with Microsoft SQL Server 2008, by default, the group of local administrators is no longer added to SQL Server administrators during the...