The goal
Passing multiple values through a single VARCHAR()
parameter.
The scenario
On my application there is a procedure that get products from some table. What I need is simple: take three (or whatever) results by id
if I pass it. For example:
CALL getProducts('1, 2, 3');
.
To do this, I'm working with IN
clause. Take a look at my query:
BEGIN
Select product.Name
From app_products As product
Where product.Id In (1, 2, 3)
END
How can I pass those 1, 2, 3
by parameter?
What I've already tried
Take a look in my query with its parameter:
CREATE PROCEDURE `getProductsPrices`(IN `ids` VARCHAR(255))
BEGIN
Select product.Name
From app_products As product
Where product.Id In (ids)
END
Now, when I call it:
CALL `getProductsPrices`('1, 2, 3')
The return is:
Warning: Truncated incorrect DOUBLE '1, 2, 3'
Someone has any suggestion for me?
Duplicated?
I think that this topic isn't duplicated because I already searched by the same subject but with no success.