最新一个项目的sql ddl为MySQL准备的,我想在Oracle中使用。之前不太了解两者的区别,结果报错一坨。于是顶着头皮开始看什么问题,以下是我陷过的坑,让大家看看。废话少说,上代码:
create table cms_ad (
f_ad_id int not null,
f_site_id int not nul
f_adslot_id int not null,
f_name varchar(150) not null comment '名称',
f_begin_date datetime comment '开始时间',
f_end_date datetime comment '结束时间',
f_url varchar(255) comment '广告url',
f_text varchar(255) comment '文字',
f_script mediumtext comment '代码',
f_image varchar(255) comment '图片',
f_flash varchar(255) comment 'flash',
f_seq int not null default 1 comment '排序',
primary key (f_ad_id)
) engine = innodb;
alter table cms_ad comment '广告表';
- Oracle是不存在engine的,所以engine=xxx是要去掉的。
Oracle的comment是这么用的:
comment on column xxx is xxx
、comment on table xxx is xxx
Oracle和MySQL在数据类型方面有很多差异,比如Oracle不存在mediumtext 这个数据类型。更多这方面的差异推荐这位大神的博客http://blog.csdn.net/yzsind/article/details/7948226
以上是我目前发现的差异,最后在附上我如何利用sed命令批量消除这些差异的的命令
sed 's/^alter table \(.*\) comment \(.*\)\;/comment on table \1 is \2\;/' mysql.sql > oracle.sql
。其效果是将mysql.sql中的
alter table cms_ad comment '广告表';
变成oracle.sql中的comment on table cms_ad is '广告表';
其他的待继续更新吧。