DB2数据库基础总结
本文从DB2语法、命令、函数等方面对DB2数据库基础以及存储过程知识做了详细总结。希望对学习DB2数据库的人员有所帮助。
获取系统日期或系统时间
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 有效
- 本文关键词:

