Example of where id in (, 3 ,...)

Source: Internet
Author: User

Normal Syntax:
Copy codeThe Code is as follows:
Select * from table_name t where t. field1 in (1, 2, 3, 4 ,...);

When the list in the write stored procedure in is substituted with an input parameter, the following method is required:

The find_in_set function is mainly used.
Copy codeThe Code is as follows:
Select * from table_name t where find_in_set (t. field1, '1, 2, 3, 4 ');

Of course, you can also be stupid, that is, assembling strings and then executing:
Copy codeThe Code is as follows:
Drop procedure if exists photography. Proc_Test;
Create procedure photography. 'proc _ test' (param1 varchar (1000 ))
BEGIN
Set @ id = param1;
Set @ sel = 'select * from access_record t where t. ID in (';
Set @ sel_2 = ')';
Set @ sentence = concat (@ sel, @ id, @ sel_2); -- connection string to generate the SQL statement to be executed
Prepare stmt from @ sentence; -- precompile and release it. "Stmt" precompiled variable name,
Execute stmt; -- execute an SQL statement
Deallocate prepare stmt; -- release resources
END;

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.