Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (2.6k 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;//

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...