DB2和Oracle的不同 下载本文

内容发布更新时间 : 2024/5/20 0:47:35星期一 下面是文章的全部内容请认真阅读。

1, Table space for indexes 的不同 Oralce: Create TABLE T1 .............IN DATA_TA Create Index ........ ON T1 ...... IN INDX_TS DB2: Create TABLE T1 ........ IN DATA_TS INDEX IN INDX_TS Create INDEX .....ON T1 2, RowID Oracle: Oracle 有RowID ,它是由数据库唯一产生的,在程序里可以获得 DB2: DB2的相对应的这个值不能被程序获得 3,一些转换 Oracle: Oracle 支持一些转换,比如: Create table t1(c1 int); Select * from t1 where c1=’1’ Select ‘abc’||2 from t1 DB2: DB2不支持一些转换,比如: Create table t1(c1 int); Select * from t1 where c1=CAST(‘1’ AS INT) Select ‘abc’||CHAR(2) from t1 4,函数的值做为表中的缺省值 Oracle: Oracle 支持把函数的值做为表中的缺省值,比如: Create table t1(C1 Number DEFAULT FN() NOT NULL, C2 DATE DEFAULT NOT NULL SYSDATE ) DB2: DB2不支持把函数的值做为表中的缺省值,比如: Create table t1(C1 INT NOT NULL, C2 TIMESTAMP DEFAULT CURRENT TIMESTAMP ) 这个是不允许的 5,一些内建的函数 Oracle NVL INSTR COALESCE LOCATE DB2 DECODE LENGTH TO_CAHR() TO_DATE() CASE LENGTH CHAR(),INTEGER(),TO_CHAR() CHAR(date,FN) TO_DATE() 6,公用的同义词(Public Synonyms) Oracle: Oracle 支持公用的同义词 DB2: DB2不支持公用的同义词 7,Date/Time DB2 SYSDATE CURRENT DATE CURRENT TIMESTAMP DT1+2 DT1+2days Add_months(DT1,5) DT2+5months DT1+3years DT1-DT2 TIMESTAMODIFF(k,Char(TS1-TS2) To_date(DT1,’MM/DD/YYYY’) Char(DT1,USA) Char(TM1,ISO) 8,外连接 Oracle DB2 Select Select A.lastname,A_id,B.name A.lastname,A_id,B.name From emp A, RIGHT OUTER From emp A,Customer B JOIN Customer B where where A.id=B.sales_rep_id; A.id(+)=B.sales_rep_id; Select Select A.lastname,A_id,B.name A.lastname,A_id,B.name From emp A, LEFT OUTER From emp A,Customer B JOIN Customer B where where A.id=B.sales_rep_id; A.id=B.sales_rep_id(+); Select Select A.lastname,A_id,B.name A.lastname,A_id,B.name From emp A, Full OUTER From emp A,Customer B JOIN Customer B where where A.id=B.sales_rep_id; A.id(+)=B.sales_rep_id(+); 现在, Oracle 9i也支持这种ANSI join 语法 Oracle 9,字符串和null的合并 Select ‘abc’||c1 from T1

C1 is null Result :

Oracle : abc DB2: null

要想得到’abc’,DB2中需要这样处理 Select ‘abc’||coalesce(c1,’’) from T1