How to create function in MySQL

1. Syntax

drop function if exists function_name ;
delimiter $$
CREATE FUNCTION function_name [ (parameter datatype [, parameter datatype]) ]
RETURNS return_datatype
BEGIN
— statements
END
$$
— for use the function
select function_n…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by The Dream Coding

1. Syntax

drop function if exists function_name ;
delimiter $$
CREATE FUNCTION function_name [ (parameter datatype [, parameter datatype]) ]
RETURNS return_datatype
BEGIN
    -- statements
END
$$
-- for use the function 
select function_name(parameter);

2. example

drop function if exists countscoll;
delimiter $$
CREATE FUNCTION countscoll( cit int ) 
returns int 
begin 
   declare tota int ;
   set tota = ( select count(*) from school 
   where city = cit );
   return tota ;
end
$$
delimiter ;
select countscoll("new york");

3. remark

we use function when we return value or Variable

4. i explaine how to create function in MySQL on youtube

click this => vidéo

5. this is my channel on youtube

click this => The Dream Coding


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by The Dream Coding


Print Share Comment Cite Upload Translate Updates
APA

The Dream Coding | Sciencx (2022-11-12T09:49:44+00:00) How to create function in MySQL. Retrieved from https://www.scien.cx/2022/11/12/how-to-create-function-in-mysql/

MLA
" » How to create function in MySQL." The Dream Coding | Sciencx - Saturday November 12, 2022, https://www.scien.cx/2022/11/12/how-to-create-function-in-mysql/
HARVARD
The Dream Coding | Sciencx Saturday November 12, 2022 » How to create function in MySQL., viewed ,<https://www.scien.cx/2022/11/12/how-to-create-function-in-mysql/>
VANCOUVER
The Dream Coding | Sciencx - » How to create function in MySQL. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/12/how-to-create-function-in-mysql/
CHICAGO
" » How to create function in MySQL." The Dream Coding | Sciencx - Accessed . https://www.scien.cx/2022/11/12/how-to-create-function-in-mysql/
IEEE
" » How to create function in MySQL." The Dream Coding | Sciencx [Online]. Available: https://www.scien.cx/2022/11/12/how-to-create-function-in-mysql/. [Accessed: ]
rf:citation
» How to create function in MySQL | The Dream Coding | Sciencx | https://www.scien.cx/2022/11/12/how-to-create-function-in-mysql/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.