CLPPlus Reference
CLPPlus Reference
CLPPlus Reference
Db2 11.1 for Linux, UNIX, and Windows IBM
CLPPlus Reference
ii Db2 11.1 for Linux, UNIX, and Windows: CLPPlus Reference
Notice regarding this document
This document in PDF form is provided as a courtesy to customers who have
requested documentation in this format. It is provided As-Is without warranty or
maintenance commitment.
CLPPlus complements the functions that the command line processor (CLP)
provides. CLPPlus includes the following features:
v Support for establishing connections to databases when you provide a database
user ID and password.
v A buffer that you can use to store scripts, script fragments, SQL statements, SQL
PL statements, or PL/SQL statements for editing and then execution. You can
list, print, or edit the text in the buffer or run the text in the buffer as a batch
script.
v A comprehensive set of processor commands that you can use to define
variables and strings that you can store in the buffer.
v A set of commands that retrieve information about a database and database
objects.
v The ability to store buffers or buffer output in a file.
v Multiple options for formatting the output of scripts and queries.
v Support for executing system-defined routines.
v Support for executing operating system commands.
v An option for recording the output of executed commands, statements, or
scripts.
Procedure
SQL>
v On Windows operating systems, you can use the menu option:
1. Click Start > IBM Db2 > CLPPlus.
2. Specify your user ID and connection information.
The menu option is not available for the following IBM® data server client
installations:
– IBM Data Server Client
– IBM Data Server Runtime Client
– IBM Data Server Driver Package
v On Linux operating systems, you can use the menu option:
1. Click Main Menu > IBM Db2 > Db2 Command Line Processor Plus.
2. Specify your user ID and connection information.
The menu option is not available for the following IBM data server client
installations:
– IBM Data Server Client
– IBM Data Server Runtime Client
– IBM Data Server Driver Package
Results
The CLPPlus prompt (SQL>) is available, and you are connected to the specified
database.
What to do next
You can now use CLPPlus commands and related features. Specify the commands
at the CLPPlus prompt.
To end the CLPPLus session, issue the EXIT or QUIT CLPPlus command.
CLPPLUS command
Starts the command line processor plus (CLPPlus) session. After you start the
CLPPlus session, you can issue CLPPlus commands, connect to databases, define,
and run SQL statements and database commands, and run scripts that contain SQL
statements and commands.
Invocation
You must run the CLPPLUS command from the operating system command prompt.
None
Required connection
None
Command Syntax
►► clpplus ►
-verbose -nw -s connection_identifier
-si /
-sil
-sile
-silen
-silent
► ►◄
@ dsn_alias @ script_name
connection_identifier:
user
/ password @ host : port / database
Command parameters
-verbose
Sets verbose on. When verbose is set on all CLPPlus messages are printed to
the console.
-nw
Specifies that the CLPPlus session is started in the current command-line
window.
-s | -si | -sil | -sile | -silen | -silent
Suppresses the version information, copyright information, prompt messages,
command echo, and connection information from being printed in the current
CLPPlus session. During silent mode, by default, ECHO is set to OFF. Any
attempt to set ECHO to ON is ignored.
/ Specifies the current operating system login user ID is used to connect to the
database.
user
Specifies the user ID to connect to the database.
password
Specifies the password that corresponds to the user ID.
hostname
Specifies the name of the computer on which the database is located. For
example, for a computer that is named ascender, specify @ascender.
port
Specifies the port number that receives connections on the computer where the
database server is installed. The default is 50000.
Example
The following examples show how you can use the CLPPLUS command to start the
CLPPlus session and optionally connect to databases.
The following command starts the CLPPlus session and attempts to connect to a
database named SAMPLE on a local host with user ID adminuser and port number
50000:
clpplus adminuser@localhost:50000/sample
The following command starts the CLPPlus session and prompts for a password
for the user ID adminuser. If the password is valid, the CLPPlus interface attempts
to connect to a database named SAMPLE, which is the default database name.
clpplus adminuser
The following command starts the CLPPlus session and attempts to connect to a
database named SAMPLE with user ID adminuser and password mypassw0rd. If
the user ID and password are valid, a database connection is established. The
drawback to specifying a password is that the password is displayed on the screen.
clpplus adminuser/mypassw0rd
The following command starts the CLPPlus session and attempts to connect to a
database named SAMPLE on the remote machine ascender using port 50000, user
ID adminuser, and password mypassw0rd. If these values are valid, a database
connection is established.
clpplus adminuser/mypassw0rd@ascender:50000/sample
The following command starts the CLPPlus session and attempts to connect to a
database named DB on the local computer with user ID adminuser, password
mypassw0rd, and the default port number, which is 50000:
clpplus adminuser/mypassw0rd@localhost/db
The following command starts the CLPPlus session and attempts to connect to a
database by first locating an IBM data server driver configuration file. If one is
found, the default_dsn is read for the host, port, and database values. The
adminuser ID is used in the connection attempt. If no IBM data server driver
configuration file is found, all required parameters are requested interactively.
clpplus adminuser
The following command starts the CLPPlus session and attempts to connect to a
database by fetching the parameters from the data_dsn alias in the IBM data server
driver configuration file. Since no user ID is specified, the current logon user ID is
used. Any parameters that cannot be read are requested interactively.
clpplus /@data_dsn
The following command starts the CLPPlus session and attempts to connect to a
database by fetching the parameters from the data_dsn alias in the IBM data server
driver configuration file. The adminuser user ID is used in the connection. Any
parameters that cannot be read are requested interactively.
clpplus adminuser@data_dsn
Window mode
When CLPPlus is started with the CLPPLUS command, the window mode console is
spawned by default. This new console window has better command editing
capabilities. As such, when using CLPPlus in an interactive mode, this window
mode might be the preferred console choice.
Non-window mode
When CLPPlus is started with the CLPPLUS command and the -nw option is
specified, the current command line environment is used, that is, no new window
is spawned. This might be a preferred choice if you are calling a script file and do
not require a spawned console window.
The window mode CLPPlus console can read UTF-8 characters from the file
system, database, and interactively from the keyboard. The window mode CLPPlus
console can write UTF-8 characters into the file system, database or interactively to
the standard output. Also, column alignment issues that can be present with the
non-window mode CLPPlus console are resolved with the window mode CLPPlus
console.
UTF-8 character support is available only in the window mode CLPPlus console,
which is the default CLPPlus console type. For the non-window mode CLPPlus
console, support for non-ASCII characters is limited. In the non-window mode
CLPPlus console, you might not be able to enter certain non-ASCII characters.
Misalignment of result set columns can occur if non-ASCII characters are included
in that result set.
Procedure
To set the font name, style, and size in the CLPPlus window mode:
Example
The following example sets the font that is displayed in the CLPPlus window
mode to serif, in bold typeset and size of 32 points.
SET FONT serif,1,32
The following example sets the font that is displayed in the CLPPlus window
mode to SansSerif, in plain typeset and size of 48 points.
SET FONT "SansSerif", 0, 48
The following example sets the font that is displayed in the CLPPlus window
mode to Lucida console, in bold typeset and size of 35 points.
SET FONT "lucida console",1, 35
Procedure
Example
The following example sets the font color that is displayed in the CLPPlus window
mode to red.
SET COLOR RED
The following example sets the font color that is displayed in the CLPPlus window
mode to white.
SET COLOR 255,255,255
Procedure
To set the background color in the CLPPlus window mode:
1. Using the CLPPLUS CLPPlus command, start the CLPPlus session. The CLPPlus
session is started, by default, in the window mode. For more information, see
the Related reference.
Example
The following example sets the background color that is displayed in the CLPPlus
window mode to cyan.
SET BGCOLOR cyan
The following example sets the background color that is displayed in the CLPPlus
window mode to white.
SET BGCOLOR 255,255,255
The IBM data server driver configuration file is an XML file that contains a list of
DSN aliases and their properties. It is used to store connection details in one place.
The CLPPlus interface can use that information to automatically connect to a data
source instead of interactively asking for all the connection details on every
connect attempt.
If DB2DSDRIVER_CFG_PATH is not set, the CLPPlus interface searches for the IBM
data server driver configuration file in the default directory location. For
information about the default location of the IBM data server driver configuration
file, see the Related concepts.
A user who attempts a connect is asked for a database name. That database name
is treated as a DSN alias and searched in the configuration file. If that DSN alias is
found, the connection attributes are read and a password is requested to complete
the connection. If the DSN alias is not found, then the host name, port number,
user name, and password are requested interactively to go with the original
database name, and all information gathered is used to attempt a connection.
Example
Consider the following IBM data server driver configuration file contents:
<configuration>
<dsncollection>
<dsn alias="S" name="SAMPLE" host="9.121.221.159" port="50000">
The following example shows a connection established with the contents of the
IBM data server driver configuration file.
In the following example, the clpplus command is used to start a CLPPlus session
and the connect command is issued to establish connection with DSN alias "S".
C:\>clpplus
CLPPlus: Version 1.1
Copyright (c) 2009, IBM CORPORATION. All rights reserved.
SQL> connect
The following example shows a connection when the database name entered is not
found as an alias in the IBM data server driver configuration file.
SQL> connect
Since "sample" is not found as a DSN alias in the configuration file, the remaining
values are requested interactively by the CLPPlus interface and then a connection
attempt is made.
For more information about supported keywords, see the Related reference.
The IBM data server driver configuration file is an XML file that contains a list of
DSN aliases, database directory information, and their properties. If the DSN alias
or database entry contains the SecurityTransportMode parameter value that is set
to SSL, the SSL protocol is used in CLPPlus connections to the server. If the
SecurityTransportMode parameter value is set to SSL and the SSL connection
requires the use of self-signed certificate on the server, you can copy the certificate
to the client and set the SSLServerCertificate parameter to the absolute path and
name of the certificate. For more information, see the Supported IBM data server
driver configuration keyword topic.
The SSL CLPPlus connections are implemented by the JDBC driver that uses the
Java SSL APIs and it does not use the IBM Global Security Kit (GSKit) libraries.
Example
Consider the following IBM data server driver configuration file contents:
<configuration>
<dsncollection>
<dsn alias="S" name="SAMPLE" host="9.121.221.159" port="50001">
</dsn>
</dsncollection>
<databases>
<database name="SAMPLE" host="9.121.221.159" port="50001">
<parameter name="SecurityTransportMode" value="SSL"/>
</database>
</databases>
</configuration>
The following example shows a connection being established with the contents of
the IBM data server driver configuration file, which includes the
SecurityTransportMode parameter value.
SQL> connect
The IBM data server driver configuration file is an XML file that contains a list of
DSN aliases and their properties. If the DSN alias entry contains the
Authentication property value that is set to kerberos, the Kerberos authentication
mechanism is used. For more information, see the DSN aliases in CLPPlus topic.
The CLPPlus interface does not request a Kerberos TGT ticket on its own. It uses
the ticket that is already obtained by the user for use with other applications or
tools.
Example
Consider the following IBM data server driver configuration file contents:
<configuration>
<dsncollection>
<dsn alias="S" name="SAMPLE" host="9.121.221.159" port="50000">
</dsn>
</dsncollection>
<databases>
<database name="SAMPLE" host="9.121.221.159" port="50000">
<parameter name="UserID" value="john"/>
</database>
</databases>
<parameters>
<parameter name="Authentication" value="KERBEROS"/>
</parameters>
</configuration>
The following example shows a connection being established with the contents of
the IBM data server driver configuration file, which includes the Authentication
parameter value.
The user starts a CLPPlus session and attempts a connection to the DSN alias "S".
C:\>clpplus
CLPPlus: Version 1.1
Copyright (c) 2009, IBM CORPORATION. All rights reserved.
The IBM data server driver configuration file is an XML file that contains a list of
DSN aliases and their properties. If the DSN alias entry contains the
Authentication property value that is set to SERVER_ENCRYPT, the
SERVER_ENCRYPT authentication mechanism is used. For more information, see
the DSN aliases in CLPPlus topic.
Example
The following example shows a connection being established with the contents of
the IBM data server driver configuration file, which includes the Authentication
parameter value.
Consider the following IBM data server driver configuration file contents:
<configuration>
<dsncollection>
<dsn alias="S" name="SAMPLE" host="9.121.221.159" port="50000">
<parameter name="Authentication" value="SERVER_ENCRYPT"/>
</dsn>
</dsncollection>
<databases>
<database name="SAMPLE" host="9.121.221.159" port="50000">
<parameter name="UserID" value="john"/>
</database>
</databases>
</configuration>
The user starts a CLPPlus session and attempts a connection to the DSN alias "S".
C:\>clpplus -nw
CLPPlus: Version 1.5
Copyright (c) 2009, 2011, IBM CORPORATION. All rights reserved.
SQL> connect
Enter DATABASE NAME [SAMPLE]: S
Enter ID [john]:
Enter password: **********
The IBM data server driver configuration file is an XML file that contains a list of
DSN aliases and their properties. If the DSN alias entry contains the
Authentication property value that is set to SERVER_ENCRYPT_AES, the
SERVER_ENCRYPT_AES authentication mechanism is used. For more information, see
the DSN aliases in CLPPlus topic.
Example
The following example shows a connection being established with the contents of
the IBM data server driver configuration file, which includes the Authentication
parameter value.
Consider the following IBM data server driver configuration file contents:
<configuration>
<dsncollection>
<dsn alias="S" name="SAMPLE" host="9.121.221.159" port="50000">
<parameter name="Authentication" value="SERVER_ENCRYPT_AES"/>
</dsn>
</dsncollection>
<databases>
<database name="SAMPLE" host="9.121.221.159" port="50000">
<parameter name="UserID" value="john"/>
</database>
</databases>
</configuration>
The user starts a CLPPlus session and attempts a connection to the DSN alias "S".
C:\>clpplus -nw
CLPPlus: Version 1.6
Copyright (c) 2009, 2011, IBM CORPORATION. All rights reserved.
SQL> connect
Enter DATABASE NAME [SAMPLE]: S
Enter ID [john]:
Enter password: **********
If you specify a DSN alias name that is not found in the IBM data server driver
configuration file (db2dsdriver.cfg), the CLPPlus interface attempts to connect to
the LDAP directory server that is specified in the IBM data server driver
configuration file to resolve the DSN alias name. The CLPPlus interface looks up
the DSN alias name on the LDAP directory server and use the required connection
details from the DSN entry, such as host name, port number, user ID, and
password, to make a connection. If no match is found on the LDAP directory
server or the connection to the LDAP directory server fails, the DSN alias name is
treated as a database name during an interactive connection.
To enable the LDAP support, use the <ldapserver> section in the IBM data server
driver configuration file to specify the LDAP directory server information. A single
LDAP directory server entry is allowed in the IBM data server driver configuration
file. The UserID and Password fields in the <ldapserver> section are optional; you
can enter user ID and password information at run time. User ID and password
information is cached during the CLPPlus session.
If you set the UserID parameter in the IBM data server driver configuration file to
"*anonymous", an anonymous connection to the LDAP directory server is
attempted; user ID and password information is not passed. You are not prompted
for a password, and if you set the Password parameter in the IBM data server
driver configuration file, the parameter is ignored.
Important:
If you set the UserID parameter to "*anonymous", you must configure the LDAP
directory server to support anonymous connections.
Examples
Consider the following sample IBM data server driver configuration file:
<configuration>
<dsncollection>
<dsn alias="alias1" name="name1" host="server1.net1.com" port="50001"/>
</dsncollection>
<databases>
</databases>
<ldapserver>
<parameter name="EnableLDAP" value="YES"/>
<parameter name="LDAPServerHost" value="ipv6lab7.torolab.ibm.com"/>
<parameter name="LDAPServerPort" value="389"/>
<parameter name="UserID" value="root"/>
<parameter name="Password" value="itdsv23"/>
The following example connects to a DSN alias DBLDAP1 with the sample IBM data
server driver configuration file. The DBLDAP1 DSN alias name is not found in the
IBM data server driver configuration file and the DSN alias entry on the LDAP
directory server ipv6lab7.torolab.ibm is searched. The host, port, and database
information from the DBLDAP1 DSN alias name that is found on the LDAP directory
server is retrieved to establish a connection.
SQL> connect
Enter DATABASE NAME [SAMPLE]: DBLDAP1
Enter ID : db2admin
Enter password: ********
The following example connects to the DBLDAP1 DSN from the CLPPlus session in
the VERBOSE mode:
SQL> connect
DB250001I: CLPPlus has successfully read the configuration file named
’C:\Documents and Settings\All Users\Application data\IBM\DB2\DB2COPY1\cfg\db2dsdriver.cfg’.
DB250014I: DSN alias ’DBLDAP1’ is not found in the configuration file named
’C:\Documents and Settings\All Users\Application Data\IBM\DB2\DB2COPY1\cfg\db2dsdriver.cfg’.
Enter ID : db2admin
Enter password: ********
The following example connects to a DSN alias DBLDAP2 with the sample IBM data
server driver configuration file. The CLPPlus session is running in the VERBOSE
mode. When the DSN alias DBLDAP2 is not found in the IBM data server driver
configuration file or on the specified LDAP directory server, then the interactive
CLPPlus connection attempt occurs.
SQL> connect
DB250001I: CLPPlus has successfully read the configuration file named
’C:\Documents and Settings\All Users\Application data\IBM\DB2\DB2COPY1\cfg\db2dsdriver.cfg’.
DB250014I: DSN alias ’DBLDAP2’ is not found in the configuration file named
’C:\Documents and Settings\All Users\Application Data\IBM\DB2\DB2COPY1\cfg\db2dsdriver.cfg’.
DB250015I: CLPPlus successfully established a connection with LDAP directory server ’ipv6lab7.torolab.ibm.com:389’
DB250016E: DSN alias ’DBLDAP2’ was not found in LDAP directory server ’ipv6lab7.torolab.ibm.com:389’.
’DBLDAP2’ is used as the database name in the subsequent interactive CLPPlus connect attempt.
The following example connects to the DBLDAP2 DSN from the CLPPlus session in
the VERBOSE mode:
SQL> connect
DB250001I: CLPPlus has successfully read the configuration file named
’C:\Documents and Settings\All Users\Application data\IBM\DB2\DB2COPY1\cfg\db2dsdriver.cfg’.
DB250014I: DSN alias ’DBLDAP2’ is not found in the configuration file named
’C:\Documents and Settings\All Users\Application Data\IBM\DB2\DB2COPY1\cfg\db2dsdriver.cfg’.
Consider the following modified version of the IBM data server driver
configuration file. The IBM data server driver configuration file does not include
the UserID and Password parameters for the LDAP directory server configuration.
The LDAP directory server ipv6lab7.torolab.ibm is specified.
<configuration>
<dsncollection>
<dsn alias="alias1" name="name1" host="server1.net1.com" port="50001"/>
</dsncollection>
<databases>
</databases>
<ldapserver>
<parameter name="EnableLDAP" value="YES"/>
<parameter name="LDAPServerHost" value="ipv6lab7.torolab.ibm.com"/>
<parameter name="LDAPServerPort" value="389"/>
Using the updated IBM data server driver configuration file, a connection to alias
name SAMPLE32 is attempted. The alias name is not found in the IBM data server
driver configuration file. When the user ID and password to the LDAP directory
server are entered interactively, as shown in the following example, the CLPPlus
interface connects to the ipv6lab7.torolab.ibm LDAP directory server. The LDAP
directory server is successfully searched for the SAMPLE32 DSN alias, and the host,
port, and database information is retrieved. A CLPPlus connection is established
with the database information that is retrieved from the LDAP server. In the
following example, the CLPPlus session is not running in the VERBOSE mode.
C:\Documents and Settings>clpplus /@SAMPLE32
You can run a script with the CLPPLUS command. For other methods, see the
related links.
Procedure
Run the CLPPLUS command, specifying a script name. For example, consider the
following script file named dept_query.sql.
SET PAGESIZE 9999
SET ECHO ON
SELECT * FROM DEPT;
EXIT
The dept_query.sql script file is run after the user connects to the database. When
the script is run, the commands SET PAGESIZE and SET ECHO ON and the statement
SELECT * FROM are issued.
The output of the script is as follows. ECHO ON displays the statement that was
issued in the script file, and the values of DEPT are displayed up to a page limit of
9999.
clpplus db2user/passw0rd @dept_query.sql
Connected to XXX v X.X (localhost:5444/db2sampl) AS db2user
SQL>
SELECT * FROM dept;
SQL >
EXIT
You can interrupt any command or script that CLPPlus is running using the
Ctrl+C keystroke. This is helpful when you encounter a long running query or
script and need to return control back to the CLPPlus interface.
You can also skip to the next SQL> prompt by pressing the ENTER key twice in
succession. This is helpful when you enter an incorrect command and want to
cancel it. The incorrect command is retained in the buffer and can be edited using
any of the CLPPlus commands you use for editing and review.
Example
Comments in CLPPlus
CLPPlus has the ability for you to include comments in your scripts and
commands.
In CLPPlus, comments can span one ore more lines. Comments that are contained
on a single line start with # or --. Comments that span multiple lines are enclosed
in /* and */.
The following examples show both single and multiple line comments.
SQL> # This is a single line comment
SQL>
SQL> -- This is also a single line comment
SQL>
SQL> /* This comment
spans
multiple lines. */
SQL>
Description
In CLPPlus, you can use the ampersand (&) character to substitute variables in
SQL statements. Escape characters can be used to escape the ampersand character
in input values to avoid substitution, for example "AT&M".
Escape characters can also be used to escape the characters "$" and "%", which are
used to reference shell and environment variables in CLPPlus.
You can define the escape character with the SET command. The default escape
character is "\". For more information about the SET command, see the related
reference.
Example
1. This example shows the use of the default escape character which avoids "&M"
being treated as a substitution variable.
SQL> set escape ON
SQL> insert into testtab values(’AT\&M’);
DB250000I: The command completed successfully.
Authorization
name
Specifies the name of the bind variable.
datatype
Specifies the data type that is associated with the bind variable. The data type
can be one of: BOOLEAN, CHARACTER, DATE, DECIMAL, DOUBLE,
FLOAT, INTEGER, REAL, SMALLINT, or VARCHAR.
REFCURSOR is also supported. REFCURSOR is used to receive the OUT
parameter values of type CURSOR in procedures, functions, and anonymous
PL/SQL blocks.
NUMBER, NUMBER(p[,s]), and VARCHAR2 are also supported. NUMBER and
NUMBER(p[,s]) are implicitly mapped to the DECIMAL data type.
VARCHAR2 is implicitly mapped to the VARCHAR data type.
CLPPlus allows the use of BOOLEAN, ROW, and ARRAY data types as
parameters for stored procedures with Db2 servers. You can run a stored
procedure with the CALL or EXEC CLPPlus statements.
Scope
Bind variables persist over the duration of a user's CLPPlus session. When a
CLPPlus session is started, bind variables can be declared and used during that
session. When a CLPPlus session is ended, any bind variables are cleared.
Restrictions
Db2 for z/OS® and Informix® Dynamic Server data servers have the following
limitations with the usage of bind variables:
v Bind variables cannot be initialized using the EXEC command.
Exec :var_name:=’john’ /* this is not supported */
v Bind variables cannot be initialized using a begin-end block.
begin
:var_name:=’john’; /* this is not supported in a begin-end block */
end;
v Since PL/SQL is not supported on Db2 for z/OS and Informix Dynamic Server
data servers, bind variables are not supported in a PL/SQL body.
v Variables with type CURSOR are not supported.
SQL> CREATE PROCEDURE getEmployeeData( ID INT, OUT NAME char(10),
OUT DOB Date, OUT SAL DECIMAL(7,2))
LET NAME=’dummy’;
LET DOB=’10/10/2010’;
LET SAL=0;
SELECT empname, empdob, salary INTO name, dob, sal FROM emp WHERE empid = ID;
END PROCEDURE;
/
DB250000I: The command completed successfully.
Examples
The following examples show how you can define, initialize, and use bind
variables.
1. Bind variables that are named ID and LNAME of type VARCHAR:
VARIABLE ID VARCHAR
VARIABLE LNAME VARCHAR
2. A bind variable that is named ID initialized in a PL/SQL block:
BEGIN
:ID := ’000020’;
END;
/
3. Bind variables ID and LNAME used in a PL/SQL block:
BEGIN
SELECT lastname INTO :LNAME FROM employee
WHERE empno = :ID;
END;
/
4. A single PL/SQL statement initializes a bind variable named ID :
EXECUTE :ID := ’000022’;
5. The variable ID is initialized from a substitution variable a (a is defined with
the DEFINE CLPPlus command):
EXECUTE :ID := &a;
6. The ID bind variable is used in a SELECT statement:
SELECT lastname FROM employee WHERE empno = :ID;
7. The ID and LNAME bind variables are used in an UPDATE statement:
UPDATE employee SET lastname = :LNAME WHERE empno = :ID;
8. The salary bind variable is defined with the number data type:
variable salary number
exec :salary := 1000.00
9. The bonus bind variable is defined with the number(p[,s]) data type:
variable bonus number(6)
exec :bonus:= 999.999
Bind variables are substituted as input and output arguments. Define the bind
variables:
variable in_var integer
variable out_var double
Optionally print the contents of the output argument, which is the out_var
bind variable:
print out_var
13. This example shows a bind variable var1, which does not reflect the precision
in the definition:
variable var1 number(4,2)
DB250000I: The command completed successfully.
Description
With this support, any shell or environment variable value can be used in a
CLPPlus command or query. This use is identical to how these variables are
accessed in shell or command windows.
Any variable prefixed with "$" is treated as a shell or environment variable. This
character provides operating system independence to scripts which are used across
differing operating systems. Environment variables on Microsoft platforms can also
be accessed by wrapping "%" around the variable name, for example, %VAR%.
If CLPPlus attempts to use a variable and it is defined, then its value is retrieved
and used as expected. If CLPPlus attempts to use a variable and it is not defined,
an empty string value is substituted and an informational message is logged. The
informational message is visible when CLPPlus is operating in verbose mode.
You can access shell and environment variables in CLPPlus with the following
methods:
v While starting CLPPlus, you can pass shell or environment variables as
arguments to a script. These passed variables are converted into position
parameters which are accessed with the "&" character and their position
(number)
v Shell or environment variables can be directly accessed in CLPPlus with the "$"
character followed by the variable name. This method is irrespective of the
operating system on which the script is run.
Examples
1. The following example shows how you can use shell or environment variables
while starting CLPPlus:
On UNIX and Linux platforms:
Export TABLE_NAME=employee
Export SCRIPT_PATH=/home/user
Note: For Db2, the CREATE DATABASE and DROP DATABASE commands fail if
connected to a remote database manager instance. You must be connected to a
local database manager instance
Note: IMPORT, EXPORT and LOAD commands have a restriction that processed
files must be on the server
Restrictions
For the Db2 environment, the CREATE DATABASE command fails if you are connected
to a remote database manager instance. You must be connected to a local database
manager instance. You can specify the following parameters for the CREATE
DATABASE command in the CLPPlus interface:
v The required database-name variable
v The optional CODESET parameter
v The optional TERRITORY parameter
Note: When you create a Db2 database without the pagesize parameter, the
default page size for the new database is 32 K.
For IBM Informix, CREATE DATABASE from the CLPPlus interface requires connection
credentials, specifically to the sysmaster database. You are prompted for
connection credentials if a connection does not exist. For more information about
the CREATE DATABASE command in IBM Informix, see http://www.ibm.com/
support/knowledgecenter/SSGU8G_12.1.0/com.ibm.sqls.doc/ids_sqs_0368.htm
Examples
The following command creates a database that is named testdb with a page size
of 4 K in the Db2 environment:
create database testdb pagesize 4K;
The following command creates a database that is named testdb in the Db2
environment. The code page set is defined as UTF-8, and the territory is defined as
US.
create db testdb using codeset UTF-8 territory US;
The following command creates a database that is named udttest in the IBM
Informix environment. No previous connection exists, so you are prompted to
provide the connection information.
SQL> create database udttest;
CLPPlus restrictions
The CLPPlus interface has certain connection, command, and statement
restrictions.
The CLPPlus interface can establish database connections with the following Db2
database products but with the following restrictions:
v Db2 Version 9.8 Fix Pack 1 or higher. You must apply Fix Pack 1 to V9.8 before
connectivity is supported.
The EDIT command is supported in the CLPPlus window mode. The command is
not supported in the CLPPlus non-window mode.
The IBM Data Server Driver for JDBC and SQLJ and IBM Data Server Driver for
ODBC and CLI offer comprehensive tracing facilities. These facilities have been
extended to CLPPlus. Trace facilities generate text log files whenever an
application accesses a specified driver (CLPPLus Client layer or JDBC Driver layer)
using the SET command. These log files provide detailed information about the
CLPPlus Client and JDBC:
v functions called by an application
v function contents; including input and output parameters passed to and received
from
v function return codes and any error or warning messages generated.
To configure the CLPPlus trace facilities, issue the SET command from a CLPPlus
command prompt. To enable client layer or driver layer traces, set the LOGMODE
parameter:
CLPPlus> SET LOGMODE logmode-value
where logmode-value indicates whether to perform tracing and for which layer. The
default value is NONE, which indicates no tracing is done. Other valid values are
CLPPLUS, which traces the client layer, JCC, which traces the JDBC layer, and
BOTH, which traces both the client and JDBC layers.
To perform more detailed JDBC tracing, set logmode-value to JCC or BOTH, and
specify the JCCLOGMODE parameter:
SET LOGMODE JCC
SET JCCLOGMODE jcclogmode_value
where jcclogmode_value indicates the features to be traced and logged. For more
information about valid jcclogmode_value settings, see “SET” on page 89.
CLPPlus commands
The CLPPlus feature includes many commands which provide extensive user
control, customization, and personalization.
.
The . CLPPlus command is similar to a No Operation Performed (NOOP or NOP)
machine language command. It is ignored when entered on its own with no other
CLPPlus command.
The . CLPPlus command can also be used to skip the currently entered command
and move to the next SQL> prompt. This can be done by entering the command
on its own on a new line in the current block of code. This can help you cancel a
command when you enter an incorrect entry. A cancelled command is available in
the history and can be accessed and edited.
Invocation
You must run this command from the CLPPlus interface or from within a CLPPlus
script file.
Authorization
None
Required connection
None
Command syntax
►► . ►◄
Example
In the following example, the . command is used to cancel the current command.
SQL> begin
2 dbms_output.putline(’wrong put_line’);
3 .
SQL>
!
The ! CLPPlus command is a synonym to the HOST CLPPlus command. It will run
an operating system command.
Invocation
You must run this command in the CLPPlus interface.
Authorization
None
Required connection
None
Command parameters
os_command
Specifies an operating system command.
Example
In the following example, the ! command is issued with the dir operating system
command.
SQL> ! dir
Directory of C:\USER_Backup\Office\Project\FP3\FP3\src
/
The / CLPPlus command reruns the last command run in the current CLPPlus
session.
Invocation
Authorization
None
Required connection
None
Command syntax
►► / ►◄
Example
The following example shows the / command rerunning the last SELECT statement
run within CLPPlus:
SQL> SELECT AVG(salary) FROM employee WHERE workdept = ’E21’
1
------------------------------------------
47086.66666666666666666666666666667
SQL> /
@
The @ CLPPlus command is an alias for the START CLPPlus command. It can be
used to run a CLPPlus script file.
Invocation
You must run this command from the CLPPlus interface.
Authorization
None
Required connection
None
Command syntax
►► @ script-file ►◄
path
URL
Command parameters
path
Specifies the path, either absolute or relative, to the script file that contains
SQL statements and commands to run. If no path is specified, the current
directory is used.
URL
Specifies the URL to the script file that contains SQL statements and
commands to run. The URL must start with http:// or https://.
script-file
Specifies the script file name that contains SQL statements and commands to
run.
Example
Invocation
Authorization
None
Required connection
None
Command syntax
►► @@ script-file ►◄
path
URL
Command parameters
path
Specifies the path, either absolute or relative, to the script file that contains
SQL statements and commands to run. If no path is specified, the current
directory is used.
URL
Specifies the URL to the script file that contains SQL statements and
commands to run. The URL must start with http:// or https://.
script-file
Specifies the script file name that contains SQL statements and commands to
run.
Example
A script called dept_details.sql calls another script called employee_count.sql. The
contents of dept_details.sql follows:
ACCEPT dept_id PROMPT "Enter Department ID code : "
@@ employee_count &dept_id
ACCEPT
The ACCEPT CLPPlus command creates a variable with a specified name. Values can
be assigned to this variable interactively in the CLPPlus interface or through a
parameter read as part of a script that is run. The ACCEPT command is useful for
storing values that you commonly use in SQL statements or in the SQL buffer.
You must run this command from the CLPPlus interface or from within a CLPPlus
script file.
Authorization
None
Required connection
None
Command syntax
►► ACCEPT variable-name ►
ACC FORMAT format-string
► ►◄
DEFAULT default-value PROMPT text HIDE
Command parameters
variable-name
Defines the variable name. You cannot use special symbols and characters such
as the forward slash (/) or at sign (@).
When you issue the ACCEPT command, you are prompted for the value of
variable-name.
FORMAT format-string
Defines the format assigned to the variable. The value you attempt to assign to
the variable must follow the format outlined.
For a character variable, the value of format-string is An, where n specifies the
number of characters that can be used to display the variable. The data wraps
if it is wider than the specified width.
For numeric variables, the value of format-string can be one or more of the
following characters:
$ Displays a leading dollar sign.
, Displays a comma at the indicated position.
. Displays a decimal point at the indicated position.
0 Displays a zero at the indicated position.
9 Displays a significant digit at the indicated position.
If loss of significant digits occurs due to overflow of the format settings, the #
character is displayed.
DEFAULT default-value
The default value defined with this option is assigned to the variable when a
user hits the ENTER key and does not provide any value when prompted.
PROMPT text
The value defined with this option is displayed in the prompt when the ACCEPT
command is entered.
Example
In the following example, the ACCEPT command creates a variable named my_name
and prompts for a value. The value John Smith is stored in this variable. The
DEFINE command displays the value of the variable.
SQL> ACCEPT my_name
Enter value for my_name: John Smith
SQL> DEFINE my_name
DEFINE my_name = "John Smith"
The following example shows all the options used in the ACCEPT command.
SQL> ACCEPT lname FORMAT A10 DEFAULT ’Joy’ PROMPT ’Enter Last Name [Joy]:’ HIDE
The FORMAT option specifies that the value for lname is alphanumeric and 10
characters in length. The DEFAULT used if the user does not provide a value when
prompted and instead hits the ENTER key is JOY. The prompt at the command line
when the ACCEPT command is issued is as defined: Enter Last Name [JOY]:. In this
case the default is included as part of the prompt. The HIDE option does not echo
what the user enters as the value for lname on the console.
The following example shows the ACCEPT command being used in a CLPPlus script
file and the different methods in which a value can be assigned to the defined
variable. Consider the following script named average_salary.sql which finds the
average salary of an employee in the given department:
ACCEPT dept_id PROMPT "Enter Department ID code : "
SELECT AVG(salary) FROM employee WHERE workdept = &dept_id;
The script can be called in two different ways, with and without arguments.
When called with arguments, the variable is assigned the value of the argument
passed at the time of invocation:
SQL> start average_salary ’E21’
When called without arguments, the user interaction is required to assign a value
to the variable:
SQL> start average_salary
Enter Department ID code : ’E21’
APPEND
The APPEND CLPPLus command adds text to the end of the current line in the SQL
buffer. You can use this command to build commands and statements in the SQL
buffer.
This is a line editor command and can be used to build commands in the SQL
buffer.
Authorization
None
Required connection
None
Command syntax
►► APPEND text-string ►◄
A
Command parameters
text-string
Specifies a string of characters to append. The string can include spaces and
special characters. The case of the string is preserved.
Examples
In the following example, the APPEND command appends the string this text is
appended. to the end of the current line in the SQL buffer:
APPEND this text is appended.
The following example shows how you can use the APPEND command to build a
SELECT statement in the SQL buffer. Two spaces are placed between the APPEND
command and the WHERE clause to separate DEPT and WHERE by one space in the
SQL buffer.
SQL> APPEND SELECT * FROM DEPT
SQL> LIST
1* SELECT * FROM DEPT
SQL> APPEND WHERE DEPTNO = 10
SQL> LIST
1* SELECT * FROM DEPT WHERE DEPTNO = 10
The LIST command displays the contents of the SQL buffer as the SQL statement is
being built.
BREAK
The BREAK CLPPlus command inserts a page break or blank lines at the specified
point in a result set.
Invocation
You must run this command from the CLPPlus interface.
Authorization
None
Command syntax
►► BREAK ON column-name ►◄
SKIP
PAGE
number-of-lines
Command parameters
column-name
Specifies the column used to determine a break.
SKIP PAGE | number-of-lines
Where number-of-lines is an integer.
When SKIP PAGE is appended to the command the output breaks and continues
on the next page. When SKIP number-of-lines is appended to the command, the
output breaks and blanks lines equal to the number-of-lines specified are
inserted in the result set.
Example
In the following example, when the SELECT statement is invoked and the value of
WORKDEPT changes from one row to another, the BREAK command is invoked and
the action specified is performed. In this case, since SKIP PAGE was specified, the
next row will be printed on the next page skipping the remainder of the current
page.
SQL> BREAK ON WORKDEPT SKIP PAGE;
SQL> SELECT * FROM EMPLOYEE ORDER BY WORKDEPT;
BTITLE
The BTITLE CLPPlus command inserts text at the bottom of each page displayed.
Invocation
You must run this command from the CLPPlus interface.
Authorization
None
Required connection
None
CENTER
►► BTITLE ▼ LEFT text ►◄
RIGHT PGNO SKIP integer-value
variable-name
Command parameters
text
Specifies the text to be displayed.
CENTER
Specifies the display will center justify the text on each page. If neither CENTER,
LEFT, or RIGHT is specified, center justification is the default behavior.
LEFT
Specifies the display will left justify the text on each page.
RIGHT
Specifies the display will right justify the text on each page.
PGNO
Specifies the current page number.
variable-name
Specifies a user defined variable that will follow the text field.
SKIP integer-value
The integer-value value specifies the number of blank lines displayed before the
bottom title.
Example
In the following example, the DEPT: (with the variable contents), CONFIDENTIAL, and
Page No: (with the current page number) is displayed across the bottom of every
page. Three blank lines follows the bottom title.
SQL> BREAK ON workdept SKIP PAGE;
SQL> COLUMN workdept OLD_VALUE old_dept;
SQL> BTITLE LEFT ’DEPT: ’ old_dept, CENTER ’CONFIDENTIAL, RIGHT ’Page No: ’ PGNO SKIP 3;
In the following example, the Page No: title (with the current page number) is
displayed across the bottom of every page with right justification. Two blank lines
follow the bottom title.
SQL> BTITLE RIGHT ’Page No: ’ PGNO SKIP 2;
CALL
The CALL CLPPlus command calls a stored procedure.
Invocation
You can use the CALL command to call a stored procedure with array parameters
when the stored procedure is on a Db2 server.
None
Required connection
None
Command syntax
►► CALL procedure_name ►◄
,
( ▼ argument )
argument:
parameter_value
?
,
ARRAY [ ▼ parameter_value ]
Command parameters
procedure_name
Specifies the procedure to call. If multiple stored procedures with the same
name are present, the specific procedure to invoke is chosen by using
procedure resolution. Procedure resolution involves identifying the target
procedure by its schema, the procedure name, and the number of parameters.
parameter_value
Specifies the argument value. Enclose all text values in single quotation marks.
? Specifies the OUT parameter placeholder.
ARRAY[ parameter_value1, parameter_value2, ... ]
Specifies the array parameter values. Enclose all text values in single quotation
marks.
Examples
In the following example, the SUM stored procedure with IN and OUT parameters is
created:
CREATE PROCEDURE SUM
(IN int1 integer, IN int2 integer, OUT int3 integer)
BEGIN
SET int3 = int1+int2;
END;
/
In the following example, the names user type and the find_student stored
procedure with array parameters are created:
CREATE TYPE names AS VARCHAR(20) ARRAY[50];
CREATE PROCEDURE find_student(IN students_in names,IN alphabet VARCHAR(1), OUT students_out names)
BEGIN
DECLARE i,j,max INTEGER;
SET i = 1;
SET j = 1;
SET students_out = NULL;
SET max = CARDINALITY(students_in);
WHILE i <= max DO
if substr(students_in[i], 1, 1) = alphabet THEN
SET students_out[j] = students_in[i];
SET j = j+1;
END IF;
SET i = i+1;
END WHILE;
END;
/
The find_student stored procedure is invoked to find the list of students whose
names start with the character A:
CALL find_student(ARRAY[’Alice’,’Bob’,’Derk’,’Peter’,’Alan’,’Clark’],’A’,?);
/
Values
---------------
’Alice’
’Alan’
CHANGE
The CHANGE CLPPlus command modifies specified content in the SQL buffer. If you
set the buffer reader to a specific line in the buffer, the command modifies only the
specified content in that line.
The CHANGE or C token is optional for the complete command when specifying
which line in the buffer you are changing. You can issue the command by
specifying only the line number in the buffer you want to change along with the
new text.
Invocation
None
Required connection
None
Command syntax
►► CHANGE ►◄
C / search-string / replacement-string /
n
Command parameters
n Specifies the line number in the buffer that will be changed. The n command
only takes the replacement-string variable.
search-string
Defines the text in the SQL buffer to be replaced or deleted. If the buffer
contains more than one line of text, specify the line to be modified by entering
the line number at the prompt before you run the CHANGE command.
If the text to search for contains an asterisk (*), enclose the asterisk in single
quotation marks.
replacement-string
Specifies the replacement text or specifies that text is to be removed. If you
specify a value for replacement-string, the first occurrence of the value of
search-string is replaced with the value of replacement-string. If you do not
specify a value for replacement-string, the first occurrence of the value of
search-string is removed.
If the replacement text contains an asterisk (*), you do not need to enclose an
asterisk (*) in single quotation marks.
Examples
In the following example, the LIST command displays the contents of the buffer. At
the SQL prompt, 3 is entered to move the buffer reader to the start of the third line
in the buffer. The third line becomes the new current line, as indicated by an
asterisk. The CHANGE command then replaces the occurrence of the string 20 with
the string 30. The LIST command then displays the modified text within the buffer.
SQL> LIST
1 SELECT EMPNO, ENAME, JOB, SAL, COMM
2 FROM EMP
3 WHERE DEPTNO = 20
4* ORDER by EMPNO
SQL> 3
3* WHERE deptno = 20
SQL> CHANGE /20/30/
3* WHERE DEPTNO = 30
SQL> LIST
1 SELECT EMPNO, ENAME, JOB, SAL, COMM
2 FROM EMP
3* WHERE DEPTNO = 30
4 ORDER by EMPNO
In the following example, the buffer contains the following single statement:
42 Db2 11.1 for Linux, UNIX, and Windows: CLPPlus Reference
SQL> SELECT EMPNO FROM EMPLOYEE
To change the statement so that EMPNO is replaced with *, 1 is entered to move the
buffer reader to the start of the first line in the buffer. The following CHANGE
command is issued:
SQL> CHANGE /empno/’*’/
The command output displays the line number followed by the new content for
that line.
You can use the CHANGE command to specify the line number in the buffer you
want to change, and what value you want to change it to.
SQL> SELECT *
2 FROM
3 EMPLOKEE ;
ERROR near line 1:
SQL0204N "SCHEMA.EMPLOKEE" is an undefined name.
SQL> LIST
1 SELECT *
2 FROM
3* EMPLOKEE
SQL> 3 EMPLOYEE
3* EMPLOYEE
SQL> LIST
1 SELECT *
2 FROM
3* EMPLOYEE
SQL> /
CLEAR
The CLEAR CLPPlus command removes the contents of the SQL buffer, deletes all
column definitions set by the COLUMN command, or clears the screen.
Invocation
You must run this command from the CLPPlus interface.
Authorization
None
Required connection
None
Command syntax
Command parameters
SCREEN | SCR
Removes all SQL commands, data currently displayed, and CLPPlus messages
from the screen. When the CLEAR command is entered with no options, the
default behavior clears the screen.
BREAKS | BRE ON column
Clears all breaks when no column is specified. When a column is specified, the
break associated with that column is cleared, all other breaks are left intact.
BUFFER | BUF and SQL
Deletes all text in the SQL buffer. You must specify both the BUFFER parameter
(or the BUF parameter) and the SQL parameter.
COLUMNS | COL
Removes column definitions in the SQL buffer.
COMPUTES | COMP ON column
Clears all compute definitions when no column is specified. When a column is
specified, the compute definition associated with that column is cleared, all
other compute definitions are left intact.
VARIABLES | VAR
Clears all defined bind variables.
COLUMN
The COLUMN CLPPlus command specifies character and numeric output formats for
columns in a table. Formats set by the COLUMN command remain in effect only for
the duration of the current session. You can change or clear format settings for the
same column more than once in the current session.
When you issue COLUMN for a specified column in a database, format settings are by
default displayed using the standard output of the CLPPlus interface.
Invocation
None
Required connection
None
Command syntax
►► COLUMN ►◄
column CLEAR | CLE
▼ ALIAS alias-name
FORMAT | FOR spec
HEADING | HEA text
FOLD_BEFORE
FOLD_AFTER
LIKE source-column
NEWLINE
NEW_VALUE variable-name
NULL text
OLD_VALUE variable-name
PRINT | NOPRINT
WRAPPED | TRUNCATED
JUSTIFY [ LEFT | RIGHT | CENTER ]
OFF
ON
Command parameters
column
Specifies the name of a table column to which formats are applied. If you do
not specify any parameters after column, default format settings apply. If you
do not specify any parameters after column, and you have set parameters for
the same column previously in this session, the last set of parameters assigned
to the column are again used.
ALIAS alias-name
Specifies and alias name for column. The maximum length of alias-name is 255
characters. The alias can be used in other commands such as: COMMAND, COMPUTE,
and COLUMN.
CLEAR | CLE
Changes all formatting settings for the specified column to their default values.
If you specify CLEAR, you cannot specify any parameters other than column.
FORMAT | FOR spec
Specifies the formats to apply to the specified column. There are two types of
columns: character columns and numeric columns.
For a character column, the value of spec is An, where n specifies the number of
characters that can be used to display the column. The data wraps if it is wider
than the specified width.
For numeric columns, the value of spec can be one or more of the following
characters:
$ Displays a leading dollar sign.
If loss of significant digits occurs due to overflow of the format settings, the #
character will be displayed.
HEADING | HEA text
Specifies a heading for the specified column.
FOLD_BEFORE
Before printing the values for the specified column, new line feed and carriage
return are provided for each row.
FOLD_AFTER
After printing the values for the specified column, new line feed and carriage
return are provided for each row.
LIKE source-column
The format and display attributes of source-column are applied to column.
NEWLINE
A synonym of FOLD_AFTER. After printing the values for the specified column,
new line feed and carriage return are provided for each row.
NEW_VALUE variable_name
Defines a variable that can hold the new value for a break column defined
using the BREAK command. The variable can be used with page top title TTITLE
command. The break column must be defined with the SKIP PAGE action.
The NEW_VALUE command can also be used in all places within the current
session. Similar to a substitution variable. Whenever you define a NEW_VALUE
variable for a column, CLPPlus creates a substitution variable with the
specified variable name. This variable is updated with the column value on
each column break.
NULL text
When the value for the specified column is NULL, the value specified for text
is printed. The maximum length of text is 255 characters.
OLD_VALUE variable_name
Defines a variable that can hold the old value for a break column defined
using the BREAK command. The variable can be used with page bottom title
BTITLE command. The break column must be defined with the SKIP PAGE
action.
The OLD_VALUE command can also be used in all places within the current
session. Similar to a substitution variable. Whenever you define a OLD_VALUE
variable for a column, CLPPlus creates a substitution variable with the
specified variable name. This variable is updated with the column value on
each column break.
PRINT | NOPRINT
Specifies whether console printing of a specified column is enabled or disabled.
WRAPPED | TRUNCATED
Specifies if column data is wrapped or truncated in the CLPPlus output if it
exceeds the specified format.
Examples
In the following example, the SET PAGESIZE command sets the maximum page
length to 9999, and the COLUMN command changes the display width of the JOB
column to five characters. The SELECT statement then prints specified columns in
the table.
SQL> SET PAGESIZE 9999
SQL> COLUMN JOB FORMAT A5
SQL> COLUMN JOB
COLUMN JOB ON
FORMAT A5
WRAPPED
SQL> SELECT EMPNO, ENAME, JOB FROM EMP;
14 rows received.
In the following example, the COLUMN command applies a numeric format to the
SAL column:
SQL> COLUMN SAL FORMAT $99,999.00
SQL> COLUMN
COLUMN JOB ON
FORMAT A5
WRAPPED
14 rows retrieved.
EMPNO
------
200340
******
000290
******
200330
******
000310
******
...
...
000030
******
000010
******
SQL>DEFINE
DEFINE HIGHEST_SAL = 000010
SQL> select EMPNO, FIRSTNME, MIDINIT, LASTNAME from employee where empno=&highest_sal;
EMPNO FIRSTNME MIDINIT LASTNAME
------ ------------ ------- ---------------
000010 CHRISTINE I HAAS
COMPUTE
The COMPUTE CLPPlus command executes a specified function on the aggregate
values of a defined column. The command works in conjunction with the BREAK
CLPPlus command.
Invocation
Authorization
None
Required connection
Command syntax
►► COMPUTE SUM LABEL text OF column1 ON column2 ►◄
MAX
MIN
AVG
COUNT
NUM
STD
VAR
Command parameters
SUM
The SUM function adds the aggregate values on the column specified.
MIN
The MIN function returns the smallest of the aggregate values on the column
specified.
MAX
The MAX function returns the largest of the aggregate values on the column
specified.
Example
CONNECT
The CONNECT CLPPlus command changes the user ID connected to a database,
connects to a different database, or does both. The command also displays the
result of the change.
Invocation
50 Db2 11.1 for Linux, UNIX, and Windows: CLPPlus Reference
This command must be run from the CLPPlus interface.
Authorization
None
Required connection
None
Command syntax
►► CONNECT connection_identifier ►◄
/
@ dsn_alias
connection_identifier:
user
/ password @hostname : port / database
@variable
with dsn_alias:
@ dsn_alias
using(accesstoken accesstoken-string)
using(apikey apikey-string)
Command parameters
Examples
In the same session, the connection is changed to the user name CLPPlus. For this
connection, localhost, 5444, and Db2 are maintained as the host, port, and database
values.
SQL> CONNECT CLPPlus/password
Connected to CLPPlus 1.1.0.10 (localhost:5444/db2) AS CLPPlus
In the following example, the login.sql file contains a variable definition that is
used to attempt a connection to a database. The login.sql file contains define
connStr = localhost:50000/sample and can be used in the CONNECT CLPPlus
command as follows:
SQL> CONNECT db2admin@connStr
COPY
The COPY CLPPlus command copies data from a source database and table to a
target database and table.
Invocation
You must run this command from the CLPPlus interface or from within a CLPPlus
script file.
Authorization
None
Required connection
None
Command Syntax
►► COPY FROM srcdb TO destdb ►
APPEND
CREATE
INSERT
REPLACE
► USING query ►◄
dest_table [(col1, col2, ...)]
srcdb, destdb:
connection_identifier
/
@ dsn_alias
connection_identifier:
user
/ password @ host : port / database
Examples
The following command copies the rows in the emp table in the db1 database and
appends them into the emp table in the db2 database.
COPY FROM u1@db1 TO u2@db2 APPEND emp USING SELECT * FROM emp;
The following command copies the rows in the emp table in the db1 database and
appends them into the emp table in the db2 database. Since the target table does
not exist in the database that is named db2, you must specify the table definition
in the command.
COPY FROM u1@db1 TO u2@db2 APPEND emp (EmpId integer, name varchar(20)) USING SELECT * FROM emp;
The following command copies the rows in the emp table in the db1 database,
creates the emp table in the db2 database, and inserts the rows into the newly
defined table in db2.
COPY FROM u1@db1 TO u2@db2 CREATE emp (EmpId integer, name varchar(20)) USING SELECT * FROM emp;
The following command copies the rows in the emp table in the db1 database and
inserts them into the emp table in the db2 database since the target table exists.
COPY FROM u1@db1 TO u2@db2 INSERT emp USING SELECT * FROM emp;
The following command copies the rows in the emp table in the db1 database,
re-creates the emp table in the db2 database, and replaces the rows.
COPY FROM u1@db1 TO u2@db2 REPLACE emp (EmpId integer, name varchar(20)) USING SELECT * FROM emp;
DEFINE
The DEFINE CLPPlus command creates a user variable, also called a substitution
variable, and specifies its value. The command also displays the value of one or
more user variables.
Invocation
Authorization
None
Required connection
None
Command syntax
►► DEFINE ►◄
DEF variable text
Command parameters
Example
In the following example, the DEFINE command defines the Db2, DEPT, and NAME
variables and then displays the values of all variables:
SQL> DEFINE DEPT = 20
SQL> DEFINE NAME = ’John Smith’
SQL> DEFINE DB2 = ’localhost:5445/sample’
SQL> DEFINE
DEFINE DB2 = "localhost:5445/sample"
DEFINE DEPT = "20"
DEFINE NAME = "John Smith"
Invocation
Authorization
None.
Required connection
None.
Command syntax
►► DEFINE_EDITOR ►◄
= editor_name
Command parameters
editor_name
Specifies the name of the editor for the current CLPPlus session.
Examples
Example to use the Vim editor
You can set the editor to Vim with the following command:
SQL> DEFINE_EDITOR=vim
Example to use the Notepad++ editor
You can set the editor to Notepad++ with the following command:
DEL
The DEL command deletes one or more lines from the SQL buffer.
Invocation
Authorization
None
Required connection
None
Command syntax
*
►► DEL ►◄
n
n m
n *
n LAST
n L
* n
* LAST
* L
Command parameters
You can use the parameters to specify the start and end of a range of lines to
delete from the SQL buffer. If you do not specify any parameters, the current line
is deleted.
n Specifies a line number.
n m
Specifies two line numbers, where the value of m is greater than the value of n.
* Indicates the current line.
LAST | L
Indicates the last line in the SQL buffer.
In the following example, the fifth line, containing column SAL, and the sixth line,
containing column COMM, are deleted from the SELECT statement in the SQL
buffer:
SQL> LIST
1 SELECT
2 EMPNO
3 ,ENAME
4 ,JOB
5 ,SAL
6 ,COMM
7 ,DEPTNO
8* FROM EMP
SQL> DEL 5 6
SQL> LIST
1 SELECT
2 EMPNO
3 ,ENAME
4 ,JOB
5 ,DEPTNO
6* FROM EMP
The contents of line 7 becomes the contents of line 5, and the contents of line 8
becomes the contents of line 6. The contents of the current line have not changed,
but the current line, marked with an asterisk, has changed from line 8 to line 6.
DESCRIBE
The DESCRIBE CLPPlus command displays a list of columns and their data types
and lengths for a table view; a list of parameters for a procedure or function; or a
list of procedures and functions and their parameters for a package.
The DESCRIBE CLPPlus command allows you to specify type of database object you
want to describe. If you do not specify the type of object you want to describe,
then all objects that are found with the given name and schema are described. The
default schema is CURRENT SCHEMA.
The DESCRIBE CLPPlus command supports temporal tables. Temporal tables are
new for Db2 for z/OS Version 10.
Invocation
You can run this command from the CLPPlus interface.
Authorization
None
Required connection
Command syntax
Command parameters
TABLE
Specifies that the type of database object to be described is a table.
VIEW
Specifies that the type of database object to be described is a view.
ALIAS
Specifies that the type of database object to be described is a alias.
PROCEDURE
Specifies that the type of database object to be described is a procedure.
FUNCTION
Specifies that the type of database object to be described is a function.
SYNONYM
Specifies that the type of database object to be described is a synonym.
PACKAGE
Specifies that the type of database object to be described is a package.
MODULE
Specifies that the type of database object to be described is a module.
schema
Specifies the name of the schema containing an object to be described. The
default schema is CURRENT SCHEMA.
object
Specifies the name of a table, view, procedure, function, or package to be
described.
Example
In the following example, the DESCRIBE command is run to get details on the table
named ABCD.
SQL> DESCRIBE TABLE ABCD ;
TABLE - ABCD
SQL> ALTER TABLE policy ADD VERSIONING USE HISTORY TABLE policy_hist;
********************************************************************************
In the following example, the DESCRIBE command is run to get details on a table
with system period, but not versioned.
SQL> create table demo_nontemp
(
policy_id int NOT NULL,
coverage int NOT NULL IMPLICITLY HIDDEN,
system_start TIMESTAMP(12) generated always as row begin NOT NULL,
system_end TIMESTAMP(12) generated always as row end NOT NULL,
trans_start generated always as transaction start ID,
period SYSTEM_TIME (system_start, system_end)
);
********************************************************************************
TABLE - DEMO_APP
********************************************************************************
********************************************************************************
In the following example, the DESCRIBE command is run to get details on a system
period temporal table.
SQL> create table demo_sys
(
policy_id int NOT NULL,
coverage int NOT NULL IMPLICITLY HIDDEN,
system_start TIMESTAMP(12) generated always as row begin NOT NULL,
SQL> ALTER TABLE DEMO_SYS ADD VERSIONING USE HISTORY TABLE DEMO_SYS_HISTORY;
TABLE - DEMO_SYS
********************************************************************************
********************************************************************************
DISCONNECT
The DISCONNECT CLPPlus command closes the current database connection but does
not exit the CLPPlus session.
Invocation
Authorization
None
Required connection
Command syntax
►► DISCONNECT ►◄
DISC
CLPPlus reads the EDITOR and PATH system environment variables to establish
which external editor is used when the EDIT command is started. Any editor of
your choice can be specified in the EDITOR system environment variable provided it
is installed on the system. The location of the binary file for the external editor
specified in the EDITOR system environment variable location must be included in
your PATH system environment variable. If these variables are not set or not set
properly, the default editor used on Windows operating systems is Notepad. On
UNIX and Linux operating systems, it is vi.
Invocation
Authorization
None
Required connection
None
Command syntax
►► EDIT ►◄
ED path filename
Command parameters
path
Specifies the path, either absolute or relative, to the file specified by the
filename variable. If no path is specified, the current directory is used.
filename
Specifies the name of the file to open. If you do not specify a file extension, the
.sql extension is used. If you do not specify the filename parameter, the
contents of the SQL buffer are brought into the editor.
The EDIT command is supported in the CLPPlus window mode. The command is
not supported in the CLPPlus non-window mode.
Invocation
You must run the EXPORT command from the CLPPlus interface.
Authorization
None.
Restrictions
The options such as DATAOBJECT, which are not supported with transient external
tables, cannot be specified in the OPTIONS clause of the EXPORT command.
Command syntax
►► EXPORT EXTERNAL TO ' filename ' ►
OPTIONS (options-string)
► ►◄
select-statement
Command parameters
EXTERNAL
Specifies that the EXPORT command uses external table operations.
OPTIONS options-string
Specifies the options that control the processing of the export operation. These
are described in CREATE EXTERNAL TABLE.
TO filename
Specifies the name of the file to which data is to be exported. If the file already
exists, the contents of the file are overwritten, not appended to. The name
must be specified in single quotes.
Select-statement
Specifies the SELECT statement that is to return the data that is to be exported.
Example
The following command exports the content of the Employees table on the server
to the Employees.txt file in Swift Object Store:
SQL> Export external to ’Employees.txt’
options(s3(’s3.amazonaws.com’, ’AKIA99999999999999999’, ’783nGlH12345678910’, ’db2.s3.qa.us-east
"DELIMITER ’,’ LOGDIR ’/home/user’) select * from employees;
The following command exports the content of the Employees table on the server
to the Employees.txt file in an AWS S3 object store:
SQL> Export external to ’Employees.txt’
options(swift(’default’, ’IBMOS28999999999’, ’b107aa9172c70f8df16’, ’db2_dev’)
DELIMITER ’,’ LOGDIR ’/home/user/’) select * from employees;
The following command exports the content of the Employees table on the server
to the Employees.txt file on the client location:
SQL> Export external to ’C:\Employees.txt’
options(’maxerrors 20 REMOTESOURCE ’JDBC’ LOGDIR ’/home/user’) select * from employees;
The following command exports the content of the Employees table on the server
to the Employees.txt file on the server location:
SQL> Export external to ’/home/user/Employees.txt’
options(maxerrors 20) select * from employees;
Invocation
You must run this command from the CLPPlus interface.
Authorization
You must ensure that the user ID that is used to run the EXECUTE CPPPlus
command has one of the following privileges:
v EXECUTE privilege on the procedure
v DATAACCESS authority
If a matching procedure exists that the authorization ID of the statement is not
authorized to run, an error is returned (SQLSTATE 42501).
Required connection
Command syntax
►► EXECUTE procedure-name ; ►◄
EXEC , /
( ▼ argument )
PL/SQL-statement
variable-definition
argument:
expression
parameter-name DEFAULT
NULL
Command parameters
procedure-name
Specifies the procedure to call. The procedure must be cataloged. For Db2 data
servers, you can qualify the name with a schema name, a module name, or
both a schema name and a module name. The procedure to run is chosen by
the procedure resolution algorithm. For Db2databases, the execution of the
EXECUTE command, including procedure resolution, is the same as the
Db2CALL statement.
PL/SQL-statement
Specifies the PL/SQL statement to run.
variable-definition
Specifies the definition of a variable.
argument
Note: You cannot display the following output data type values in the
CLPPlus interface: row, array, associative array, and Boolean.
v INOUT parameter
– The value must be a single variable or parameter marker (SQLSTATE
42886).
– The value must be assignable to the parameter.
– The assignment of a string value uses the storage assignment rules on
invocation and the retrieval assignment rules on return.
Examples
1. The CREATE PROCEDURE statement creates a procedure that is called
save_tester_details_PROC. The EXECUTE command runs this procedure.
EXIT
The EXIT CLPPlus command ends the CLPPlus session and returns control to the
operating system. This command is synonymous with the QUIT command.
Invocation
Authorization
None
Required connection
None
Command syntax
SUCCESS COMMIT
►► EXIT ►◄
FAILURE ROLLBACK
WARNING
value
variable
:bindvariable
Command parameters
Examples
In the following example, the EXIT command is issued with the SUCCESS parameter.
SQL> exit success
You can review whether the return code indicates success by running the echo
%errorlevel% command.
echo %errorlevel%
0
In the following example, the EXIT command is issued with the WARNING and
COMMIT parameters.
SQL> exit warning commit
You can review the return code for by running the echo %errorlevel% command.
echo %errorlevel%
2
You can review the return code for by running the echo %errorlevel% command.
echo %errorlevel%
5
The EXPLAIN PLAN CLPPlus command is supported on Db2 for z/OS and IBM
Informix.
Invocation
Authorization
None
Required connection
You must be connected to a database.
Restrictions
Support on IBM Informix has these restrictions:
v Only SELECT statements are supported.
v You must create and specify a default sbspace name for the SBSPACENAME
configuration parameter in the ONCONFIG file. This sbspace is used for creating
BLOB objects when an explain plan is created.
v To retrieve statistics data from an Informix server, your user ID must have the
DBA privilege on the Informix database. Only user IDs with this privilege have
access to statistics data.
Syntax diagram
►► EXPLAIN PLAN FOR SQL-statement ►◄
Command parameters
SQL-statement
The SQL statement on which explain information is retrieved. For IBM
Informix only SELECT statements are supported.
Example
SQL> explain plan for select * from emp where bonus > 1000 and salary>10000;
GET
The GET CLPPlus command loads the contents of a text file into the CLPPlus SQL
buffer.
Authorization
None
Required connection
None
Command syntax
LIS
LIST
►► GET filename ►◄
path NOLIST
NOL
Command parameters
path
Specifies the path, either absolute or relative, to the file specified by the
filename variable. If no path is specified, the current directory is used.
filename
Specifies the name of the file to load into the SQL buffer. If you do not specify
a file extension, the .sql extension is used.
LIST | LIS
Displays the contents of the SQL buffer after the file is loaded.
NOLIST | NOL
Prevents the contents of the SQL buffer from being displayed after the file is
loaded.
HELP
The HELP command displays an index of topics for CLPPlus or it displays help for
a specific CLPPlus topic.
Invocation
Authorization
None
Required connection
None
Command syntax
Command parameters
INDEX
Displays an index all CLPPlus help topics.
topic
Displays help for a specific CLPPlus subject, for example, ACCEPT.
HOST
The HOST CLPPlus command runs an operating-system command in the CLPPlus
interface.
Invocation
Authorization
None
Required connection
None.
Command syntax
►► HOST os_command ►◄
HO
Command parameters
os_command
Specifies an operating-system command.
Invocation
You must run the IMPORT command from the CLPPlus interface.
Authorization
None
Required connection
Syntax diagram
Command parameters
filename
Specifies the file that contains the import data. You can specify a path as part
of the filename variable. The path can be absolute or relative to the current
directory. If the path is omitted, the current directory is searched.
COMMITCOUNT | COMMIT n
When specified, IMPORT commits data after every n records are read and
imported.
RESTARTCOUNT | RESTART n
When specified, IMPORT starts at record n+1. The first n records are skipped.
This option is functionally equivalent to SKIPCOUNT. RESTARTCOUNT and
SKIPCOUNT are mutually exclusive.
SKIPCOUNT | SKIP n
When specified, IMPORT starts at record n+1. The first n records are skipped.
This option is functionally equivalent to RESTARTCOUNT. RESTARTCOUNT and
SKIPCOUNT are mutually exclusive.
ROWCOUNT | ROW n
When specified, n physical records from the beginning of filename are
imported. When ROWCOUNT is specified with RESTARTCOUNT or SKIPCOUNT, IMPORT
reads n rows from filename starting from the record that is defined by
RESTARTCOUNT or SKIPCOUNT.
table_name
Specifies the target database table for the IMPORT operation. This table cannot
be a system table, a declared temporary table or a summary table. If not fully
qualified with a schema, the default schema is the current ID.
Examples
The following IMPORT command reads the first 100 rows of the c:\data.txt file and
inserts the data into the db2admin.emptab table:
import from c:\data.txt rowcount 100 insert into db2admin.emptab;
The following IMPORT command starts reading data at row 11 of the data.txt file,
one directory up in the directory tree relative to the current directory. The
command inserts the data into the emptab table.
import from ./data.txt restart 10 insert into emptab;
INPUT
The INPUT line-editor command adds a line of text to the SQL buffer after the
current line.
Invocation
Authorization
None
Required connection
None
Command syntax
►► INPUT text ►◄
I
Command parameters
text
Specifies the text to be inserted into the SQL buffer.
Example
LIST
The LIST line-editor command displays all of the lines or a range of lines in the
SQL buffer.
Authorization
None
Required connection
None
Command syntax
*
►► LIST ►◄
L n
n m
n *
n LAST
n L
* n
* LAST
* L
Command parameters
n Displays the specified line in the SQL buffer.
n m
Displays the specified range of lines in the SQL buffer, where the value of m is
greater than the value of n.
* Displays the current line in the SQL buffer.
LAST | L
Displays the last line in the SQL buffer.
Example
In the following example, the L command used to show line buffer contents.
SQL> LIST
1 SELECT
2 *
3 FROM
4* EMPLOYEE
SQL> L2
2* *
SQL> L4
4* EMPLOYEE
SQL> L5
DB250400E: The buffer line number is invalid. Valid values can be between ’1’ and ’4’.
SQL>
In the following example, a variant of the LIST command is used to show line
buffer contents.
SQL> begin
2 dbms_output.put_line(’list command ’);
3 end;
4 /
SQL> list
1 begin
2 dbms_output.put_line(’list command ’);
3* end
SQL> 2
2* dbms_output.put_line(’list command ’);
SQL>
Note in the previous example how the number 2 is entered on its own in. The
result is the contents of line buffer 2 is displayed. You can enter any valid line
number in the buffer to display the contents of the line.
Invocation
You must run the LOAD command from the CLPPlus interface.
Authorization
None
Required connection
Command syntax
►► LOAD EXTERNAL FROM filename ►
pipename NOT LOGGED INITIALLY
► ►
OPTIONS ( options-string )
► INTO table-name ►◄
( insert-column-names )
Command parameters
EXTERNAL
Specifies that the LOAD command uses external table operations.
FROM filename or pipename
Specifies the file or pipe that contains the data that is being loaded.
NOT LOGGED INITIALLY
Data that is loaded into the table by a LOAD operation that is in the same unit
of work is not logged.
OPTIONS(options-string)
Specifies the external table options that control the processing of the LOAD
operation. Refer to the target server's external table options for details.
Usage notes
LOG and BAD files contain information about records that are successfully loaded,
rejected, or skipped. The location of these files depends on the location of the
server:
Remote server (REMOTESOURCE 'LOCAL' is not specified)
LOGDIR specifies the directory to which ~.log and ~.bad files are
generated. If log and bad files are generated, the server returns the full
path to store them by including the specified LOGDIR in the log and bad
file path that is returned to the driver.
If the LOGDIR option is not defined, the JDBC driver’s output directory is
used to store the log and bad files. This default output directory is the
operating system default temp directory or the configured
db2.jcc.outputDirectory directory.
Local server (REMOTESOURCE 'LOCAL' is specified)
LOGDIR specifies the directory to which ~.log and ~.bad files are
generated. When used with SWIFT or S3, the files are located in the object
store where the paths of the log and bad files are relative to the top of the
bucket or container.
ERROR_LOG can be used as a synonym for the LOGDIR option. If the LOGDIR
option is not defined, then the default location is the location of the data files.
Draft comment
I've omitted the bullet about "invalid syntax returns an error". That's
obvious
If the server or JCC driver returns an error message, then the result of LOAD
command displays the same error message in the CLP.
Draft comment
The preamble of this example mentions ain input file
C:\data\et.txt. However, the path is the LOAD command refers to
/home/regres1/et/et1.txt. Is this correct? Or is one of these
filepaths incorrect?
Draft comment
The preamble of this example mentions ain input file
C:\data\et.txt. However, the path is the LOAD command refers to
/home/regres1/et/et1.txt. Is this correct? Or is one of these
filepaths incorrect?
Draft comment
The preamble of this example mentions ain input file
C:\data\et.txt. However, the path is the LOAD command refers to
/home/regres1/et/et1.txt. Is this correct? Or is one of these
filepaths incorrect?
Invocation
You must run the LOAD command from the CLPPlus interface.
Authorization
Required connection
Command syntax
►► LOAD "<filename>" LOADSTMT "<loadstmt>" UTILITYID "<utilityid>" ►
► VERBOSE ON ►◄
OFF
Command parameters
filename
File from which data is to be loaded. The parameter value has to be enclosed
in double quotes.
LOADSTMT
Load statement. User can directly specify the LOADSTMT in the command, or
write the LOADSTMT in a file and specify the complete path of the file. This
parameter value has to be enclosed in double quotes. Refer to Syntax and
options of the LOAD control statement for a detailed definition on LOADSTMT
UTILITYID
Specifies the utility-id for LOAD operation. This is an optional parameter. This
parameter value has to be enclosed in double quotes. If the driver returns
java.sql.SQLException, CLPPlus will display the same. If the driver returns
java.sql.SQLException, CLPPlus will display the same.
VERBOSE
Specifies whether CLPPlus should display the LOAD result on console. This is an
optional parameter. The default value for this parameter is ON. Unless the user
specifies verbose as OFF, CLPPlus will display the LOAD result on the console. If
the CLPPlus tracing is enabled, verbose will be put into the trace file
irrespective of the value specified for verbose.
Example
The following LOAD command loads the data from block.cust.del into Db2 for
z/OS serve:
SQL> load file "C:\Users\IBM_ADMIN\Desktop\CLPPlus_Deliver\zFastLoadTesting\block.cust.del"
loadstmt "TEMPLATE SORTIN DSN &JO..&ST..SORTIN.T&TIME. UNIT SYSVIO SPACE(10,10) CYL DISP(NEW,DEL
TEMPLATE SORTOUT DSN &JO..&ST..SORTOUT.T&TIME. UNIT SYSVIO SPACE(10,10) CYL DISP(NEW,DELETE,DELE
LOAD DATA INDDN SYSCLIEN WORKDDN(SORTIN,SORTOUT)
REPLACE PREFORMAT LOG(NO) REUSE NOCOPYPEND FORMAT DELIMITED EBCDIC INTO TABLE ADMF001.CUSTOMER_L
The following LOAD command loads the data from block.cust.del into Db2 for
z/OS server. LOADSTMT is read from a file loadStatement.txt, and VERBOSE is ON:
SQL> Load file "C:\Users\IBM_ADMIN\Desktop\CLPPlus_Deliver\zFastLoadTesting\block.cust.del" loadstmt
Return Code : 0
PAUSE
The PAUSE CLPPlus command suspends CLPPlus processing, optionally displays a
message, and waits to resume processing until the ENTER key is pressed.
Invocation
Authorization
None
Required connection
You must be connected to a database.
Command syntax
►► PAUSE optional-text ►◄
PAU
PRINT
The PRINT CLPPLus command displays the value of a bind variable. Bind variables
are used in place of literal values. If you issue a SELECT statement multiple times,
you can use bind variables to reduce the number of literal values.
Invocation
You can run this command in the CLPPlus interface.
Authorization
None
Required connection
Command syntax
►► PRINT bind-variable-name ►◄
PRI
Command parameters
bind-variable-name
Specifies a string of characters that can include spaces and special characters. If
you do not specify bind-variable-name, the values of all bind variables are
printed.
If bind-variable-name is of the datatype REFCURSOR, the result set pointed to by
bind-variable-name will be read in its entirety and all the rows will be printed
following the report formatting specified in the current CLPPlus session.
PROMPT
The PROMPT CLPPlus command prints a line to the display.
Invocation
Authorization
None
None
Command syntax
►► PROMPT optional-text ►◄
PRO
pro
Command parameters
optional-text
Specifies a message. The message is a string of characters that can include
spaces and special characters. If you use quotation marks around the message,
it is included in the command output or statement output. The case of letters is
maintained.
QUIT
The QUIT CLPPlus command ends the CLPPlus session and returns control to the
operating system. This command is synonymous with the EXIT command.
Invocation
You must run this command from the CLPPlus interface.
Authorization
None
Required connection
None
Command syntax
SUCCESS COMMIT
►► QUIT ►◄
FAILURE ROLLBACK
WARNING
value
sub-variable
Command parameters
SUCCESS
Returns an operating system-dependant return code indicating success.
FAILURE
Returns an operating system-dependant return code indicating failure.
WARNING
Returns an operating system-dependant return code indicating a warning.
REMARK
The REMARK CLPPlus command allows for the coding of a comment in a script. This
is similar to a comment line coded with two dashes.
Invocation
You must run this command from the CLPPlus interface. It can only be included in
CLPPlus scripts.
Authorization
None
Required connection
None
Command syntax
►► REMARK optional-text ►◄
REM
Command parameters
optional-text
Specifies a string of characters that can include spaces and special characters.
You can use the convention shown in the following example.
/*
* This is a three-line comment
*/
REORGCHK
The REORGCHK CLPPlus command calculates statistics on the database to determine
whether tables or indexes, or both, must be reorganized or cleaned up.
Invocation
You must have SELECT privilege on the catalog tables. You must have EXECUTE
privilege on the REORGCHK_IX_STATS procedure.
Restriction
Required connection
Syntax diagram
►► REORGCHK ON TABLE USER ►◄
SYSTEM
ALL
table-name
SCHEMA schema-name
Command parameters
TABLE [ USER | SYSTEM | ALL | table-name]
Where USER checks the tables that are owned by the authorization ID at
runtime, SYSTEM checks the system tables, ALL checks all user and system
tables, and table-name specifies which table to check. When you use table-name,
the fully qualified name or alias must be used, for example, schema.tablename.
The schema is the user name under which the table was created. If the table
specified is a system catalog table, the schema is SYSIBM. For typed tables, the
specified table name must be the name of the root table of the hierarchy.
SCHEMA schema-name
Checks all the tables that are created under the specified schema.
Example
1. This example performs REORGCHK on system tables.
SQL> reorgchk on table system
2. This example performs REORGCHK on table EMPLOYEE under schema
manshanb.
SQL> reorgchk on table manshanb.EMPLOYEE
3. This example performs REORGCHK on all user and system tables.
SQL> reorgchk on table all
4. This example performs REORGCHK the tables that are owned by the runtime
authorization ID.
SQL> reorgchk on table user
5. This example performs REORGCHK on schema named manshanb.
SQL> reorgchk on schema manshanb
REPFOOTER
The REPFOOTER CLPPlus command prints a report footer at the end of a report.
Authorization
None
Required connection
None
Command syntax
,
CENTER
►► REPFOOTER ▼ LEFT text ►◄
RIGHT SKIP PAGE
number-of-lines
Command parameters
text
Specifies the text displayed at the end of a report.
CENTER
Specifies the display will center justify the report footer. If neither CENTER, LEFT,
or RIGHT is specified, center justification is the default behavior.
LEFT
Specifies the display will left justify the text for the report footer.
RIGHT
Specifies the display will right justify the text for the report footer.
SKIP
PAGE
Specifies the report footer is displayed on the next new page.
number-of-lines
Specifies the number of lines to skip.
Example
In the following example, the report footer END SALARY REPORT is displayed with
center justification at the end of the report on the next new page.
SQL> REPFOOTER CENTER ’END SALARY REPORT’ SKIP PAGE;
In the following example, the report footer Company Name is displayed, two lines are
skipped, then End of Report is displayed all with center justification on the next
new page.
SQL> REPFOOTER CENTER "Company Name" SKIP 2, CENTER "End of Report" SKIP PAGE
Invocation
Authorization
None
Required connection
None
Command syntax
,
CENTER
►► REPHEADER ▼ LEFT text ►◄
RIGHT SKIP PAGE
number-of-lines
Command parameters
text
Specifies the text displayed for the report header.
CENTER
Specifies the display will center justify the report header. If neither CENTER,
LEFT, or RIGHT is specified, center justification is the default behavior.
LEFT
Specifies the display will left justify the text for the report header.
RIGHT
Specifies the display will right justify the text for the report header.
SKIP
PAGE
Specifies the report header is displayed and the report data starts on the next
new page.
number-of-lines
Specifies the number of lines to skip.
Example
In the following example, the report header SALARY REPORT is displayed with left
justification and the report data starts on the next new page.
SQL> REPHEADER LEFT ’SALARY REPORT’ SKIP PAGE;
In the following example, the report header COMPANY NAME is displayed, two lines
are skipped, and then SALARY REPORT is displayed all with center justification. The
report data starts on the next new page.
RUN
The RUN CLPPlus command runs a SQL query or a PL/SQL command that is
stored in the SQL buffer.
Invocation
You must run this command from the CLPPlus interface.
Authorization
None
Required connection
Command syntax
►► RUN ►◄
Example
In the following example, the contents of the SQL buffer is populated with the
SELECT EMPNP FROM EMP statement.
SQL> APPEND SELECT EMPNP FROM EMP
SAVE
The SAVE line-editor command stores the contents of the SQL buffer in a new or
existing file.
Invocation
You must run this command from the CLPPlus interface.
Authorization
None
None
Command syntax
►► SAVE filename ►◄
SAV path CREATE
CRE
REPLACE
REP
APPEND
APP
Command parameters
path
Specifies the path, either absolute or relative, to the file used. If no path is
specified, the current directory is used.
filename
Specifies the name of a file to which the buffer contents are written. If you do
not provide a file extension, the .sql extension is used.
CREATE | CRE
Creates the specified file if it does not exist.
REPLACE | REP
Overwrites the specified file.
APPEND | APP
Adds the contents of the SQL buffer to the end of the specified file.
SET
The SET CLPPlus command controls a session-level variable for the CLPPlus
interface.
Important:
v For each invocation of the SET command, you can specify only one parameter.
v In a batch script, you can issue several SET commands in a series.
Invocation
Authorization
None
Required connection
None
Command syntax
► ►
AUTOTRACE ON EXPLAIN STATISTICS BGCOLOR color
AUTOT OFF EXP STAT r,g,b
TRACEONLY
TRACE
► ►
COLOR color COLSEP column-separator DUPLICATES ON ECHO ON
r,g,b OFF OFF
► ►
ENCODING encoding-format ON ESCAPE ON
ENVARSUBSTITUTION OFF OFF
ENVARSUBST character
► ►
FEEDBACK ON FLUSH ON FONT name , style , size
FEED OFF FLU OFF
row-threshold
► ►
HEADING ON HEADSEP LOGMODE logmode-value
HEAD OFF HEADS
HEA
► ►
JCCLOGMODE jcclogmode-value LINESIZE width-of-line LOCALE locale_name
LIN
► ►
LOGPATH log-path LONG integer-value NEWPAGE lines-per-page
NEWP
► ►
NULL null-string NUMFORMAT format-string OFF
NUMWIDTH
integer-value
► ►
PAGESIZE lines-per-page SQLCASE MIXED PAUSE ON
PAGES SQLC MIX PAU OFF
UPPER
UP
LOWER
LO
► ►
TRUE RECSEP ON RECSEPCHAR character
PRESERVEWHITESPACE FALSE OFF
► ►
SQLPROMPT prompt TERMOUT ON TIMING ON
SQLP TERM OFF TIMI OFF
► ►
TRIMOUT ON TRIMSPOOL ON UNDERLINE ON VERBOSE ON
TRIMO OFF TRIMS OFF OFF OFF
► ►◄
VERIFY ON WRAP ON
VER OFF OFF
Command parameters
ARRAYSIZE integer-value
Defines the number of rows that are fetched at a time from the server. You can
use this parameter to tune query performance. Valid values are 1 - 10000. The
default value is 10.
AUTOCOMMIT | AUTO
Controls the commit behavior of SQL statements in CLPPlus. CLPPlus always
automatically commits DDL statements.
ON | IMMEDIATE
Enables automatic commitment of SQL statements.
OFF
Disables automatic commitment of SQL statements except for DDL
statements.
OFFALL
Disables automatic commitment of SQL statements.
AUTOTRACE | AUTOT
Controls the display of explain plans and statistics information for SQL
statements in a CLPPlus session.
The AUTOTRACE parameter is supported on Db2 for z/OS. The AUTOTRACE
parameter is also supported on IBM Informix, with these restrictions:
v The EXPLAIN option is supported only for SELECT statements.
v If you specify the EXPLAIN, option, you must create and specify a default
sbspace name for the SBSPACENAME configuration parameter in the ONCONFIG
file. This sbspace name is used for creating BLOBs when an explain plan is
created.
v To retrieve statistics from an Informix server, you must have the Informix
privilege or an equivalent privilege.
ON Enables AUTOTRACE. If you set the AUTOTRACE parameter to ON, CLPPlus
continues to display the explain information until the session ends or until
you set the AUTOTRACE parameter to OFF.
OFF
Disables AUTOTRACE.
SPOOL
You can use the SPOOL CLPPlus command to log CLPPlus command and its output
to a file. The output file uses UTF-8 encoding.
Authorization
None
Required connection
None
Command syntax
►► SPOOL ►◄
SP path output_file
OFF
Command parameters
path
Specifies the path, either absolute or relative, to the output file. If you do not
specify a path, the current directory is used.
output_file
Causes the CLPPlus command and its output to be logged in the file that is
specified by the output_file variable instead of being displayed in the CLPPlus
standard output.
OFF
Causes the CLPPlus command and its output to be displayed in the CLPPLus
standard output, which is the default behavior.
SHOW
The SHOW CLPPlus command displays the current settings of session-level variables
in the CLPPlus interface or errors returned from server-side procedures. The
settings are controlled using the SET command.
Invocation
You must run this command from the CLPPlus interface.
Authorization
None
Required connection
None
100 Db2 11.1 for Linux, UNIX, and Windows: CLPPlus Reference
Command syntax
►► SHOW { } ►◄
SHO setting
ALL
ERRORS
procedure-name
Command parameters
setting
Displays the name and setting of the specified session-level variable.
ALL
Displays the names and settings of all session-level variables.
ERRORS
Displays the errors for all server-side procedures run in the current CLPPlus
session.
procedure-name
When appended to the SHOW ERRORS command, shows only the errors for
procedure-name.
START
The START CLPPlus command runs a CLPPlus script file.
Invocation
Authorization
None
Required connection
None
Command syntax
►► START script-file ►◄
STA path
URL
Command parameters
path
Specifies the path, either absolute or relative, to the script file that contains
SQL statements and commands to run. If no path is specified, the current
directory is used.
URL
Specifies the URL to the script file that contains SQL statements and
commands to run. The URL must start with http:// or https://.
Example
This example shows CLPPlus starting a script named demo.sql found on the
computer with IP address 9.124.159.144.
SQL> Start http://9.124.159.144/demo.sql
TTITLE
The TTITLE CLPPlus command inserts text at the top of each page displayed.
Invocation
Authorization
None
Required connection
None
Command syntax
,
CENTER
►► TTITLE ▼ LEFT text ►◄
RIGHT PGNO SKIP integer-value
variable-name
Command parameters
text
Specifies the text to be displayed.
CENTER
Specifies the display will center justify the text on each page. If neither CENTER,
LEFT, or RIGHT is specified, center justification is the default behavior.
LEFT
Specifies the display will left justify the text on each page.
RIGHT
Specifies the display will right justify the text on each page.
PGNO
Specifies the current page number.
variable-name
Specifies a user defined variable that will follow the text field.
SKIP integer-value
The integer-value value specifies the number of blank lines displayed after the
top title.
102 Db2 11.1 for Linux, UNIX, and Windows: CLPPlus Reference
Example
In the following example, the DEPT: (with the variable contents), CONFIDENTIAL, and
Page No: (with the current page number) is displayed across the top of every
page. One blank line follows the top title.
SQL> BREAK ON workdept SKIP PAGE;
SQL> COLUMN workdept NEW_VALUE new_dept;
SQL> TTITLE LEFT ’DEPT: ’ new_dept, CENTER ’CONFIDENTIAL’, RIGHT ’Page No: ’ PGNO SKIP 1;
In the following example, the Page No: title (with the current page number) is
displayed across the top of every page with right justification. Two blank lines
follow the top title.
SQL> TTITLE RIGHT ’Page No: ’ PGNO SKIP 2;
UNDEFINE
The UNDEFINE CLPPlus command clears and deletes a variable created by the
DEFINE CLPPlus command.
Invocation
You must run this command from the CLPPlus interface.
Authorization
None
Required connection
Command syntax
►► UNDEFINE ▼ variable-name ►◄
UNDEF
Command parameters
variable-name
Specifies the name of the variable to clear and delete.
WHENEVER OSERROR
The WHENEVER OSERROR CLPPlus command specifies the action the CLPPlus
interface performs when an operating system error occurs. You can use this
command to trap errors and control the CLPPlus interface behavior by performing
specified actions like EXIT or CONTINUE.
Invocation
The WHENEVER OSERROR command must be issued from the CLPPlus interface.
Authorization
None
None
Command syntax
NONE
►► WHENEVER OSERROR CONTINUE ►◄
COMMIT
ROLLBACK
SUCCESS COMMIT
EXIT
FAILURE ROLLBACK
value
variable
:bindvariable
Command parameters
CONTINUE
Directs the CLPPlus interface to continue with a specified action when an SQL
or PL/SQL error is encountered.
NONE
The default value that is used in the WHENEVER OSERROR CONTINUE command. No
action on the block of SQL generating an error is taken.
COMMIT
When COMMIT is specified in the WHENEVER OSERROR CONTINUE command, any
possible work that is done by the current SQL block is committed.
ROLLBACK
When ROLLBACK is specified in the WHENEVER OSERROR CONTINUE command, all
work in the current SQL block is rolled back.
EXIT
Directs the CLPPlus interface to exit once an operating system error is
encountered. The functionality of this option is the same as the stand-alone
EXIT command.
SUCCESS
Returns an operating system-dependant return code that indicates success. This
is the first default EXIT parameter.
FAILURE
Returns an operating system-dependant return code that indicates a failure.
value
Specifies a variable that is created by the DEFINE command whose value is
returned as the return code.
variable
Specifies a substitution variable value that is created by the DEFINE command
whose value is returned as the return code.
:bindvariable
Specifies a Bind variable value that is created by the DEFINE command whose
value is returned as the return code.
104 Db2 11.1 for Linux, UNIX, and Windows: CLPPlus Reference
COMMIT
Specifies that uncommitted updates are committed when the CLPPlus session
ends. This is the second default EXIT parameter.
ROLLBACK
Specifies that uncommitted updates are rolled back when the CLPPlus session
ends.
Examples
The following example shows the command behavior when EXIT and an exit error
value are specified.
SQL> whenever oserror exit -1
SQL> get c:\nonexistingfile.sql
DB250204E: An attempt to locate a file ’c:\\nonexistingfile.sql’ failed. The co
mmand cannot be processed.
You can review the return code for by running the echo %errorlevel% command.
echo %errorlevel%
-1
The following example shows the command behavior when CONTINUE is specified.
SQL> whenever oserror continue
SQL> get c:\nonexistingfile.sql
DB250204E: An attempt to locate a file ’c:\\nonexistingfile.sql’ failed. The co
mmand cannot be processed.
SQL>
WHENEVER SQLERROR
The WHENEVER SQLERROR CLPPlus command specifies the action CLPPlus performs
when an SQL error occurs in SQL or PL/SQL. This command allows you to trap
errors and control CLPPlus behavior by performing specified actions like EXIT or
CONTINUE.
Invocation
Authorization
None
Required connection
None
Command syntax
Command parameters
CONTINUE
Directs CLPPlus to continue with a specified action when an SQL or PL/SQL
error is encountered.
NONE
The default value used in the WHENEVER SQLERROR CONTINUE command. No
action on the block of SQL generating an error is taken.
COMMIT
When COMMIT is specified in the WHENEVER SQLERROR CONTINUE command, any
possible work done by the current SQL block is committed.
ROLLBACK
When ROLLBACK is specified in the WHENEVER SQLERROR CONTINUE command, all
work in the current SQL block is rolled back.
EXIT
Directs CLPPlus to exit once an SQL or PL/SQL error is encountered. The
functionality of this option is the same as the stand-alone EXIT command.
SUCCESS
Returns an operating system-dependant return code indicating success. The is
the first default EXIT parameter.
FAILURE
Returns an operating system-dependant return code indicating failure.
WARNING
Returns an operating system-dependant return code indicating a warning.
value
Specifies a variable created by the DEFINE command whose value is returned as
the return code.
variable
Specifies a substitution variable value created by the DEFINE command whose
value is returned as the return code.
:bindvariable
Specifies a Bind variable value created by the DEFINE command whose value is
returned as the return code.
COMMIT
Specifies that uncommitted updates are committed when the CLPPlus session
ends. The is the second default EXIT parameter.
106 Db2 11.1 for Linux, UNIX, and Windows: CLPPlus Reference
ROLLBACK
Specifies that uncommitted updates are rolled back when the CLPPlus session
ends.
Examples
The following example shows the WHENEVER SQLERROR CONTINUE command behavior.
The CLPPlus prompt is returned and CLPPlus is still available for use.
SQL> whenever sqlerror continue
SQL> select * from nonexistingtable;
SQL0204N "SCHEMA.NONEXISTINGTABLE" is an undefined name.
SQL>
You can also commit, rollback, or take no action whenever an SQL error occurs.
SQL> whenever sqlerror continue commit
SQL>
SQL> whenever sqlerror continue rollback
SQL>
SQL> whenever sqlerror continue none
SQL>
The following examples use the EXIT option to exit the CLPPlus application.
SQL> whenever sqlerror exit
SQL> select * from nonexistingtable;
SQL0204N "SCHEMA.NONEXISTINGTABLE" is an undefined name.
C:\>
The following specify the error code returned during exit. This behavior is
identical to the EXIT CLPPlus command.
SQL> whenever sqlerror exit success
SQL> whenever sqlerror exit failure
SQL> select * from nonexistingtable;
SQL0204N "SCHEMA.NONEXISTINGTABLE" is an undefined name.
C:\echo %errorlevel%
1
SQL> define exit_value=6
SQL> whenever sqlerror exit exit_value
SQL> select * from nonexistingtable;
SQL0204N "SCHEMA.NONEXISTINGTABLE" is an undefined name.
C:\echo %errorlevel%
6
Similar to the EXIT CLPPlus command, you can specify whether to commit or
rollback while exiting the CLPPlus application.
SQL> whenever sqlerror exit 2 commit
G U
GET command 70 UNDEFINE command 103
H W
HELP command WHENEVER OSERROR command 103
CLPPlus 70 WHENEVER SQLERROR command 105
HOST command 71
I
INPUT command 73
L
LOAD CLPPlus command using external
tables 75
LOAD command 79
log records
command line processor plus
(CLPPlus) 30
P
PAUSE command 81
PRINT command 82
PROMPT command 82
Q
QUIT CLPPLus command 83
R
REMARK command 84
REPFOOTER command 86
REPHEADER command 87
RUN command 88
S
SAVE command 88
Session
Global
CLPPlus 5
Variable 5
SET command 89
SHOW command 100
SPOOL command 100
START CLPPlus command 101
110 Db2 11.1 for Linux, UNIX, and Windows: CLPPlus Reference
IBM®
Printed in USA