CTOCIO IT专家网

天极传媒 比特网 | 天极网 | IT专家网 | IT商网 | 52PK游戏网 | 手机天极 | IT分众 |
IT专家网搜索

数据库 | Oracle | DB2 | SQL Server | MySQL | 商业智能 | BI | DBA | Sybase| SQL Server 2008

您现在的位置: IT专家网 > 数据库子站 > 数据库技巧

DB2数据库基础总结

作者: 小灵,  出处:IT专家网, 责任编辑: 李书琴, 
2008-04-16 11:47
  本文从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 有效

共25页。 9 6 7 8 9 10 11 12 13 14 15 16 ... :

网友评论

笔名 
请您注意:遵守国家有关法律、法规,尊重网上道德,承担一切因您的行为而直接或间接引起的法律责任。    IT专家网友拥有管理笔名和留言的一切权利。
  • 周排行榜
  • 月排行榜

邮件订阅


    
天极服务 | 关于我们 | 网站律师 | 加入我们 | 联系我们 | 广告业务 | 友情链接 | 我要挑错
All Rights Reserved, Copyright 2004-2008, Ctocio.com.cn
渝ICP证B2-20030003号 如有意见请与我们联系 powered by 天极内容管理平台CMS4i