How do I pass an array and use WHERE IN inside stored procedure?
Do i need to concatenate input string or something ?
Lets say
DELIMITER $$
DROP PROCEDURE IF EXISTS `abc`.`table1`$$
CREATE PROCEDURE `abc`.`test`
(IN somestring VARCHAR(255))
BEGIN
SELECT * FROM abc.table1
WHERE flight_type IN somestring
END $$
DELIMITER ;
You can use temporary table instead stored procedure into where clause. Hi Rox, It would be better to convert your Stored Procedure into a Function, if possible. Then you can use function in WHERE clause.
Where are stored procedures stored? Stored procedures are stored in the mysql. routines and mysql. parameters tables, which are part of the data dictionary.
Using SQL Server Management Studio Expand Databases, expand the database in which the procedure belongs, and then expand Programmability. Expand Stored Procedures, right-click the procedure and then click View Dependencies. View the list of objects that depend on the procedure.
Create a simple stored procedure. DELIMITER ; To create the MySQL Stored Procedure, open the MySQL workbench Connect to the MySQL Database copy-paste the code in the query editor window click on Execute. You can view the procedure under stored procedures.
You can use the string concatenation and the PREPARE statement to run dynamically built queries.
somestring
must be constructed in a valid SQL format like '1','2','3'
DELIMITER $$
DROP PROCEDURE IF EXISTS `abc`.`table1`$$
CREATE PROCEDURE `abc`.`test`
(IN somestring VARCHAR(255))
BEGIN
@s=CONCAT("
SELECT * FROM abc.table1
WHERE flight_type IN (",somestring,");")
PREPARE stmt FROM @s;
EXECUTE @s;
END $$
DELIMITER ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With