DB2与Oracle命令区别
2013-05-09 12:59
309 查看
由于现在数据集市项目中将即席查询ORACLE版本的迁移DB2版本,故在网上找了下资料,也结合自己在测试过程中发现的问题,列举出DB2与Oracle命令区别。
DB2与Oracle命令区别:
1.取前N条记录
Oracle : select * from tablename where rownum <= n;
DB2:select * from tablename fetch first n rows only;
2.取得系统日期
Oracel:select sysdate from dual;
DB2: select current timestamp from sysibm.sysdummy1;
3.空置转换
Oracle:select productid,loginname,nvl(cur_rate,'0') from tablename;
DB2:select productid,loginname,value(cur_rate,'0') from tablename;
4.类型转换
Oracle: 数据类型转换函数:to_char(),to_data(),to_number()等
如果仅仅取年,月,日等,可以用to_char(sysdate,'YYYY-MM-DD'),to_char(sysdate,'YYYY'),to_char(sysdate,'MM');
DB2: 数据类型转换函数:char(),varche(),int(),data(),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-36272;
5.快速清空大表
Oracle:truncate tablename;
DB2:alter table tablename active not logged initially with empty table;
6.to_number
Oracle:select to_number('123') form dual;
DB2:select cast('123' as integer)from sysibm,sysdummy1;
select cast(current time as char(8)) from sysibm,sysdummy1;
7.创建类似表
Oracle:create table a as select * from b;
DB2:crate table a like b;
8.子查询
Oracle:直接使用子查询
DB2:With 语句
with a1 as(
select max(id) as aal from test)
select id,aal from test,al
9.数据类型
比较大的差别:
Oracle:char-2000 date datetime
DB2:char-254 date time timestamp
10.数据类型转换函数
Oracle:
整型转字符型,字符串转整型,
to_char(1),to_char(1.1),to_number('1'),to_number('1.1')
to_data('2011-04-10 19:17:30','YYYY-MM-DD HH24:MI:SS')
to_char(to_date('2011-04-10','yyyy-mm-dd'),'yyyy-mm-dd')
DB2:
char(1),int('1'),double('1.1'),char(1.1)date('2011-04-20')
to_date('2011-04-20 19:28:30','YYYY-MM-DD HH24:MI:SS')
char(date('2011-04-20'))
兼容写法
cast (1 as char)
cast ('1' as int)
11.where 条件弱类型判断
Oracle:where 字符型字段 in(整型) 是允许的
DB2:不允许
Oracle:where 字符型字段 = 数字类型字段 是允许的
DB2:不允许
12.replace 关键字
Oracle 支持,DB2不支持,create or replace 语句在DB2中非法。
13.substr不同
Oracle
select * from tablename where substr('10086',1,10)='100' with ur; 允许
select * from tablename where substr('usr_nbr',1,10)='100' with ur; 允许,不报错,但无结果集。
DB2
select * from tablename where substr('10086',1,10)='100' with ur; 不允许,报错“ SUBSTR 函数的第二个或第三个自变量超出范围”
select * from tablename where substr('usr_nbr',1,10)='100' with ur; 不允许,报错“ SUBSTR 函数的第二个或第三个自变量超出范围”
如果要从第一位取到最后一位,可以不需要第三位参数:
select substr('usr_nbr',1) from tablename;ORACLE和DB2 一样;
DB2与Oracle命令区别:
1.取前N条记录
Oracle : select * from tablename where rownum <= n;
DB2:select * from tablename fetch first n rows only;
2.取得系统日期
Oracel:select sysdate from dual;
DB2: select current timestamp from sysibm.sysdummy1;
3.空置转换
Oracle:select productid,loginname,nvl(cur_rate,'0') from tablename;
DB2:select productid,loginname,value(cur_rate,'0') from tablename;
4.类型转换
Oracle: 数据类型转换函数:to_char(),to_data(),to_number()等
如果仅仅取年,月,日等,可以用to_char(sysdate,'YYYY-MM-DD'),to_char(sysdate,'YYYY'),to_char(sysdate,'MM');
DB2: 数据类型转换函数:char(),varche(),int(),data(),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-36272;
5.快速清空大表
Oracle:truncate tablename;
DB2:alter table tablename active not logged initially with empty table;
6.to_number
Oracle:select to_number('123') form dual;
DB2:select cast('123' as integer)from sysibm,sysdummy1;
select cast(current time as char(8)) from sysibm,sysdummy1;
7.创建类似表
Oracle:create table a as select * from b;
DB2:crate table a like b;
8.子查询
Oracle:直接使用子查询
DB2:With 语句
with a1 as(
select max(id) as aal from test)
select id,aal from test,al
9.数据类型
比较大的差别:
Oracle:char-2000 date datetime
DB2:char-254 date time timestamp
10.数据类型转换函数
Oracle:
整型转字符型,字符串转整型,
to_char(1),to_char(1.1),to_number('1'),to_number('1.1')
to_data('2011-04-10 19:17:30','YYYY-MM-DD HH24:MI:SS')
to_char(to_date('2011-04-10','yyyy-mm-dd'),'yyyy-mm-dd')
DB2:
char(1),int('1'),double('1.1'),char(1.1)date('2011-04-20')
to_date('2011-04-20 19:28:30','YYYY-MM-DD HH24:MI:SS')
char(date('2011-04-20'))
兼容写法
cast (1 as char)
cast ('1' as int)
11.where 条件弱类型判断
Oracle:where 字符型字段 in(整型) 是允许的
DB2:不允许
Oracle:where 字符型字段 = 数字类型字段 是允许的
DB2:不允许
12.replace 关键字
Oracle 支持,DB2不支持,create or replace 语句在DB2中非法。
13.substr不同
Oracle
select * from tablename where substr('10086',1,10)='100' with ur; 允许
select * from tablename where substr('usr_nbr',1,10)='100' with ur; 允许,不报错,但无结果集。
DB2
select * from tablename where substr('10086',1,10)='100' with ur; 不允许,报错“ SUBSTR 函数的第二个或第三个自变量超出范围”
select * from tablename where substr('usr_nbr',1,10)='100' with ur; 不允许,报错“ SUBSTR 函数的第二个或第三个自变量超出范围”
如果要从第一位取到最后一位,可以不需要第三位参数:
select substr('usr_nbr',1) from tablename;ORACLE和DB2 一样;
相关文章推荐
- DB2的常用命令及与ORACLE的一些区别
- DB2的常用命令 及 与ORACLE的一些区别
- oracle中使用drop、delete和truncate三个命令区别
- DB2和Oracle区别
- oracle和db2的sql语句区别
- 【转】oracle 与 DB2 的区别
- DB2和Oracle创建序列和查询的区别
- DB2与oracle游标定义的区别
- DB2与oracle的区别2
- DB2和Oracle创建序列和查询的区别
- 【转】oracle 与 DB2 的区别
- Access和sql server的语法区别 (包括db2 oracle)
- DB2与oracle的区别
- db2与oracle、mysql使用区别
- DB2、Oracle、mysql和sql server区别
- oracle、sql server、mysql、db2 查询 区别
- Oracle 数据库相关知识 ---------- DML、DDL、DCL 命令区别
- db2 与 Oracle 的锁的区别和比较
- Oracle和DB2转换的部分区别
- oracle和SQL SERVER以及DB2之间的区别