MySQL与Oracle的语法区别详细对比

如题所述

第1个回答  推荐于2017-11-29
Oracle和mysql的一些简单命令对比在本文中将会涉及到很多的实例,感兴趣的你不妨学习一下,就当巩固自己的知识了

Oracle和mysql的一些简单命令对比
1) SQL>
select to_char(sysdate,'yyyy-mm-dd') from dual;
  SQL> select
to_char(sysdate,'hh24-mi-ss') from dual;
  mysql> select
date_format(now(),'%Y-%m-%d');
  mysql> select
time_format(now(),'%H-%i-%S');
  日期函数
  增加一个月:
  SQL> select
to_char(add_months(to_date ('20000101','yyyymmdd'),1),'yyyy-mm-dd') from dual;

  结果:2000-02-01
  SQL> select
to_char(add_months(to_date('20000101','yyyymmdd'),5),'yyyy-mm-dd') from dual;

  结果:2000-06-01
  mysql> select date_add('2000-01-01',interval 1
month);
  结果:2000-02-01
  mysql> select
date_add('2000-01-01',interval 5 month);
  结果:2000-06-01
  截取字符串:

  SQL> select substr('abcdefg',1,5) from dual;
  SQL> select
substrb('abcdefg',1,5) from dual;
  结果:abcdemysql> select
substring('abcdefg',2,3);
  结果:bcd
  mysql> select
mid('abcdefg',2,3);
  结果:bcd
  mysql> select substring('abcdefg',2);

  结果:bcdefg
  mysql> select substring('abcdefg' from 2);

  结果:bcdefg
2) 在MySQL中from 后的表如果是(select.......)这种,那么后面必须有别名
3)
连接字符串在Oracle中用|| ,SqlServer中用+,MySQL中用concat('a','b','c')

4)

在SqlServer中的写法:

复制代码
代码如下:

declare @id varchar(50);
set
@id='4028e4962c3df257012c3df3b4850001';
select * from sims_sample_detect
where ID= @id;

在MySQL中的写法:

复制代码
代码如下:

set @a = 189;
select * from bc_article
where id = @a //不用declare

在Orcale中的写法:

5)MySQL存储过程:

复制代码
代码如下:

DELIMITER $$
DROP PROCEDURE IF EXISTS
`SIMS`.`transaction_delSampleInfo`$$
CREATE DEFINER=`root`@`%` PROCEDURE
`transaction_delSampleInfo`(in sampleInfoId varchar(50))
BEGIN
start
transaction;
update sims_sample_info set del='1' where ID = sampleInfoId;

update sims_sample_detect set del='1' where SAMPLE_ID_PARENT = sampleInfoId;

update sims_sample_detect_info set del='1' where DETECT_ID in(
select ID
from sims_sample_detect where SAMPLE_ID_PARENT = sampleInfoId
);
commit;

END$$
DELIMITER ;

变量名不能跟列名相同,否则效果为1=1,且MySQL不区分大小写。本回答被提问者和网友采纳
第2个回答  2014-10-28
这个只有你在用的时候好好体会了
相似回答