Stored Procedures for MySQL to execute search prompts with INOUT Parameters

Source: Internet
Author: User

Stored Procedures for MySQL to execute search prompts with INOUT Parameters

[SQL] DELIMITER $ USE 'b10k' $ DROP PROCEDURE IF EXISTS 'SP _ suggest '$ CREATE DEFINER = 'luth' @ '% 'Procedure 'SP _ suggest '( IN query_column VARCHAR (100 ), /* retrieved field name */IN keyword VARCHAR (100),/* keyword */IN table_name VARCHAR (100 ), /* Name of the retrieved table */INOUT result_count INT/* Number of matching records to be retrieved */) COMMENT execute keyword search 'in in/* Definition variable */DECLARE m_begin_row int default 0; DECLARE m_where_string CHAR (128); DECLARE m_order_string CHAR (128); DECLARE m_limit_string CHAR (64 ); /* construct the statement */SET m_begin_row = result_count; SET m_where_string = CONCAT ('where', query_column, 'like \ '', keyword, '% \''); SET m_order_string = CONCAT ('ORDER BY', query_column); SET m_limit_string = CONCAT ('limit', result_count); SET @ COUNT_STRING = CONCAT ('select distinct count (*) INTO @ ROWS_TOTAL FROM ', table_name, '', m_where_string,'', m_order_string, '', m_limit_string); SET @ MAIN_STRING = CONCAT ('select DISTINCT', query_column, 'from', table_name, '', m_where_string,'', m_order_string, '', m_limit_string);/* preprocessing */PREPARE count_stmt FROM @ COUNT_STRING; EXECUTE count_stmt; deallocate prepare count_stmt; SET result_count = @ ROWS_TOTAL; PREPARE main_stmt FROM @ MAIN_STRING; EXECUTE main_stmt; deallocate prepare main_stmt; END $ DELIMITER;/* call */SET @ aa = 10; CALL sp_suggest ('Latin _ name', 'A', 'species ', @ aa); SELECT @ aa;

 

 

Related Article

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.