db2常用命令大全(高级篇)

1、fetch first 10 rows only --列出表中前10条数据

例如:select * from <表名> fetch first 10 rows only


2、coalesce(字段名,转换后的值) --对是null的字段进行值转换

例如:select coalesce(id,1) from <表名> --对表中id如果为null转换成1


3、dayofweek(日期) --计算出日期中是周几(1是周日,2是周一…7是周六)

dayofweek_iso --计算出日期中是周几(1是周一…7是周日)

例如:dayofweek(date(2008-01-16)) --它会返回是4,代表星期三

dayofweek_iso(date(2008-01-16)) --它会返回是3,代表星期三


4、dayofyear(日期) --一年中的第几天,范围在1-366范围之内

注意:参数中日期的格式是YYYY-MM-DD的形式,如果不是需要进行转换,否则函数不能使用

例如:日期是20080116必须要进行转换

dayofweek(concat(concat(concat(substr(openDate,1,4),‘-’),concat(substr(openDate,5,2),‘-’)),substr(openDate,7,2))) as week)

这样格式正确的。


5、concatt(参数1,连接值) --把参数1加上连接值组成一个新值。

例如: concat(‘aa’,‘b’) --返回是aab

把oracle表导入到db2数据库中,有些字段类型需要进行转换,具体看:oracle与db2数据类型转换

启动DB2服务:db2start
关闭DB2服务: db2stop


一、加载数据:
1、 以默认分隔符加载,默认为“,”号
db2 “import from tablename.txt of del insert into tablename”
2、 以指定分隔符“|”加载
db2 “import from tablename.txt of del modified by coldel| insert into tablename”


二、卸载数据:
1、 卸载一个表中全部数据
db2 “export to tablename.txt of del select * from tablename”
db2 “export to tablename.txt of del modified by coldel| select * from tablename”


2、 带条件卸载一个表中数据
db2 “export to tablename.txt of del select * from tablename where brhid=‘99802000’”
db2 “export to tablename.txt of del select * from tablename where codtp=‘01’”
db2 “export to tablename.txt of del modified by coldel| select * from tablename where codtp=‘01’”

三、查询数据结构及数据:
db2 “select * from tablename”
db2 “select * from tablename where brhid=‘99802000’ and oprid=‘0001’”
db2 “select oprid,oprnm,brhid,passwd from tablename”


四、删除表中数据:
db2 “delete from tablename”
db2 “delete from tablename where brhid=‘99802000’ or brhid=‘99803000’”


五、修改表中数据:
db2 “update tablename set prtlines=0 where brhid=‘99801000’ and jobtp=‘02’”
db2 “update tablename set prtlines=0 where jobtp=‘02’ or jobtp=‘03’”


六、联接数据库
db2 connect to dbname


七、清除数据库联接
db2 connect reset 断开数据库连接
db2 terminate 断开数据库连接
db2 force applications all 断开所有数据库连接


八、备份数据库
1、 db2 backup db dbname
2、 db2move dbname export
db2look -d dbname -e -x [-a] -o crttbl.sql


九、恢复数据库
1、 db2 restore db dbname without rolling forward
2、 db2 -tvf crtdb.sql
crtdb.sql文件内容:create db dbname on /db2catalog
db2 -stvf test.sql
db2move dbname import


十、DB2帮助命令:
db2 ?
db2 ? restroe
db2 ? sqlcode (例:db2 ? sql0803) 注:code必须为4位数,不够4位,前面补0


十一、bind命令:将应用程序与数据库作一捆绑,每次恢复数据库后,建议都要做一次bind
(1) db2 bind cs4500.bnd
(2) /btp/bin/bndall /btp/bnd
/btp/bin/bndall /btp/tran/bnd


十二、查看数据库参数:
db2 get dbm cfg
db2 get db cfg for dbname


十三、修改数据库参数:
db2 update db cfg for dbname using LOGBUFSZ 20
db2 update db cfg for dbname using LOGFILSIZ 5120
改完后,应执行以下命令使其生效:
db2 stop
db2 start

相关推荐

  1. db2命令大全高级

    2024-05-04 13:16:01       33 阅读
  2. DOS命令大全

    2024-05-04 13:16:01       23 阅读
  3. CentOS基础命令大全(linux命令)2

    2024-05-04 13:16:01       41 阅读
  4. Git命令大全

    2024-05-04 13:16:01       54 阅读
  5. 华为命令大全

    2024-05-04 13:16:01       55 阅读
  6. Git命令大全

    2024-05-04 13:16:01       64 阅读
  7. hdc命令大全

    2024-05-04 13:16:01       38 阅读
  8. git 命令大全

    2024-05-04 13:16:01       44 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-04 13:16:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-04 13:16:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-05-04 13:16:01       87 阅读
  4. Python语言-面向对象

    2024-05-04 13:16:01       97 阅读

热门阅读

  1. 机车 - 教你学摩托车

    2024-05-04 13:16:01       27 阅读
  2. Linux之sed命令(包含MacOS使用方法)

    2024-05-04 13:16:01       37 阅读
  3. Centos 启动jar包的详细步骤

    2024-05-04 13:16:01       32 阅读
  4. nginx在CentOS系统安装

    2024-05-04 13:16:01       36 阅读
  5. VM Ubuntu unknown filesystem

    2024-05-04 13:16:01       35 阅读
  6. 综合案例(账号密码登录和SQL注入)

    2024-05-04 13:16:01       29 阅读
  7. 我的创作纪念日

    2024-05-04 13:16:01       33 阅读
  8. 批处理任务的通用工具类

    2024-05-04 13:16:01       33 阅读
  9. git简介

    git简介

    2024-05-04 13:16:01      34 阅读
  10. 【Trick】conda指令安装yml文件中的python依赖

    2024-05-04 13:16:01       29 阅读
  11. 纯正英语新闻 5.7(提前)

    2024-05-04 13:16:01       30 阅读