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…

AJAX: What it is and how to use it in Scriptcase

Hello, in this post we will conceptually understand the AJAX event and how use  inside the Scriptca...

What advantages for a company in adopting a low-code tool?

Let's understand how low-code tools have become a facilitator in the web development process as they...

How to implement A2F using Swivel in a Scriptcase application

I want to start talking about Swivel, Swivel is a provider of authentication solutions who have been...

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.