DB2 命令行工具CLPPLUS

【CLPPLUS简介】

DB2自带的CLP很不好用,和Oracle的SQL plus相比,尤其是格式化显示方面做的不够好。DB2为了提高Oracle的兼容度,在9.7推出了和SQLPLUS非常相似的CLPPLUS。这个命令行环境为那些数据Oracle习惯的技术人员提供了一个非常熟悉的界面来操作DB2数据库。和 DB2 CLP 一样,CLPPlus 是 DB2 数据服务器驱动程序包和客户端上的一个轻量级命令行处理器。


CLPPlus 通过添加以下功能扩展了 DB2 CLP 的一些特性:

    支持连接到仅给定了数据库名称、端口、用户 ID 和密码(不需要 DB2 目录文件)的数据库

    存储脚本、脚本片段、SQL 语句、SQL PL 语句和 PL/SQL 语句的一个文本缓冲

    格式化脚本和查询输出的多个选项

CLPPlus 还提供一种可自定义的查询结果显示方式,其中在执行查询时以更友好的方式呈现数据,并且呈现数据的方式是可以定制的。例如,可以格式化数值结果、更改列标题,等等。

CLPPlus 也是接纳使用其他数据库管理产品的用户的一种不错方式。有了 CLPPlus,其他 RDMS 产品用户习惯于使用的大部分选项和功能仍然可用,外加 IBM DB2 的功能。


【一般语法】

clpplus -nw username/password@hostname:port/database_name

或者

clpplus -nw username@hostname:port/database_name
#需要手工输入密码
#推荐这种方式连接


【说明】

其中,-nw选项指:Enables no window mode




【用法举例】

clpplus -nw db2inst1/password@localhost:52000/mydb

或者

clpplus -nw db2inst1@localhost:52000/mydb
#需要手工输入密码
#推荐这种方式连接


要获取有关任何可用命令的具体帮助,只需输入 HELP 然后输入命令。

例如:

SQL> help set
SQL> 
SQL> set line 400
SQL> set pages 10000
SQL> col objectschema for a30

通过使用 SET 命令更改参数,可以在执行查询时更改显示数据的方式。还可以在执行命令之前(或收到错误消息之后)通过 EDIT 命令对其进行编辑。调用 EDIT 命令之后,会打开一个默认编辑器(在 Windows 上是 Notepad,在 Linux 上是 vi),您可以从中创建和保存脚本。编辑并保存脚本之后,编辑器将会关闭,您可以通过 CLPPlus RUN 命令运行编辑过的命令。

命令可以有多个行(斜杠符号 ("/") 是编辑器的一个完成指示符),而且因为有 CLPPlus 缓冲,所以您可以按下键盘上的向上和向下箭头键浏览输入的所有命令(因为启动了 CLPPlus)。




 【help index】

$ clpplus -nw db2inst1@localhost:52000/mydb
CLPPlus: Version 1.6
Copyright (c) 2009, 2011, IBM CORPORATION.  All rights reserved.

Enter password: ********

Database Connection Information :
---------------------------------
Hostname = localhost 
Database server = DB2/AIX64  SQL09078 
SQL authorization ID = db2inst1 
Local database alias = MYDB 
Port = 52000 

SQL> 
SQL> help index

INDEX
-------

Type 'HELP [topic]' for command line help.

@                 ACCEPT            APPEND            BREAK             
BTITLE            CHANGE            CLEAR             CLPPLUS           
COLUMN            COMPUTE           CONNECT           COPY              
CURRENT_SCHEMA    DEFINE            DEL               DESCRIBE          
DISCONNECT        EDIT              EXECUTE           EXIT              
EXPLAIN           EXPORT            GET               GET_DBM_CFG       
GET_DB_CFG        HELP              HOST              IMPORT            
INDEX             INPUT             LIST              LOAD              
PASSWORD          PAUSE             PRINT             PROMPT            
QUIT              REMARK            REORG             REORGCHK          
REPFOOTER         REPHEADER         RESET_DBM_CFG     RESET_DB_CFG      
RUNSTATS          SAVE              SERVEROUTPUT      SET               
SHOW              SPOOL             START             TTITLE            
UNDEFINE          UPDATE_DBM_CFG    UPDATE_DB_CFG     VARIABLE          
WHENEVER

SQL>



【clpplus帮助信息】

$ clpplus -h
CLPPlus: Version 1.6
Copyright (c) 2009, 2011, IBM CORPORATION.  All rights reserved.

Starts CLPPlus from the operating system command line.

clpplus [-verbose] [-nw] [-s[ilent]] [connection_identifier | / | /@dsn_alias] 
[@script_name]

where connection_identifier is:

user[/password][@host[:port][/database]]

-verbose Turns on the verbose mode to print more messages on to the console.

-nw Enables no window mode.

-s[ilent] Suppresses the version information, copyright information, prompt messages, echoing of commands and connection information from being printed in the current CLPPlus session.

connection_identifier - Specifies the database login details to establish connection to the database server. 

/ - Specifies that current OS login user name be used as the database login user and database login details be picked from the dsn with alias as "default_dsn" element in db2dsdriver.cfg file.

/@dsn_alias - Specifies that the database login details be picked from the dsn with 
alias as dsn_alias in db2dsdriver.cfg file. 

When the specified dsn_alias is not found in the db2dsdriver.cfg file, CLPPlus will search for the dsn_alias in LDAP directory server configured in the db2dsdriver.cfg file. If LDAP directory server is not configured or alias name is not found in the LDAP directory server, then corresponding values will be obtained interactively from the user.

@script_name - Specifies the path to the script file to be executed.



重要参考资料:

http://www.ibm.com/developerworks/cn/data/library/techarticle/dm-1006clpplusreports/

http://www.ibm.com/developerworks/cn/data/library/techarticle/dm-1109clpplussql/


转载于:https://my.oschina.net/goopand/blog/397353

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值