The variables are part of the routine for any programmer or DBA, since it is from them that many functions are triggered and make modifications within a system. In the case of databases, more specifically MySQL, variables assist in performing a variety of tasks.

variaveis_msql

By default, the variables are created in MySQL as follows:

@var1:= 1

After the indication of the special character “@”, one just need to indicate the value to be stored in the variable. In the example, the variable receives the integer value “1”.

If you need to set a new value to the variable, the SET command must be used as shown in the example below:

SET @var1 = 2

The variables in the database are more often used in procedures, and that is because they are, in most cases, indicated by the user who will work with the change.

As an example, let’s create a procedure that will perform a calculation from a received information shaped as a variable:

 

CREATE PROCEDURE ‘sp_RaiseSquare’ (INOUT val INT)

BEGIN

SET val = val * val;

END

Once created the procedure, let’s call it also using the variables feature:

SET @var1 = 2

CALL ElevarQuadrado(@var1);

SELECT @var1;

 

In this case, the printed value on the screen will be the number 4.

In a simple example, you can see how the variables are present in solving almost every problem. Therefore, understanding its operation helps solve everyday problems more quickly and effectively.

You might also like…

PROCESAMIENTO AJAX EN SCRIPTCASE

Ajax en los formularios de Scriptcase puede usarse para recargar un campo de tipo de select basado e...

IMPORTAR IMAGENES DE LA BASE DE DATOS Y UTILIZAR CLASES DE BOOSTRAP

Como muchas personas ya saben, Bootstrap es una biblioteca de front-end libre y de código abierto p...

TENDENCIAS DE DESARROLLO WEB PARA 2017

Usted verá en este post tendencias para 2017 en Diseño Web, en el medio digital y en el desarrollo...

Comment this post

Get new posts, resources, offers and more each week.

We will use the information you provide to update you about our Newsletter and Special Offers. You can unsubscribe any time you want by clinck in a link in the footer of any email you receive from us, or by contacting us at sales@scriptcase.net. Learn more about our Privacy Police.