Msql paging Stored Procedure

Source: Internet
Author: User

The paging storage process of MySQL. The foreground can call the corresponding parameters to obtain the results. It can also be used in combination with the jqgrid list and the page sharer configuration parameters.

-- ---------------------------------------------------------------------------------- Routine DDL -- Note: comments before and after the routine body will not be stored by the server -- revoke delimiter $ create definer = 'root' @ '% 'Procedure 'fenye' (in p_table_name varchar (100), -- table name in p_fields varchar (500), -- selected field in p_where_string varchar (500), -- filter condition with where in p_order_string varchar (500 ), -- sorting method with order in p_page_now int, -- current page number in p_page_size int, -- number of pages out p_out_rows int -- output parameter, total number of records) begin/* define variable */declare m_begin_row int default 0; declare m_limit_string varchar (128);/* construct statement */set m_begin_row = (p_page_now-1) * p_page_size; set m_limit_string = Concat ('limit', m_begin_row, ',', p_page_size); Set @ count_string = Concat ('select count (*) into @ rows_total from ', p_table_name, '', p_where_string); Set @ main_string = Concat ('select', p_fields, 'from', p_table_name,'', p_where_string, '', p_order_string, m_limit_string ); /* pre-processing */prepare count_stmt from @ count_string; execute count_stmt; deallocate prepare count_stmt; Set region = @ rows_total; prepare region from @ main_string; execute region; deallocate prepare else

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.