文档介绍:1、取前 N条记录 Oracle :Select *from TableName where rownum <=N; DB2 :Select *from TableName fetch first Nrows only; 2、取得系统日期 Oracle :Select sysdate from dual; DB2 :Select current timestamp from ; 3、空值转换 Oracle :Select productid,loginname,nvl(cur_rate,'0') from TableName ; DB2 :Select productid,loginname,value(cur_rate,'0') from TableName; Coalesce(cur_rate,'0') 4、类型转换( 8版有了 to_char,to_date,9 版新增了 to_number ) Oracle :select to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') from dual; DB2 :select varchar(current timestamp) from ; ##Oracl e数据类型改变函数:to_char() 、to_date() 、to_number() 等; 如果仅仅取年,月,日等,可以用 to_char(sysdate, 'YYYY'),to_char('MM') ,to_char('DD') 取得。只取年月日 TRUNC(SYSDATE) , 取时分秒 TO_CHAR(SYSDATE,'HH24:MI:SS') 。##DB2 数据类型改变函数:char() 、varchar() 、int() 、date() 、 time() 等; 取得年,月,日等的写法:YEAR(current timestamp) ,MONTH(current timestamp) , DAY(current timestamp) ,HOUR(current timestamp) ,MINUTE(current timestamp) ,SECOND(current timestamp) ,MICROSECOND(current timestamp) , 只取年月日可以用 DATE(current timestamp) ,取时分秒 TIME(current timestamp) 。 Char() 是定长字符串( 1-255 ), varchar() 为非定长字符串( 1-32672 ) 日期,时间形态变为字符形态:char(current date) ,char(current time) 将字符串转换成日期或时间形态:TIMESTAMP('2002-10-2012:00:00'),DATE('2002-10-20'), DATE('10/20/2002'),TIME('12:00:00') ##目前 DB2 V8也支持 to_char 和to_date 5、快速清空大表 Oracle :truncate table TableName ; DB2 :alter table TableName active not logged initially with empty table; 6、关于 ROWID Oracle 它是由数据库唯一产生的,在程序里可以获得 DB2 v8也有此功能。 7、To_Number Oracle :select to_number('123') from dual; DB2 :select cast('123' asinteger) from ; SELECT CAST (current time aschar(8)) 8、创建类似表 Oracle :create table aasselect *from b; DB2 :create table alike b; CREATE TABLE tab_newAS select col1,col2 …FROMtab_old DEFINITION ONLY (8 版有效, 9版无效)9、decode 方法 Oracle :decode 方法(DECODE( 条件,值1,翻译值 1,值2,翻译值 2,... 值n,翻译值n,缺省值))或者 case 语句 DB2 中只有 CASE 表达式 SELECT id,name ,CASE WHEN integer(flag)=0 THEN ‘假’ WHEN integer(flag)=1 THEN ‘真’ ELSE ‘异常’ END