I’m trying to create a stored procedure that will be used by a client application to search for customers in a customers table and then return all the info about the customer if he’s found. I’ve created a procedure to add a customer to the table:
DELIMITER $
CREATE PROCEDURE `add_cust` (IN custF VARCHAR(100), IN custL VARCHAR(100))
BEGIN
INSERT INTO customers (cFirst, cLast) VALUES(custF, custL);
END $
And it works.
My customers table is very simple – an auto-incrementing primary key, fist and last name columns.
I can’t wrap my head around this other search procedure. The way I see it is to have two procedures for searching. One procedure uses First Name to search for customer, and the second one will use Last Name.
I assume I’ll have to use a cursor FOR SELECT with WHERE clause, and a WHILE loop. But how do I return the result to the client application? Do I declare one of the parameters in the stored procedure as OUT? Or do I just declare one parameter as INOUT?
So far this is where I am at:
DELIMETER $
CREATE PROCEDURE `searchCustByFirst` (IN custF VARCHAR(100))
BEGIN
END $
It is very simply –
This procedure will return dataset, just read it in the application.
Another solution is to use OUT parameters, for example –
In this case SELECT statement cannot return more then one record, so criteria field
cFirstshould be unique.