大家都知道mysql没有像Oracle的隐含字段rownum ,而我想写一个函数实现rownum的功能,函数代码如下:CREATE FUNCTION rno()
RETURNS INT
BEGIN
SET @rno = @rno + 1;
RETURN @rno;
END; 执行时报了错误,我不理解,请大家帮忙看看!ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'return int beginset @rno = @rno + 1' at line 2ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax
to use near 'return @rno' at line 1ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax
to use near 'end' at line 1
RETURNS INT
BEGIN
SET @rno = @rno + 1;
RETURN @rno;
END; 执行时报了错误,我不理解,请大家帮忙看看!ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'return int beginset @rno = @rno + 1' at line 2ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax
to use near 'return @rno' at line 1ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax
to use near 'end' at line 1
CREATE FUNCTION rno()
RETURNS INT
BEGIN
SET @rno = @rno + 1;
RETURN @rno;
END;
$$
你是在命令行下输入?
select @num:=@num+1,f1,f2... from tt
mysql> delimiter //
mysql> CREATE FUNCTION rno()
-> RETURNS INT
-> BEGIN
-> SET @rno = @rno + 1;
-> RETURN @rno;
-> END;
-> //
Query OK, 0 rows affected (0.11 sec)mysql> delimiter ;mysql> select rno();
+-------+
| rno() |
+-------+
| NULL |
+-------+
1 row in set (0.05 sec)mysql>
MySQL中的ROWNUM的实现
http://blog.csdn.net/ACMAIN_CHM/archive/2009/04/20/4095531.aspx