1.定义:
Oracle 能在所有主流平台上运行(包括Windows)。完全支持所有的工业标准,采用完全开放策略,提供高可用性和高伸缩性的簇的解决方案。 Oracle 在兼容性、可移植性、可联结性、高生产率上、开放性也存在优点。Oracle产品采用标准SQL,与 IBM SQL/DS,DB2,INGRES,IDMS/R等兼容。
SQL Server 具有使用方便、可伸缩性好、与相关软件集成程度高等优点,逐渐成为Windows平台下进行数据库应用开发较为理想的 选择之一。
MySQL是一种关系数据库管理系统,使用的 SQL 语言是用于访问数据库的最常用标准化语言。MySQL 软件采用了双授权政策,分为社区版和商业版,其体积小、速度快、总体拥有成本低,开放源码。
Oracle和mysql都是甲骨文的产品,SQL Server 是微软的产品
2.面向对象:
Oracle:主流的大型数据库,用于中大型网站开发,商业收费
SQL Server:一般做中小型数据库,用于中小型网站,以及个人使用 ,商业收费
Mysql:一般做中小型数据库,用于中小型网站,以及个人使用,开源免费
3.架构:
Oracle: 数据文件包括:控制文件、数据文件、重做日志文件、参数文件、归档文件、密码文件。这是根据文件功能行进行划分,并且所有文件都是二进制编码后的文件,对数据库算法效率有极大的提高。由于Oracle文件管理的统一性,就可以对SQL执行过程中的解析和优化,指定统一的标准:RBO(基于规则的优化器)、CBO(基于成本的优化器)通过优化器的选择,以及无敌的HINT规则,给与了SQL优化极大的自由,对CPU、内存、IO资源进行方方面面的优化。
MySQL:最大的一个特色,就是自由选择存储引擎。每个表都是一个文件,都可以选择合适的存储引擎。常见的引擎有 InnoDB、 MyISAM、 NDBCluster等。但由于这种开放插件式的存储引擎,比如要求数据库与引擎之间的松耦合关系。从而导致文件的一致性大大降低。在SQL执行优化方面,也就有着一些不可避免的瓶颈。在多表关联、子查询优化、统计函数等方面是软肋,而且只支持极简单的HINT。
SQL Server :数据架构基本是纵向划分,分为:Protocol Layer(协议层), Relational Engine(关系引擎), Storage Engine(存储引擎), SQLOS。SQL执行过程就是逐层解析的过程,其中Relational Engine中的优化器,是基于成本的(CBO),其工作过程跟Oracle是非常相似的。在成本之上也是支持很丰富的HINT,包括:连接提示、查询提示、表提示
4.安装:
Oracle:安装难度中等,安装包比较大,占内存较多,图形界面得借助第三方工具。
Sql Server:安装难度较大,出错要删除注册码,还不行就得重装系统,安装包也比较大,占内存中等,有完整的图形界面。
Mysql:安装难度易,安装包小,占内存较小,图形界面得借助第三方工具
5.操作:
1.组函数用法规则
Oracle中如果查询语句中有组函数,那其他列名必须是组函数处理过的,或者是group by子句中的列,否则报错
MySQL中组函数在select语句中可以随意使用
注:select name,count(money) from user;这个放在MySQL,Sql Server中没有问题在Oracle中就有问题了。
2.自动增长的数据类型处理
Oracle没有自动增长的数据类型,需要建立一个自动增长的序列号,插入记录时要把序列号的下一个值赋于此字段。
Sql Server,MySQL有自动增长的数据类型,插入记录时不用操作此字段,会自动获得数据值。
3.主键
Oracle没有自动增长类型,主键一般使用的序列,插入记录时将序列号的下一个值付给该字段即可;
SQL Server一般使用自动增长类型,通过IDENTITY来设置。
MySQL一般使用自动增长类型,在创建表时只要指定表的主键为auto increment,插入记录时,不需要再指定该记录的主键值,MySQL将自动增长;
4.翻页的SQL语句的处理
Oracle
-- 读取前10条
select * from table1 where rownum<=10;
-- 读取后10条
select * from table1 where rownum<=10 order by id desc;
--取出第三条到第六条数据(效率不高)
select * from (select * from table1 where rownum<=6) minus (select * from table1 where rownum<3);
--或者下面这个
select * from (select * from (select rownum rn ,a.* from table1 a) where rn>=3) where rn<=6;
SQL Server
-- 读取前10条
select top (10) * from table1 where 1=1;
-- 读取后10条
select top (10) * from table1 order by id desc;
-- 在SQL Server里面,如何读取按照某个排序,第3到6这四个记录
select top 4 * from table1 where id not in(select top 2 id from table1);
MySql
-- 读取前10条
select * from table1 where 1=1 limit 10;
-- 读取第5到第10条
select * from tb_email where toname='caixiangyu' limit 5,10;
5.字符串的模糊比较
Oracle里也可以用字段名like%'字符串%'但这种方法不能使用索引,速度不快,用字符串比较函数instr(字段名,'字符串')>0会得到更精确的查找结果。SQL Server,MySQL里用字段名like%'字符串%'
6、字符串拼接
Sqlserver | + |
Mysql | concat() |
Oracle | || |
7、空值处理数
Sqlserver | isnull() |
Mysql | ifnull() 注意:mysql也有isnull()函数,但意义不一样 select a.mobile,isnull(a.mobile) ,ifnull(a. mobile,'空') from ud_connect_new a; |
Oracle | Nvl() |
8、获取系统时间
Sqlserver | getdate() |
Mysql | now() |
Oracle | sysdate |
9、日期格式化(以常用的yyyymmdd格式为例)
Sqlserver | convert(varchar(8),getdate(),112) |
Mysql | date_format(xcs_received_date,'%Y%m%d') |
Oracle | to_char(sysdate,'yyyymmdd') |
10、检查是否有表再删除
Sqlserver | IF OBJECT_ID('xxx') IS NOT NULL 需要用到系统表(dbo.sysobjects )来判断 |
Mysql | drop table if exists tablename |
Oracle | select count(1) from user_tables where table_name = 'xxx' |
11、日期增加一个时间间隔
Sqlserver | SELECT DATEADD(month, -1, getdate()) |
Mysql | select date_sub(now(),interval 1 month) |
Oracle | select add_months(sysdate,1) from dual;
|
12、查询部分记录
Sqlserver | top关键字 |
Mysql | limit |
Oracle | 不支持mysql中limit功能,但可以通过rownum来限制返回的结果集的行数 |
13、Rollup()
Sqlserver | group by with rollup(xx)
|
Mysql | group by with rollup(xx) --mysql这边不能带order by 语句 |
Oracle | group by rollup(xx) --区别于sqlserver及mysql没有with |
14、定义变量
Sqlserver | Begin
DECLARE @count int SET @count=123 Select @count
end
|
Mysql | set @num1=(select max(rank) From tmp_ud_test where is_member=1)/3; set @num2=(select max(rank) From tmp_ud_test where is_member=1)/3*2; set @num3=(select max(rank) From tmp_ud_test where is_member=1)/3*3;
update tmp_ud_test a set type= case when a.rank<=@num1 then 1 when @num1<a.rank and a.rank<=@num2 then 2 when @num2<a.rank and a.rank<=@num3 then 3 end where a.is_member=1; |
Oracle | declare count number := 20; currtime date := sysdate;
begin update xxx set aa= count ,bb= currtime; end;
|
15、主键自增长
Sqlserver | create table tb(id int identity(1,1) primary key ) |
Mysql | create table tb(id int auto increment primary key ) |
Oracle | ORACLE没有自动增长的数据类型,需要建立一个自动增长的序列号,插入记录时要把序列号的下一个值赋于此字段。 例:使用序列自动增长: |
16、类型转换
--Oracle select to_number('123') from dual; --123;
select to_char(33) from dual; --33;
select to_date('2004-11-27','yyyy/mm/dd') from dual;--2004-11-27
--Mysql select cast('123' as signed integer); --123
select cast(33 as char(2)); --33;
select to_days('2000-01-01'); --730485
--SqlServer select cast('123' as decimal(30,2));
--123.00 select cast(33 as char(2)); --33;
select convert(varchar(12) , getdate(), 120)
17、四舍五入函数区别
--Oracle select round(12.86*10)/10 from dual; --12.9
--Mysql select format(12.89,1); --12.9
--SqlServer select round(12.89,1); --12.9
18、日期时间函数
--Oracle select sysdate from dual; --日期时间
--Mysql select sysdate(); --日期时间
select current_date(); --日期
--SqlServer select getdate(); --日期时间
select datediff(day,'2010-01-01',cast(getdate() as varchar(10)));--日期相差天数
19、Decode函数
--Oracle select decode(sign(12),1,1,0,0,-1) from dual;--1
--Mysql/SqlServer select case when sign(12)=1 then 1 when sign(12)=0 then 0 else -1 end;--1
20、判空函数
--Oracle select nvl(1,0) from dual; --1
--Mysql select ifnull(1,0); --1
--SqlServer select isnull(1,0); --1
21、字符串连接函数
--Oracle select '1'||'2' from dual; --12
select concat('1','2'); --12
--Mysql select concat('1','2'); --12
--SqlServer select '1'+'2'; --12
22、记录限制函数
--Oracle select 1 from dual where rownum <= 10;
--Mysql select 1 from dual limit 10;
--SqlServer select top 10 1
23、字符串截取函数
--Oracle select substr('12345',1,3) from dual;
--Mysql/SqlServer select substring('12345',1,3);
24、把多行转换成一合并列
--Oracle select wm_concat(列名) from dual; --多行记录转换成一列之间用,分割
--Mysql/SqlServer select group_concat(列名);
25、大体上讲,Oracle的数字类型更加简单,大部分情况直接设置number类型就行。而不需要像mysql及sqlserver设置个种数值类型
26、Oracle对子查询的支持非常好。而Mysql中的子查询效率就非常低
27、提交方式
Sqlserver | 默认是自动提交 |
Mysql | mysql默认是自动提交 |
Oracle | 默认不自动提交,需要用户手动提交。Sql脚本中经常用到commit; |
28、MySQL支持insert into tabl1 values (1,1), (1,1), (1,1), (1,1), (1,1), (1,1), (1,1)。而sqlserver及oracle则不能这么插入,可用union all实现
5.安全性:
Oracle比SQL Server高,SQL Server又比MySQL高