资源描述:
《-【优秀资料】oracle与db2有哪些区别》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、Oracle和DB2有哪些区别1、取前N条记录Oracle:Select*fromTab1eNamewhererownum<=N;DB2:Select*fromTableNamefetchfirstNrowsonly;2、取得系统日期Oracle:Selectsysdatefromdual;DB2:Seiectcurrenttimesteimpfromsysibm.sysdummyl;3、空值转换Oracle:Selectproductid,logirmamc,nvl(currate,'。’)fromTableName;D
2、B2:Selectproductid,loginname,value(currate,,0")fromTableName;Coalesce(currate,'O')4、类型转换(8版有了to_char,to_date,9版新增了to_number)Oracle:selectto_char(sysdate,?YYYY-MM-DD:SS')fromdual;DB2:selectvarchar(currenttimestamp)fromsysibm・sysdumniyl;##Oracle数据类型改变函数:tochar()>tod
3、ate()>tonumber()等;如果仅仅取年,月,日等,可以用to_char(sysdate,'YYYY'),to_char('MM'),to_char('DD')取得。只取年月FlTRUNC(SYSDATE),取时分秒TOCHAR(SYSDATE,'HH24:MI:SS')。##DB2数据类型改变函数:char()>varchar()>int()>date()>time()等;取得年,月,日等的写法:YEAR(currenttimestamp),MONTH(currenttimestamp),DAY(currentt
4、imestamp),HOUR(currenttimestamp),MINUTE(currenttimestamp),SECOND(currenttimestamp),MICROSECOND(currenttimestamp),只取年月日可以用DATE(currenttimestamp),取时分秒TIME(currenttimestamp)。Char()是定长字符串(1-255),varchar()为非定长字符串(1-32672)日期,时间形态变为字符形态:char(currentdate),char(currenttime
5、)将字符串转换成口期或时间形态:TIMESTAMP('2002-10-2012:00:00'),DATE('2002-10-20'),DATE('10/20/2002'),TIMEC12:00:00,)##目前DB2V8也支持to_char和to_date5、快速清空人农Oracle:tnmcatetableTablcNamc;DB2:altertableTablcNamcactivenotloggedinitiallywithemptytable;6、关于ROWIDOracle它是由数据库唯一产生的,在程序里可以获得DB
6、2v8也有此功能。7、To_NumberOracle:selectto_number123?)fromdual;DB2:selectcast('123'asinteger)fromsysibm.sysdummyl;SELECTCAST(currenttimeaschar(8))FROMsysibm.sysdunnnyl8、创建类似表Oracle:createtableaasselect*fromb;DB2:creatctablealikeb;CREATETABLEtab_newASselectcoll,col2-FR0Mt
7、ab_oldDEFINITIONONLY(8版有效,9版无效)9、decode方法Oracle:decode方法(DECODE(条件,值1,翻译值1,值2,翻译值2,...值n,翻译值n,缺省值))或者case语句DB2中只有CASE表达式SELECTid,name,CASEWHENinteger(flag)=0THEN,假'WHENinteger(flag)=1THEN,真'ELSE,异常,ENDFROMTEST或者SELECTid,name,CASEinteger(flag)WHEN0THEN'假'WHEN1THEN'
8、真'ELSE,异常'ENDFROMTEST10、子查询(8版,9版也支持子查询)Oracle:直接用子查询Db2:with语句WITHalAS(selectmax(id)asaalfromtest)selectid,aalfromtest,al11、数据类型比较人的差别:Oracle:char2000D