Back
(mysql) create a simple function in mysql
I want to create a simple MySQL function, I have this MySQL procedure:
CREATE PROCEDURE getUser(gU INT)
SELECT * FROM Company_Intellipaat
WHERE id_number = gU;
CALL getUser(2)
To create a simple function in MySql and know all the information about the pros and cons of using function over a procedure.
DROP FUNCTION IF EXISTS K_TEST //CREATE FUNCTION K_TEST(PID INT) RETURNS VARCHARBEGIN DECLARE NAME_FOUND VARCHAR DEFAULT ""; SELECT EMPLOYEE_NAME INTO NAME_FOUND FROM TABLE_NAME WHERE ID = PID; RETURN NAME_FOUND;END;//
DROP FUNCTION IF EXISTS K_TEST //
CREATE FUNCTION K_TEST(PID INT) RETURNS VARCHAR
BEGIN
DECLARE NAME_FOUND VARCHAR DEFAULT "";
SELECT EMPLOYEE_NAME INTO NAME_FOUND FROM TABLE_NAME WHERE ID = PID;
RETURN NAME_FOUND;
END;//
31k questions
32.8k answers
501 comments
693 users