mysql number of records in cursor without iterating?

前端 未结 2 1542
耶瑟儿~
耶瑟儿~ 2021-01-12 05:04

I am trying to write mysql procedure for below logic,

select id, fullname from users where fullname like concat(lastname, \' \', firstname, \' (\' , middlena         


        
相关标签:
2条回答
  • 2021-01-12 05:37

    Do a count before the cursor:

    select count(*)
    into @user_cnt
    from users
    where fullname like concat (
        lastname,
        ' ',
        firstname,
        ' (',
        middlename,
        '%'
        );
    

    EDIT: If you want to do it after OPENING the cursor, try doing:

    OPEN your_cursor;
    select FOUND_ROWS() into user_cnt ;
    
    0 讨论(0)
  • 2021-01-12 05:37

    Include SQL_CALC_FOUND_ROWS in your cursor select.Then on fetch use FOUND_ROWS(). It gives the number of records

    0 讨论(0)
提交回复
热议问题