Create a view with column num_rows - MySQL

后端 未结 7 1468
[愿得一人]
[愿得一人] 2020-12-10 06:41

I need to create a view that has a column named row_num where it will be inserted the row number, just like an auto increment in a normal table.

Let\'s say I\'ve thi

7条回答
  •  青春惊慌失措
    2020-12-10 07:32

    I tried the example of the func_inc_var_session function.

    There was a small problem of session variable initialization that I solved using the mysql IFNULL function.

    Below the enhanced func_inc_var_session function.

    CREATE DEFINER=`root`@`localhost` FUNCTION `func_inc_var_session`() RETURNS int(11)
    begin
      SET @var := IFNULL(@var,0) + 1;
      return @var;
    end
    

提交回复
热议问题