Javatpoint Logo
Javatpoint Logo

MySQL Functions

Creating a function

In MySQL, Function can also be created. A function always returns a value using the return statement. The function can be used in SQL queries.

Syntax

Parameter:

Function_name: name of the function

Parameter: number of parameter. It can be one or more than one.

return_datatype: return value datatype of the function

declaration_section: all variables are declared.

executable_section: code for the function is written here.

Example 1

Step 1: Create database and table.

Database: employee

MySQL Functions

Table 1 : designation

MySQL Functions

Table 2 : staff

MySQL Functions

Step 2: Create a function

Function query:

MySQL Functions

Step 3: Execute the function

Query :

SELECT id, get_designation1(`d_id`) as DESIGNATION, name FROM 'staff'

MySQL Functions

Drop a function

In MySQL Function can also be dropped. When A function id dropped, it is removed from the database.

Syntax:

Parameter

function_name: name of the function to be dropped.

Example 1:

drop function get_designation_name;

MySQL Functions
Next TopicMySQL Literals




Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA