博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MySQL和Oracle开发差异
阅读量:7115 次
发布时间:2019-06-28

本文共 2706 字,大约阅读时间需要 9 分钟。

1)  数据类型差异

Oracle

MySQL

注释

单独创建序列来实现

自动增长的数据类型

 

varchar2

varchar

 

number

tinyint,smallint,mediumint,int,bigint

float,double

 

clob

text,mediumtext,longtext

 

date

datetime

 

enum

 

raw

binary(n),varbinary(n)

 

bit(n)

 

blob

blob,mediumblob,longblob

 

 

2)  内建函数差异

Oracle

MySQL

注释

length

char_length

 

substr

substring

 

nvl

ifnull

 

decode

case

 

to_char

date_format,time_format

 

to_date

str_to_date

 

trunc

cast

 

to_number

cast

 

date+/-n

date_add

 

date1-date2

datediff

 

 

3)  SQL语句差异

操作

Oracle

MySQL

创表指定表空间

create table…tablespace x

没有表空间,使用默认存储引擎

CTAS建表

create table…as select…不能新增字段和改变字段属性

create table t1(a int,b int) as select a,b,a,b from t2可以选择新的字段和字段属性

表结构复制

create table t1 as select * from t2 where 1=0,只复制字段定义,不包括约束

create table t1 like t2,复制包括约束

全局分区索引

create index…global partition by

重命名列

alter table t1 rename c1 to c2

alter table t1 change c1 c2

修改列类型

alter table t1 modify c1 integer

alter table t1 change c1 c1 int

修改列缺省值

alter table t1 modify c1 default 0

alter table t1 change c1 c1 int default 0

修改列非空

alter table t1 modify c1 not null

alter table t1 change c1 c1 int not null

重命名表

rename t1 to t2

alter table t1 rename t2

rename table t1 to t2

删除索引

drop index idx1

alter table t1 drop index idx1

drop index idx1 on t1

重命名索引

alter index idx1 rename to idx2

删除重建

重建索引

alter index idx1 rebuild

禁用索引

alter index idx1 unusable

删除表

drop table t1,如果表不存在报错

drop table if exists t1,判断表是否存在,存在删除,不存在不报错

重命名视图

rename v1 to v2

rename view v1 to v2

左右连接

select * from t1,t2

where t1.c1=t2.c2(+);

select * from t1,t2

where t1.c1(+)=t2.c2;

select * from t1 left join t2

on t1.c1=t2.c2;

select * from t1 right join t2

on t1.c1=t2.c2;

交集

select intersect select

select inner join select;使用inner join代替

差集

Select minus select

select left join where,使用left join where代替

获取固定值

select 1 from dual

select 1

字段连接

select c1||c2 from t1

select concant(c1,c2) from t1

结果子查询

select * from (select * from t)

select * from (select * from t) t1 结果集需要有别名

Merge

merge into

replace into

行号

rownum

无,需要使用用户变量来实现

分析函数

max() over()

min() over()

……

无,需要自行实现

位图索引

create bitmap index

Top查询

select * from (select rownum from t1 order by c1)

where rownum>=1 and

rownum<=5

select * from t1 order by c1 limit 5

语句内部临时表

with as

创建存储过程/

create or replace procedure

create procecure

创建函数

create or replace function

create function

创建视图

create or replace view

create view

创建触发器

create or replace trigger

create trigger

创建包

create or replace package

创建用户

create user u1 identified by p1 default tablespace x temporary tablespace y

create user u1 identified by p1

修改密码

alter user u1 identified by p2

mysqladmin -u u1 -p p1 password p2

大小写

不区分

缺省数据库、表名区分大小写,列名不区分;

可以设置lower_case_table_names=1都不分区

 

3) 子程序差异

Oracle中创建的匿名PL/SQL块、PL/SQL函数和存储过程,MySQL需要全部重新实现

 

转载地址:http://ruwel.baihongyu.com/

你可能感兴趣的文章
Unicode(统一码、万国码、单一码)
查看>>
【协变】和【逆变】的简单示例
查看>>
Zabbix实现短信报警设置(实战)
查看>>
Windows下Git多账号配置,同一电脑多个ssh-key的管理
查看>>
微信打开网址添加在浏览器中打开提示遮罩
查看>>
maven 打包 java中的配置文件
查看>>
13.生成规格文件
查看>>
maven学习手记 - 1
查看>>
DLL基本开发规则
查看>>
前端进阶-Position
查看>>
PDO和PDOStatement类常用方法
查看>>
JS - The react framework
查看>>
在js自定义函数中使用$(event.target)代替$(this)
查看>>
[HNOI2006]最短母串问题——AC自动机+状压+bfs环形处理
查看>>
Codechef MARCH14 GERALD07加强版
查看>>
React-Apollo-Prisma-Graphql
查看>>
第17章 网络编程
查看>>
Test a website's performance
查看>>
C#四则运算器(多态方法实现)
查看>>
小程序flex-direction
查看>>