MySQL Functions | Create Function | MySQL Tutorial

Knowledge Thrusters
Knowledge Thrusters
5.1 هزار بار بازدید - 2 سال پیش - In this mysql video, you
In this mysql video, you will be able to create a function in mysql.

A stored function is a set of SQL statements that perform some operation and return a single value.

Just like Mysql in-built function, it can be called from within a Mysql statement.
By default, the stored function is associated with the default database.

Video duration
Intro : 00:00
Function Syntax: 01:02
Create Function : 01:20
Create Function in PHPMyAdmin: 03:45
Call Function: 05:30

Syntax:
CREATE FUNCTION function_name(func_parameter1, func_parameter2, ..)
         RETURN datatype [characteristics]
         func_body

Parameters used:
function_name:
It is the name by which stored function is called. The name should not be same as native(built_in) function. In order to associate routine explicitly with a specific database function name should be given as database_name.func_name.
func_parameter:
It is the argument whose value is used by the function inside its body. You can’t specify to these parameters IN, OUT, INOUT. The parameter declaration inside parenthesis is provided as func_parameter type. Here, type represents a valid Mysql datatype.
datatype:
It is datatype of value returned by function.
characteristics:
The CREATE FUNCTION statement is accepted only if at least one of the characteristics { DETERMINISTIC, NO SQL, or READS SQL DATA } is specified in its declaration.

DELIMITER  
The default delimiter is semicolon. You can change the delimiters to create procedures and so on.
The delimiter_character may consist of a single character or multiple characters e.g., // or $$. However, you should avoid using the backslash (\) because it’s the escape character in MySQL.


CREATE FUNCTION require the CREATE ROUTINE privilege.
The parameter list enclosed within parentheses must always be present. If there are no parameters, an empty parameter list of () should be used. Parameter names are not case-sensitive.

Documentation:
https://dev.mysql.com/doc/refman/8.0/...

#knowledgethrusters #mysql
2 سال پیش در تاریخ 1401/03/21 منتشر شده است.
5,108 بـار بازدید شده
... بیشتر