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 ;