db2学习总结整理

整理总结一下db2相关的用法以及见到的错误与解决方式
(如果命令执行有问题,可能是因为在服务器端没有加db2 “” 或者在可视化工具中加了造成的,之前遇到过一次怎么百度都没有找到解决方式,后来自己试着加了db2 “”,命令就可以了,因为笔者一直在数据库服务器进行的操作= =)

查看表空间:

 db2 list tablespaces show detail

增加表空间(修改)

db2 "alter tablespace table_name extend (all 50000)"    resize

查看字符集

 locale 

修改字符集

export LANG=en_US.UTF-8 

查看数据库配置

db2 get dbm cfg

链接数据库

db2 connect to  database

查看表

db2 list tables

操作数据库

db2 "SQL" >>a.log

查看所有连接

db2 list application

查看日志信息

db2 get db cfg | grep LOG

创建一样的表

create table table_temp like table

查看表结构

db2 describe table cm_sys_para

分组查询,聚合函数

select tran_date,msg_tp, row_number() over(partition by tran_date,msg_tp order by tran_date,msg_tp) as row_num  from table

删除重复数据

delete from (select * from (select PROTOCOLNO,PAYERACCNO,PAYEEACCCLEARBANK,row_number() over(partition by PROTOCOLNO,PAYERACCNO,PAYEEACCCLEARBANK order by PROTOCOLNO,PAYERACCNO,PAYEEACCCLEARBANK) as row_num from table) as e where row_num > 1)

第二种方式

db2 "declare tmpcursor  cursor for select * from table"
declare atmycursor cursor for select distinct PROTOCOLNO,PAYERACCNO,PAYEEACCCLEARBANK,STARTDATE from table where PROTOCOLSTATUS = '1' and EFFECTFLAG = '1';
load from tmpcursor  of cursor insert into  table;

导出数据:

db2 "export to 全路径.del of del select * from table"

导入数据

db2 "load from 全路径.del of del insert into table"

删除

select distinct length(SIGN_NO) from table
delete from table where length(SIGN_NO) = 16

问题:

Category Timestamp Duration Message Line PositionError 2019/6/6
10:08:57 0:00:00.100 DB2 Database Error: ERROR [42601]
[IBM][DB2/AIX64] SQL0104N An unexpected token “CREATE” was found
following “”. Expected tokens may include: “RECLAIM”.
SQLSTATE=42601 10 0 reorg table table_name CREATE INDEX I_UPD_TIME
ON table_name ( UPD_TIME ASC );

解决:
不是有效字符,检查sql发现缺少分号;

问题:

db2 the transaction log for the database is null

解决:
db2日志文件满了的缘故

db2 get db cfg | grep LOG

db2 update db cfg using LOGFILSIZ 10240
db2 update db cfg using LOGPRIMARY 100
db2 update db cfg using LOGSECOND 100

db2stop force
db2start

问题:

Category Timestamp Duration Message Line PositionError 2019/6/6
11:18:23 0:00:00.029 : ERROR [57016] [IBM][DB2/AIX64] SQL0668N
Operation not allowed for reason code “7” on table
“”. SQLSTATE=57016 2 0

解决:
需要重构一次表,如果对表字段进行了修改

reorg table tablename
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值