This section provides information about using Structured Query Language (SQL) statements from the command line. These statements can be executed directly from an operating system command prompt, and can be used to define and manipulate information stored in a database table, index, or view in much the same way as if the commands were written into an application program. Information can be added, deleted, or updated, and reports can be generated from the contents of tables.
All SQL statements that can be executed through the command line processor are listed in the CLP column of Table 8. The syntax of all the SQL statements, whether executed from the command line or embedded in a source program, is described in the SQL Reference. The syntax of many embedded SQL statements and CLP SQL statements is identical. However, host variables, parameter markers, descriptor names, and statement names are applicable only to embedded SQL. The syntax of CLOSE, CONNECT, DECLARE CURSOR, FETCH, OPEN, and SELECT does depend on whether these statements are embedded or executed through the CLP. The CLP syntax of these statements is provided below:
>>-CALL----+-SQLJ.INSTALL_JAR--(--jar-url, jar-id--)--+-------->< +-SQLJ.REPLACE_JAR--(--jar-url, jar-id--)--+ +-SQLJ.REMOVE_JAR--(--jar-id--)------------+ '-SQLJ.REFRESH_CLASSES--(--void--)---------'
>>-CLOSE--cursor-name------------------------------------------><
>>-CONNECT------------------------------------------------------> >-----+---------------------------------------------------------------+> +-TO--server-name--+-----------------+---+--------------------+-+ | '-| lock-block |--' '-| authorization |--' | +-RESET---------------------------------------------------------+ | (1) | '-| authorization |---------------------------------------------' >-------------------------------------------------------------->< authorization |---USER--authorization-name------------------------------------> >-----+--------------------------------------------------------+-| +-USING--password--+-----------------------------------+-+ | '-NEW--password--CONFIRM--password--' | '-CHANGE PASSWORD----------------------------------------' lock-block .-IN SHARE MODE--------------------------. |---+----------------------------------------+------------------| '-IN EXCLUSIVE MODE--+----------------+--' '-ON SINGLE NODE-'
Notes:
>>-DECLARE--cursor-name--CURSOR---+-----------+-----------------> '-WITH HOLD-' >----FOR--select-statement-------------------------------------><
>>-FETCH--+------+--cursor-name---------------------------------> '-FROM-' >-----+-------------------------------------------------------+->< +-FOR--+-ALL-+---+-ROW--+-------------------------------+ | '-n---' '-ROWS-' | '-LOB--+-COLUMN--+---ALL--INTO--filename--+-APPEND----+-' '-COLUMNS-' +-NEW-------+ '-OVERWRITE-'
>>-OPEN--cursor-name-------------------------------------------><
fullselect |--+-subselect---------+----------------------------------------> +-(fullselect)------+ '-| values-clause |-' .---------------------------------------------------. V | >--------+---------------------------------------------+--+-----| '--+-UNION---------+---+-subselect---------+--' +-UNION ALL-----+ +-(fullselect)------+ +-EXCEPT--------+ '-| values-clause |-' +-EXCEPT ALL----+ +-INTERSECT-----+ '-INTERSECT ALL-' subselect |---select-clause--from-clause----------------------------------> >----+--------------+--+-----------------+--+---------------+---| '-where-clause-' '-group-by-clause-' '-having-clause-' select-clause .-ALL------. |---SELECT----+----------+--------------------------------------> '-DISTINCT-' >-----+-*----------------------------------------------+--------| | .-,-----------------------------------------. | | V | | '----+-expression--+----------------------+-+--+-' | | .-AS-. | | | '-+----+--column-name--' | +-table-name.*-------------------------+ +-view-name.*--------------------------+ '-correlation-name.*-------------------' values-clause .-,---------------------. V | |---VALUES-------| row-expression |---+-------------------------| row-expression |---+--+-expression-+---------------+---------------------------| | '-NULL-------' | | .-,-----------------. | | V | | '-(------+-expression-+--+---)--' '-NULL-------'
Notes:
For example:
db2 call sqlj.install_jar ( "file:///C:/java/jarfiles/myprocs.zip", "myprocs" )
For example, create and populate table t1 as follows:
create table t1 (i1 int , i2 int); insert into t1 values (1,1),(2,0),(3,null);
The statement: select i1/i2 from t1 generates the following result:
1 --- 1 + - 3 records selected |
Change the way that the CLP displays data (when querying databases using SQL statements through the CLP) by rebinding the CLP bind files against the database being queried. For example, to display date and time in ISO format, do the following:
db2clpcs.bnd + db2clprr.bnd + db2clpur.bnd + db2clprs.bnd + db2clpns.bnd
db2 bind @clp.lst collection nullid datetime iso
For detailed information about the command line processor, see Chapter 2, Command Line Processor (CLP). For more information about the syntax of SQL statements and the function provided by SQL statements, see the SQL Reference. For information about reading syntax diagrams, see Appendix A, How to Read the Syntax Diagrams.
Table 8. SQL Statements (DB2 Universal Database)
SQL Statement | Dynamic1 | Command Line Processor (CLP) | Call Level Interface3 (CLI) | SQL Procedure | ||
---|---|---|---|---|---|---|
ALLOCATE CURSOR | X | |||||
assignment statement | X | |||||
ASSOCIATE LOCATORS | X | |||||
ALTER { BUFFERPOOL, NICKNAME,10 NODEGROUP, SERVER,10 TABLE, TABLESPACE, USER MAPPING,10 TYPE, VIEW } | X | X | X | |||
BEGIN DECLARE SECTION2 | ||||||
CALL | X9 | X4 | X | |||
CASE statement | X | |||||
CLOSE | X | SQLCloseCursor(), SQLFreeStmt() | X | |||
COMMENT ON | X | X | X | X | ||
COMMIT | X | X | SQLEndTran, SQLTransact() | X | ||
Compound SQL (Embedded) | X4 | |||||
compound statement | X | |||||
CONNECT (Type 1) | X | SQLBrowseConnect(), SQLConnect(), SQLDriverConnect() | ||||
CONNECT (Type 2) | X | SQLBrowseConnect(), SQLConnect(), SQLDriverConnect() | ||||
CREATE { ALIAS, BUFFERPOOL, DISTINCT TYPE, EVENT MONITOR, FUNCTION, FUNCTION MAPPING,10 INDEX, INDEX EXTENSION, METHOD, NICKNAME,10 NODEGROUP, PROCEDURE, SCHEMA, TABLE, TABLESPACE, TRANSFORM TYPE MAPPING,1 TRIGGER, USER MAPPING,10 TYPE, VIEW, WRAPPER10 } | X | X | X | X11 | ||
DECLARE CURSOR2 | X | SQLAllocStmt() | X | |||
DECLARE GLOBAL TEMPORARY TABLE | X | X | X | X | ||
DELETE | X | X | X | X | ||
DESCRIBE8 | X | SQLColAttributes(), SQLDescribeCol(), SQLDescribParam()6 | ||||
DISCONNECT | X | SQLDisconnect() | ||||
DROP | X | X | X | X11 | ||
END DECLARE SECTION2 | ||||||
EXECUTE | SQLExecute() | X | ||||
EXECUTE IMMEDIATE | SQLExecDirect() | X | ||||
EXPLAIN | X | X | X | X | ||
FETCH | X | SQLExtendedFetch()7, SQLFetch(), SQLFetchScroll()7 | X | |||
FLUSH EVENT MONITOR | X | X | X | |||
FOR statement | X | |||||
FREE LOCATOR | X4 | X | ||||
GET DIAGNOSTICS | X | |||||
GOTO statement | X | |||||
GRANT | X | X | X | X | ||
IF statement | X | |||||
INCLUDE2 | ||||||
INSERT | X | X | X | X | ||
ITERATE | X | |||||
LEAVE statement | X | |||||
LOCK TABLE | X | X | X | X | ||
LOOP statement | X | |||||
OPEN | X | SQLExecute(), SQLExecDirect() | X | |||
PREPARE | SQLPrepare() | X | ||||
REFRESH TABLE | X | X | X | |||
RELEASE | X | X | ||||
RELEASE SAVEPOINT | X | X | X | X | ||
RENAME TABLE | X | X | X | |||
RENAME TABLESPACE | X | X | X | |||
REPEAT statement | X | |||||
RESIGNAL statement | X | |||||
RETURN statement | X | |||||
REVOKE | X | X | X | |||
ROLLBACK | X | X | SQLEndTran(), SQLTransact() | X | ||
SAVEPOINT | X | X | X | X | ||
select-statement | X | X | X | X | ||
SELECT INTO | X | |||||
SET CONNECTION | X | SQLSetConnection() | ||||
SET CURRENT DEFAULT TRANSFORM GROUP | X | X | X | X | ||
SET CURRENT DEGREE | X | X | X | X | ||
SET CURRENT EXPLAIN MODE | X | X | X, SQLSetConnectAttr() | X | ||
SET CURRENT EXPLAIN SNAPSHOT | X | X | X, SQLSetConnectAttr() | X | ||
SET CURRENT PACKAGESET | ||||||
SET CURRENT QUERY OPTIMIZATION | X | X | X | X | ||
SET CURRENT REFRESH AGE | X | X | X | X | ||
SET EVENT MONITOR STATE | X | X | X | X | ||
SET INTEGRITY | X | X | X | |||
SET PASSTHRU10 | X | X | X | X | ||
SET PATH | X | X | X | X | ||
SET SCHEMA | X | X | X | X | ||
SET SERVER OPTION10 | X | X | X | X | ||
SET transition-variable5 | X | X | X | X | ||
SIGNAL statement | X | |||||
SIGNAL SQLSTATE5 | X | X | X | |||
UPDATE | X | X | X | X | ||
VALUES INTO | X | |||||
WHENEVER2 | ||||||
WHILE statement | X | |||||
|