oracle、mysql、sql server常用语法的差异

1.数据类型

mysql中Number类型分的比较细,常用的int、decimal、tinyint、smallint、mediumint、bigint等

oracle中number类型

例:

mysql小数类型定义decimal(5,1)

oracle小数类型定义number(5,1)

2.查询限制记录数

oracle使用rownum来限制

例:

查询前n条数据

select * from score where rownum=<n;

查询第m条到第n条数据

select * from score where rownum between m and n;

mysql使用limit来限制

例:

查询前n条数据

select * from score limit n;

查询第m条到第n条数据

select * from score where rownum limit m n;

3.左连接右连接

Oracle左连接,右连接可以使用(+)来实现.  MySQL只能使用left join ,right join等关键字

-- Oracle 左关联
select * from taba, tabb where taba.id = tabb.id(+);
-- Oracle 右关联
select * from taba, tabb where taba.id(+) = tabb.id;
-- MySQL 左关联
select * from taba left join tabb on taba.id=tabb.id;
-- MySQL 右关联
select * from taba right join tabb on taba.id=tabb.id;

4.创建表并添加约束条件

相同点:

1)NOT  NULL约束

create table score(

id int(10) NOT NULL,

name varchar(255)

);

2)为多列创建Unique、Primary Key 、Foreign Key、Check约束

create table score(

id int(10) NOT NULL,

name varchar(255),

constraint id_name Primary Key(id,name)

) ;

3)Default约束

create table score(

id int(10) DEFAULT 100,

name varchar(255)

);

不同点:Unique、Primary Key 、Foreign Key、Check

单列创建约束:

mysql:

create table score(

id int(10) NOT NULL,

name varchar(255),

 Primary Key (id)

) ;

oracle/sql server:

create table score(

id int(10) NOT NULL Primary Key,

name varchar(255)

) ;

4.删除索引

sql server:

drop index table_name.table_index;

oracel:

drop index index_name;

mysql:

alter table table_name drop index_name;

5.函数

1)NULL函数

Products表

sql server:

select ProductName,UnitPrice*(ISNULL(UnitsOnOrder,0)+UnitsInStock)  from products;

mysql:

 select ProductName,UnitPrice*(IFNULL(UnitsOnOrder,0)+UnitsInStock) from products;

oracle:

 select ProductName,UnitPrice*(NVL(UnitsOnOrder,0)+UnitsInStock) from products;

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值