首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

mysql 像Oracle同样 解决方案

2012-08-24 
mysql 像Oracle一样 解决方案DROP FUNCTION IF EXISTS currval? DELIMITER $? CREATE FUNCTION currval (

mysql 像Oracle一样 解决方案


DROP FUNCTION IF EXISTS currval;?
DELIMITER $?
CREATE FUNCTION currval (seq_name VARCHAR(50) CHARACTER SET utf8 )?
RETURNS INTEGER?
CONTAINS SQL?
BEGIN?
? DECLARE value INTEGER;?
? SET value = 0;?
? SELECT current_value INTO value?
? FROM sequence?
? WHERE name = seq_name COLLATE utf8_general_ci;?
? RETURN value;?
END$?
DELIMITER ;?
DROP FUNCTION IF EXISTS setval;?
DELIMITER $?
CREATE FUNCTION setval (seq_name VARCHAR(50) CHARACTER SET utf8? , value INTEGER)?
RETURNS INTEGER?
CONTAINS SQL?
BEGIN?
?? UPDATE sequence?
?? SET????????? current_value = value?
?? WHERE name = seq_name COLLATE utf8_general_ci;?
?? RETURN currval(seq_name);?
END$?
DELIMITER ;?
DROP FUNCTION IF EXISTS nextval;?
DELIMITER $?
CREATE FUNCTION nextval (seq_name VARCHAR(50) CHARACTER SET utf8 )?
RETURNS INTEGER?
CONTAINS SQL?
BEGIN?
?? UPDATE sequence?
?? SET????????? current_value = current_value + increment?
?? WHERE name = seq_name COLLATE utf8_general_ci;?
?? RETURN currval(seq_name);?
END$?
DELIMITER ;

热点排行