0% found this document useful (0 votes)
39 views8 pages

User Defined Functions in MYSQL

The document discusses user defined functions (UDFs) in MySQL. It defines UDFs, provides the syntax for creating them, and gives an example of a UDF that calculates the square of a number. It also lists some common needs and uses of UDFs like code reusability, modularity, and abstraction of complex queries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views8 pages

User Defined Functions in MYSQL

The document discusses user defined functions (UDFs) in MySQL. It defines UDFs, provides the syntax for creating them, and gives an example of a UDF that calculates the square of a number. It also lists some common needs and uses of UDFs like code reusability, modularity, and abstraction of complex queries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

User Defined Functions in MYSQL

- by
Hemanth Kumar Reddy
T
Batch -8
1. What are UDFs ?
2. How to Create UDFs ?

3. Example
4. Need of UDFS
Definition
• User Defined Functions(UDFs) are functions
composed by users, which in take some
parameters and perform previously defined
operations on it to return result of the action as a
value
• UDFs allow users to create custom queries ,
therefore easing it to users to solve complex
queries.
Creating User Defined Function
• The syntax for creating UDFs in SQL follows a specific structure and
format.

CREATE FUNCTION function_name


([parameter1 data_type1, parameter2 data_type2, ...])
RETURNS return_data_type
BEGIN
-- Function body
END;
Let’s understand
•function_name: The name of the UDF.
•parameter1, parameter2, ...: Optional
parameters that the UDF can accept. Each
parameter consists of a name and a data
type.
•return_data_type: The data type of the
value that the UDF returns.
•BEGIN and END: The start and end of the
function body. The function body contains
the logic and calculations performed by the
UDF.
Example
• UDF that calculates the square of a number :

CREATE FUNCTION square(number INT)


RETURNS INT
BEGIN
RETURN number * number;
END;
Need
OF
UDFs 1. Code Reusability
2. Modularity
3. Custom Logic
4. Performance Optimization
5. Encapsulation of security logic
6. Data Validation & Integrity
7. Abstraction of complex queries
….
and many more

You might also like