DB2数据库基础知识总结(6)
来源:百度文库 编辑:神马文学网 时间:2024/03/29 13:51:24
获取系统日期或系统时间
select current time into curtime from (values 1) as tmp;
select current date into curdate from (values 2) as tmp;
select year(current date) into curdate from (values 2) as tmp; --获取系统年份
select month(current date) into curdate from (values 2) as tmp; --获取系统月份
select day(current date) into curdate from (values 2) as tmp; --获取系统日份
(CURRENT TIMESTAMP 精度达到微秒)
如何预防空值
DB2的COALESCE函数返回()中表达式列表中第一个不为空的表达式,可以带多个表达式, 和oracle的isnull类似。语法格式如下:
CLEASCE(colname,default_value)
多表的关联更新方法
db2的update语法不支持“update table1 set t1.col1=t2.value1 from table1 t1,table2 t2 where …”的写法,但是可以通过如下方法解决:
update table1 t1 set t1.col1=(select t2.col1 from table2 t2 where …)
例:
update test t1 set (t1.username,t1.instcode) = (select t2.instcode,t2.instname from sysinsttb t2 where t2.instcode=t1.instcode);
获取操作(insert、update)的记录数
GET DIAGNOSTICS rcount=ROW_COUNT;
注:
get diagnostics rcount =ROW_COUNT;
只对update,insert,delete起作用.
不对select into 有效
如何执行RUNSTATS等优化命令
db2 runstats on table with distribution and detailed indexes all
db2 reorgchk update statistics on table all
查看什么时候进行了runstats
db2 "select name, stats_time from sysibm.systables"
完整执行如下:
db2 connect to ocrm1 user db2iocrm using db2iocrm
db2 runstats on table db2iocrm.eosoperator with distribution and indexes all
db2 reorg table db2iocrm.eosoperator allow read access
db2 reorg indexes all for table db2iocrm.eosoperator allow read access
db2 connect reset
如何获取结果集的前N行数据
Select * from tablename fetch first N rows only
安装DB2默认值?
在WINDOWS或OS/2中默认实例的是DB2
在LINUX或UNIX环境下默认实例的是DB2INST1
在WINDOWS或OS/2中默认帐户的是DB2ADMIN
在LINUX或UNIX环境下默认帐户的是DB2AS
select current time into curtime from (values 1) as tmp;
select current date into curdate from (values 2) as tmp;
select year(current date) into curdate from (values 2) as tmp; --获取系统年份
select month(current date) into curdate from (values 2) as tmp; --获取系统月份
select day(current date) into curdate from (values 2) as tmp; --获取系统日份
(CURRENT TIMESTAMP 精度达到微秒)
如何预防空值
DB2的COALESCE函数返回()中表达式列表中第一个不为空的表达式,可以带多个表达式, 和oracle的isnull类似。语法格式如下:
CLEASCE(colname,default_value)
多表的关联更新方法
db2的update语法不支持“update table1 set t1.col1=t2.value1 from table1 t1,table2 t2 where …”的写法,但是可以通过如下方法解决:
update table1 t1 set t1.col1=(select t2.col1 from table2 t2 where …)
例:
update test t1 set (t1.username,t1.instcode) = (select t2.instcode,t2.instname from sysinsttb t2 where t2.instcode=t1.instcode);
获取操作(insert、update)的记录数
GET DIAGNOSTICS rcount=ROW_COUNT;
注:
get diagnostics rcount =ROW_COUNT;
只对update,insert,delete起作用.
不对select into 有效
如何执行RUNSTATS等优化命令
db2 runstats on table with distribution and detailed indexes all
db2 reorgchk update statistics on table all
查看什么时候进行了runstats
db2 "select name, stats_time from sysibm.systables"
完整执行如下:
db2 connect to ocrm1 user db2iocrm using db2iocrm
db2 runstats on table db2iocrm.eosoperator with distribution and indexes all
db2 reorg table db2iocrm.eosoperator allow read access
db2 reorg indexes all for table db2iocrm.eosoperator allow read access
db2 connect reset
如何获取结果集的前N行数据
Select * from tablename fetch first N rows only
安装DB2默认值?
在WINDOWS或OS/2中默认实例的是DB2
在LINUX或UNIX环境下默认实例的是DB2INST1
在WINDOWS或OS/2中默认帐户的是DB2ADMIN
在LINUX或UNIX环境下默认帐户的是DB2AS
DB2数据库基础知识总结(6)
DB2数据库基础知识总结(1)
DB2数据库基础知识总结(2)
DB2数据库基础知识总结(3)
DB2数据库基础知识总结(5)
DB2 最佳实践: DB2 数据库存储机制
DB2 for z/OS: DB2 数据库设计
DB2 最佳实践: DB2 数据库存储机制
DB2上建立数据库分区
数据库 第1章基础知识 4-6
基础知识总结
数据库的基础知识
DB2数据库部分日常实用操作
DB2数据库临时表的注意事项
使用DB2数据库临时表的注意事项
使用DB2数据库临时表的注意事项
诊断DB2数据库锁的问题
DB2个人知识总结(不断更新中.........)
测试您的 DB2 数据库: 用 JMeter 测量性能
将 DB2 UDB 应用程序迁移到分区数据库中
DB2数据库优化10佳性能技巧 1-4
DB2数据库优化10佳性能技巧 5-10
浅谈DB2数据库故障处理及最佳实践
DB2 最佳实践: 关于数据库存储的最佳实践