Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (2.5k points)

(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)

1 Answer

0 votes
by (7.2k points)
edited by

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 VARCHAR

BEGIN

  DECLARE NAME_FOUND VARCHAR DEFAULT "";

    SELECT EMPLOYEE_NAME INTO NAME_FOUND FROM TABLE_NAME WHERE ID = PID;

  RETURN NAME_FOUND;

END;//

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jan 4, 2020 in Web Technology by anmolj (9k points)

Browse Categories

...