1、DB2 访问前10行数据与Oracle区别
DB2 :
select * from test fetch first 10 rows only Oracle :
select * from test where rownum<=10
查询语句
Db2:不提供隐形转换
select * from employee where empno=1010; oracle:提供隐形转换
select * from employee where empno='1010';
2、DB2 Insert into 与Oracle区别
DB2 允许有类似这样多行插入:
insert into staff values(1212,'cemy',20,'sales',3,90000,30000); (1212,'cemy',20,'sales',3,90000,30000);
oracle:
SQL> insert into staff values(1212,'cemy',20,'sales',3,90000,30000),(1212,'cemy' ,20,'sales',3,90000,30000)
3、DB2 Update 与Oracle区
Db2
DB2 update staff set (salary,comm)=(80000,50000); DB2 update staff set salary=80000,comm=50000; Oracle:
SQL> update staff set salary=80000,comm=50000; 已更新 1 行。I
4、取得系统日期
Oracle:
Select sysdate from dual;
DB2:
Select current timestamp from sysibm.sysdummy1;
5、转换日期时间到字符类型:
Oracle
TO_CHAR(date_expression_r_r, 'YYYY-MM-DD') TO_CHAR(date_expression_r_r, 'HH24:MI:SS') DB2
CHAR(date_expression_r_r,ISO) CHAR(time_expression_r_r,ISO)
6、转换日期时间字符串到日期时间类型:
Oracle
TO_CHAR(date_expression_r_r, 'YYYY-MM-DD') TO_CHAR(date_expression_r_r, 'HH24:MI:SS') DB2
DATE('2005-05-20') TIME('18:59:59')
TIEMSTAMP('2007-2-1', '21:12:12') TIEMSTAMP('2007-2-1 21:12:12')
DB2也有TO_CHAR 和 TO_DATE函数,但只能提供固定的转换格式,如下 TO_CHAR (timestamp_expression_r_r,'YYY-MM-DD HH24:MI:SS') TO_DATE (string_expression_r_r, 'YYY-MM-DD HH24:MI:SS')
7、快速清空大表
Oracle:
truncate table TableName ; DB2:
alter table TableName active not logged initially with empty table;
8、创建类似表
Oracle:
create table a as select * from b ; DB2:
create table a like b ;
9、修改字段长度或类型:
ORACLE:
ALTER TABLE NODES MODIFY NODE_NAME varchar(32); DB2:
alter table NODES ALTER NODE_NAME SET DATA TYPE varchar(32);
10、空值处理得到abc
Oracle:
SELECT 'abc' || c1 FROM t1 (c1 IS NULL) DB2 :
SELECT 'abc‘ || COALESCE(c1,'') FROM t1
11、创建 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