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--)------------'
>>-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) | ||
---|---|---|---|---|---|
ALTER { BUFFERPOOL, NODEGROUP, TABLE, TABLESPACE, TYPE, VIEW } | X | X | X | ||
BEGIN DECLARE SECTION2 | |||||
CALL | X9 | X4 | |||
CLOSE | X | SQLCloseCursor(), SQLFreeStmt() | |||
COMMENT ON | X | X | X | ||
COMMIT | X | X | SQLEndTran, SQLTransact() | ||
Compound SQL | X4 | ||||
CONNECT (Type 1) | X | SQLBrowseConnect(), SQLConnect(), SQLDriverConnect() | |||
CONNECT (Type 2) | X | SQLBrowseConnect(), SQLConnect(), SQLDriverConnect() | |||
CREATE { ALIAS, BUFFERPOOL, DISTINCT TYPE, EVENT MONITOR, FUNCTION, INDEX, NODEGROUP, PROCEDURE, SCHEMA, TABLE, TABLESPACE, TRIGGER, TYPE, VIEW } | X | X | X | ||
DECLARE CURSOR2 | X | SQLAllocStmt() | |||
DELETE | X | X | X | ||
DESCRIBE8 | X | SQLColAttributes(), SQLDescribeCol(), SQLDescribParam()6 | |||
DISCONNECT | X | SQLDisconnect() | |||
DROP | X | X | X | ||
END DECLARE SECTION2 | |||||
EXECUTE | SQLExecute() | ||||
EXECUTE IMMEDIATE | SQLExecDirect() | ||||
EXPLAIN | X | X | X | ||
FETCH | X | SQLExtendedFetch()7, SQLFetch(), SQLFetchScroll()7 | |||
FREE LOCATOR | X4 | ||||
GRANT | X | X | X | ||
INCLUDE2 | |||||
INSERT | X | X | X | ||
LOCK TABLE | X | X | X | ||
OPEN | X | SQLExecute(), SQLExecDirect() | |||
PREPARE | SQLPrepare() | ||||
RELEASE | X | ||||
RENAME TABLE | X | X | X | ||
REVOKE | X | X | X | ||
ROLLBACK | X | X | SQLEndTran(), SQLTransact() | ||
select-statement | X | X | X | ||
SELECT INTO | |||||
SET CONNECTION | X | SQLSetConnection() | |||
SET CONSTRAINTS | X | X | X | ||
SET CURRENT DEGREE | X | X | X | ||
SET CURRENT EXPLAIN MODE | X | X | X, SQLSetConnectAttr() | ||
SET CURRENT EXPLAIN SNAPSHOT | X | X | X, SQLSetConnectAttr() | ||
SET CURRENT FUNCTION PATH | X | X | X | ||
SET CURRENT PACKAGESET | |||||
SET CURRENT QUERY OPTIMIZATION | X | X | X | ||
SET EVENT MONITOR STATE | X | X | X | ||
SET transition-variable5 | X | X | X | ||
SIGNAL SQLSTATE5 | X | X | X | ||
UPDATE | X | X | X | ||
VALUES INTO | |||||
WHENEVER2 | |||||
|