postgresql使用的sql语句如下:selectt.seqValuefrom(selectnextval('seq_attr_id')seqValue,generate_series(1,5)seqNum)t;oracle使用的sql语句如下:selectseq_attr_id.nextvalfro...
postgresql使用的sql语句如下:
select t.seqValue from (select nextval('seq_attr_id') seqValue, generate_series(1, 5) seqNum )t;
oracle使用的sql语句如下:
select seq_attr_id.nextval from (select rownum from dual connect by rownum <=5);
其中seq_attr_id是序列名,如果要用mysql实现上面的功能sql语句该怎么写?
后面通过各种查询答案,使用了以下解决方案:
创建存储过程,在过程中将序列存入一个临时表中,之后调用储存过程,查询临时表,语句如下:
drop PROCEDURE IF EXISTS showSeriesVal;
CREATE PROCEDURE showSeriesVal (IN seqSize INT,IN seqName VARCHAR(50))
BEGIN
DECLARE seqNumber int ;
drop TABLE IF EXISTS tmpSeriesLst;
CREATE TABLE tmpSeriesLst (
seqValue INTEGER
);
Set seqNumber=0 ;
WHILE seqNumber
SET seqNumber=seqNumber+1 ;
INSERT into tmpSeriesLst SELECT nextval(seqName);
END WHILE;
END;
call showSeriesVal(5,'seq_attr_id');
SELECT * FROM tmpSeriesLst;
展开