Normal wording:
Copy Code code as follows:
SELECT * FROM table_name t where T.field1 in (1,2,3,4,...);
When the list in the write stored procedure is entered with an incoming parameter, the following methods are used:
Mainly used to Find_in_set function
Copy Code code as follows:
SELECT * FROM table_name t where Find_in_set (t.field1, ' 1,2,3,4 ');
Of course, the more stupid way is to assemble the string and then execute:
Copy Code code as follows:
DROP PROCEDURE IF EXISTS Photography. Proc_test;
CREATE PROCEDURE Photography. ' Proc_test ' (param1 varchar (1000))
BEGIN
Set @id = param1;
Set @sel = ' SELECT * Access_record t where t.id in (';
Set @sel_2 = ') ';
Set @sentence = Concat (@sel, @id, @sel_2);--The connection string generates the SQL statement to execute
prepare stmt from @sentence;--to be prepared. The name of the "stmt" precompiled variable,
execute stmt;--Execute SQL statement
Deallocate prepare stmt;--release resource
end;