大家都知道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

解决方案 »

  1.   

    DELIMITER $$
    CREATE FUNCTION rno()   
      RETURNS INT   
      BEGIN   
      SET @rno = @rno + 1;   
      RETURN @rno;   
      END;  
      $$
    你是在命令行下输入?
      

  2.   

    set @num=0;
    select @num:=@num+1,f1,f2... from tt
      

  3.   

    用啥rownum啊 limit 不挺好吗
      

  4.   

    你是如何操作的?没有什么错误啊。
    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>
      

  5.   


    MySQL中的ROWNUM的实现
    http://blog.csdn.net/ACMAIN_CHM/archive/2009/04/20/4095531.aspx