why 发表于 2016-11-18 09:46:14

DB2常用函數總結

  最近用DB2,数据库之间的差异还是很大的,好多函数都不一样
  1.去空格
*DB2中:Ltrim()是去左边空格,rtrim()是去右边空格。
*informix中:trim()就是去空格。
用法:例:string a="abc";
   *DB2中:Ltrim(a)="abc";rtrim(a)="abc",rtrim(ltrim(a))="abc";
   *informix中:trim(a)="abc".
注意:DB2中无trim()函数,所以要去空格要执行左右去空格。
  2.取值若为空值,用另外一个值代替 value(parm,string) 或者 coalesce(parm,string) 从表中取字段parm,若为空值,用string代替。
*DB2中:value(parm,string) 或者 coalesce(parm,string)
*informix中:NVL(parm,string)。
用法:例:
   *DB2中:select value(name,'呵呵') from student;select coalesce(name,'呵呵') from   student;
    若student的表中name字段为空值,则显示出‘呵呵’,若有值则显示出name字段的值
    *informix中:select NVL(name,'呵呵') from student 一样
  注意:DB2中无trim()函数,所以要去空格要执行左右去空格。
  3.repeat(parm,int z),将字段重复z次后输出
*DB2中:select name from student,select repeat(name,2) from student
第一句输出为:‘呵呵’,
第二句输出为:‘呵呵呵呵’
  4.往表格中插入多行
*DB2中:insert into table1 (select parm1,parm2... from table2)
*注意:从table2中必须取与table1相同多字段值才行
  5.CASE WHEN
  selectCASEWHEN MAINTAIN ='0' THEN 'A' WHEN MAINTAIN ='1' THEN 'A' WHENMAINTAIN IS NULLTHEN 'A' ELSE MAINTAIN ENDfrom V_RepairPart
页: [1]
查看完整版本: DB2常用函數總結