What are literals in MySQL?

If we look in the dictionary: literals are meanings. Description of something in the form of text. In MySQL, Oracle, SQL Server, or any other database, a literal is the content of a variable, or simply a value offered for comparison.

SET var_Name = ‘ALEXANDRE’

In the example above we’ve assigned the literal ALEXANDRE to the var_Name variable. We can say that the content (or meaning) of var_Name is ALEXANDRE.

Ah! Got it!!! Everything between quotes is a literal. Not so fast. The analogy is good but imperfect.

SET var_I_like_move_move_it  = FALSE;

SET @var_Price = 10;

SET @Qty = 3;

SET @Total = @var_Price * @Qty;

FALSE (0) is a literal that has been assigned to var_I_like_move_move_it.  Although my children love Madagascar, and, I am sympathetic to King Julien, I don’t like to dance. Therefore, FALSE (0 in MySQL) describes the contents of the variable to which it was assigned.

10 is the literal assigned to the integer variable @var_Price. Like, 3 tells me how much the @Qty variable is worth. The computation (calculation) of the literals contained in the environment variables @Var_Price and @Qty describe the environment variable @Total, or the value within the variable.

So a literal can be of any type: string, numbers, dates, booleans, or even binary.

SELECT * FROM tab_1 WHERE purchase_date > = ‘2020-01-01’

The literal ‘2020-02-01’ was used to make a comparison with the purchase date, making it possible to filter the data from table tab_1.

Social causes we support

Social causes we support

Our achievements are our efforts

About us

dbsnOOp is a company established in Brazil and founded by the database guru creator of alejuice, alemonitor, alebackup, and aletools. A company focused on database consultancy services and support based on high level and deep knowledge, honor, and respect.

Contact us

  • Este endereço de email está sendo protegido de spambots. Você precisa do JavaScript ativado para vê-lo.