目录
-
连接数据库
db2 connect to cmis; cmis是数据库名
-
导入导出
db2 导出、导入命令行查询的数据 ,有中文的建议用ixf方式
del方式导出:db2 export to /xxx/xxx/test.del of del "select * from s_dic"
del方式导入:db2 import from /xxx/xxx/test.del of del insert into s_dic
ixf方式导出:db2 export to /xxx/xxx/test.ixf of ixf"select * from s_dic"
ixf方式导入:db2 import from /xxx/xxx/test.ixf of ixf insert into s_dic
其中test.del就是导出文件的位置
-
查询数据库编码
db2 get db cfg for cmis;cmis是数据库名
-
删除死锁
1、连接数据库,db2 connect to 数据库名;
2、db2 "get snapshot for locks on 数据库名"
3、找到Applicaiton status = UOW Waing 的记录及对于记录的 Application handle
4、db2 "force application(xxx)" 其中xxx 就是Application handle的号,杀掉死锁进程
-
字符串截取
select substr('xxxxxxxx11320401',9,8) from sysibm.sysdummy1;--11320401
截取字符串,输出从第9位开始后的8位
-
in返回结果集顺序
使用sql语句查询时,如:select * from user where name in ('张三','李四','王五','赵六'),返回的结果集的顺序不一定是:张三、李四、王五、赵六,如果业务上要求返回结果集的顺序一定需要根据in的顺序返回,则可以通过instr函数,instr函数,第一个参数是被检索字符串,第二个参数是检索字符串,instr返回的是检索字符串位置的函数,检索不到返回0,满足以上要求,sql如下:
select * from user where name in ('张三','李四','王五','赵六')order by instr('张三李四王五赵六',name)