开发者

Singleton function

Is it possible to create a singleton function inside of mysql?

BackStory: Looking to recreate Oracle's "sequence" functi开发者_JAVA技巧onality inside of MySQL for a project so that all numbers returned are contiguous and unrepeated

TIA


You might be able to utilize the Distinct() operator.

select DISTINCT('your field') from `Your Table`

This can be better understood studying the examples from MYSQL's website at:

http://dev.mysql.com/doc/refman/5.1/en/distinct-optimization.html


Thanks for the pointers guys, I ended up creating the function to do it after digging around inside of MySQL's documents

DELIMITER //
CREATE
FUNCTION KBID_SEQ()
RETURNS INT
BEGIN
DECLARE kbid INT;
UPDATE KB_ID set SEQUENCE = LAST_INSERT_ID(SEQUENCE + 1);
select LAST_INSERT_ID() into kbid;
RETURN kbid;
END
//
DELIMITER ;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜