CLP command line processor:
可以使用CLP 执行如下命令:
SQL语言
XQUERY 查询语言
DB2 命令
OS 命令
Db2 “ select * from
Syscat.table” 使用做连字符。
Db2 ?
Db2 ?command :db2? Export
Db2? Sqlnnnn: db2 ? sql3185(sqlcode)
Db2? Nnnnn (sqlstate)
非交互模式
Db2 connect to testdb
Db2 “select * from syscat.tables”|more (“ 一般在UNIX平台需要,尤其是语句中有*等特殊字符)
交互模式
Db2
Db2=> connect to testdb
Db2=>select * from syscat.tables
在交互模式下不可以执行OS管道命令象非交互模式那样,但是可以在db2=>! 加!来执行OS命令例如db2=>!ls
Db2=>h
db2 => h r
3 hr
2 h
1 !ls
db2 => h
1 !ls
2 h
3 hr
4 hr
db2 => h r 4
6 h
7 !ls
8 h r
9 h
10 h 4
可以在db2=>e来编辑以前执行过的命令。例如db2=>e 5 编辑第5个命令
同样还可以使用db2=>r去RUN以前执行过的命令 例如db2=>r 5就是以前第5个执行过的命令。
在执行XQUERY的时候语句的前缀应该加XQUERY
在输出的情况下NULL 在CLP 里显示为“-”,数字显示的时候从右侧对齐。非数字左侧对齐。
Db2 connect to dbname
Db2 set client connect 1|2
Db2 connect reset
如果 connect 1 当DB2DBDFT环境变量设置后 db2 connect reset 发出后终止当前连接自动连接到 DB2DBDFT指定的数据库上
如果 connect 2 时当前连接进入休眠状态,然后连接到default database上。
Db2 terminate
终止当前连接,结束后台进程
Quite
Db2=>connect to testdb
Db2=>quit
Db2 select count(*) from syscat.tables;
不结束后台进程也不终止连接。
Db2 list command options
db2 => ? options
db2 [option ...] [db2-command | sql-statement |
[? [phrase | message | sqlstate | class-code]]]
option: -a, -c, -e{c|s}, -finfile, -lhistfile, -n, -o, -p, -rreport, -s, -t,
-td;, -v, -w, -x, -zoutputfile.
Option Description Default Setting
------ ---------------------------------------- ---------------
-a Display SQLCA OFF
-c Auto-commit ON
-e Display SQLCODE/SQLSTATE OFF
-f Read from input file OFF
-l Log commands in history file OFF
-n Remove new line character OFF
-o Display output ON
-p Display db2 interactive prompt ON
-r Save output report to file OFF
-s Stop execution on command error OFF
-t Set statement termination character OFF
-v Echo current command OFF
-w Display FETCH/SELECT warning messages ON
-x Suppress printing of column headings OFF
-z Save all output to output file OFF
Notes:
Use the DB2OPTIONS environment variable to customize option defaults.
An option takes on the opposite value if the minus sign (-) is changed to a
plus (+).
Use UPDATE COMMAND OPTIONS to change option settings in interactive or
file input mode.
D:>db2 -a select count(*)from syscat.tables
1
-----------
3534
1 条记录已选择。
SQLCA 信息
sqlcaid : SQLCA sqlcabc: 136 sqlcode: 0 sqlerrml: 0
sqlerrmc:
sqlerrp : SQLRI01F
sqlerrd : (1) -2147221503 (2) 1 (3) 0
(4) 0 (5) 0 (6) 0
sqlwarn : (1) (2) (3) (4) (5) (6)
(7) (8) (9) (10) (11)
sqlstate: 00000
D:>db2 -ec select count(*)from syscat.tables
1
-----------
3534
1 条记录已选择。
0
D:>db2 -es select count(*)from syscat.tables
1
-----------
3534
1 条记录已选择。
00000
Db2 –l r.txt select count(*) from syscat.tables
2009-10-01 20:16:23 select count(*)from syscat.tables
2009-10-01 20:16:23 DB20000I SQL 命令成功完成。
Db2 –r rp.txt select count(*) from syscat.tables
1
-----------
251
1 条记录已选择。
D:>db2 -x select count(*)from syscat.tables
251
CLP 有2个进程组成一个是前台进程一个是后台进程他们之间通过三个队列进行交互:请求队列,输入队列,输出队列。
DB2BQTIME:当前台进程去检查后台进程的状态时候,发现后台进程不可用那么它将SLEEP DB2BQTIME指定时间后继续检查。
DB2BQTRY 当前台进程检查到DB2BQTRY 指定的次数后,如果后台进程还不可用,则去激活后台进程。
DB2RQTIME:指出后台进程等在请求队列待响应前台进程的时
DB2IQTIME:指出后台进程在输入队列上等待前台进程的时间。
Db2 –r select count(*) from syscat.tables
Db2 –stvf create.sql
db2 +c update staff set salary=salary+100
db2 => update command options using x on
DB20000I UPDATE COMMAND OPTIONS 命令成功完成。
db2 => select * from staff
10 Sanders 20 Mgr 7 18357.50 -
20 Pernal 20 Sales 8 18171.25 612.45
DB2CA
使用DB2CA 配置网络时候如果采用SEARCH:
DB2 GET DBM CFG
(DISCOVER) = SEARCH
(DISCOVER_INST) = ENABLE
DAS
DB2 ADMINISTRATION SERVER 协助管理控制DB SERVER,如果你要使用CC,TC,DC等工具就要配置DAS:
1. 可以实现DB SERVER的远端管理。
2. 提供JOB管理,定期RUN DB2或OS 命令或脚本。
3. 提供发现 INSTANCE,DATABASE,其他DAS的一种方法 DB2 GET ADMIN CFG (SEARCH)
每一个机器上只能有一个DAS
DAS is used to perform remote tasks on the server system and the host system on behalf
of a client request from the Control Center, the Configuration Assistant, or any of the other
available tools.
创建DAS
在 UNIX上使用dascrt –u dasuser (root)
/opt/ibm/db2/v9.5/instance/dascrt
在WINDOWS
Db2admin create
在WINDOWS 下必须是超级用户
在UNIX下用户必须属于DASADMIN_GROUP组的用户 db2 get admin cfg(db2inst 加到此组)
停止:
Db2admin stop
启动:
Db2admin start
查看:
Db2admin
查看配置信息:
Db2 get admin cfg
更新配置信息:
Db2 update dbm cfg using ***
删除DAS
1. Db2admin stop
2. Db2admin drop (windows) dasdrop dasname(UNIX root)
[@more@]来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8188536/viewspace-1027570/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/8188536/viewspace-1027570/