日期:2014-05-16  浏览次数:20749 次

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 ;