Doubts about Stored Function

Asked

Viewed 229 times

4

What is a Stored Function, what is its basic syntax ? How and where to use a Stored Function

1 answer

2


Basic syntax of a Mysql Function :

delimiter $    
CREATE FUNCTION nome_da_funcao (parametros)  
RETURNS INT  -- pode retornar qualquer tipo de dado 
BEGIN
    -- codigo
       return valor;
END$

delimiter;

The function works to make changes or methods that would save programming work.

Ex. Discounting a particular product, Calculating tax, etc.

To call the function you can both make a simple call :

select funcao();

You can also assign the return value to a variable in Mysql :

declare valor;
set valor = funcao();

There are also Stored Procedures, which basically do not return value, but are called by a different command:

call procedure();

More information :

Creating Stored Procedures Mysql
Mysql Stored Functions

Browser other questions tagged

You are not signed in. Login or sign up in order to post.