国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

MySQL與Oracle的語法區別詳細對比

2024-07-24 12:48:44
字體:
來源:轉載
供稿:網友
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不區分大小寫。

6)mysql 游標
mysql沒有像orcale的動態游標,只有顯示游標,例子如下:
復制代碼 代碼如下:

DELIMITER $$
DROP PROCEDURE IF EXISTS `test`.`liyukun`$$
CREATE DEFINER=`ids`@`localhost` PROCEDURE `liyukun`(out z int)
BEGIN
declare count1 int;
DECLARE done INT DEFAULT 0;
declare v_haoma varchar(50);
declare v_yingyeting varchar(100);
DECLARE cur1 CURSOR FOR select haoma,yingyeting from eryue where id<2;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
//這里和oracle有區別,Oracle的PL/SQL的指針有個隱性變
量%notfound,Mysql是通過一個Error handler的聲明來進行判斷的
OPEN cur1;
cur1: LOOP
FETCH cur1 INTO v_haoma,v_yingyeting;
IF done=1 THEN //如果沒有數據了,則離開
LEAVE cur1;
ELSE
select count(*) into count1 from year2012 where haoma=v_haoma ;
if(count1=0) then
insert into year2012(haoma, yingyeting)
values(v_haoma,v_yingyeting);
else
set z = z+1;
update year2012 set eryue = ‘100' where haoma=v_haoma;
end if;
END IF;
END LOOP cur1;
CLOSE cur1;
END$$
DELIMITER ;
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 溆浦县| 马山县| 龙山县| 萍乡市| 张家口市| 定陶县| 池州市| 手机| 德兴市| 仙居县| 深泽县| 西华县| 南部县| 青浦区| 康马县| 灯塔市| 翁源县| 黔西县| 和静县| 扶风县| 寻甸| 鲁山县| 乌兰浩特市| 穆棱市| 武宁县| 山东| 京山县| 仲巴县| 英山县| 神木县| 娱乐| 历史| 平遥县| 晋中市| 博野县| 徐州市| 秦安县| 鄢陵县| 城固县| 抚宁县| 太仆寺旗|