tags:

views:

47

answers:

2
+1  Q: 

Singleton function

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

BackStory: Looking to recreate Oracle's "sequence" functionality inside of MySQL for a project so that all numbers returned are contiguous and unrepeated

TIA

+1  A: 

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

Michael Eakins
A: 

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 ;
kSiR