What is a MySQL literal

ORACLE PL / SQL

This MySQL tutorial uses examples to explain how literals (string, number, date, time, and Boolean literals) are used in MySQL.

description

In MySQL, a literal is the same as a constant. We'll cover different types of literals - string literals, number literals, date and time literals, and Boolean literals.

String literals

String literals are always enclosed in single quotation marks (') or double quotation marks ("). For example:

exampleExplanation
'oracleplsql.info'String literal with single quotes
"oracleplsql.info"String literal with double quotes
'Good Morning'String literal with single quotes
"Good Morning"String literal with double quotes

Number of literals

Number of literals can be positive or negative numbers that are exact values ​​or floating point values. If you do not include a sign, a positive number is assumed. Here are some examples of a valid number of literals:

exampleExplanation
25Unsigned integer literal (positive sign assumed)
+25Integer literal with a positive sign
-25Integer literal with a negative sign
25e-04Floating point literal
25.607Decimal literal

Date and time literals

Date and time literals can be expressed either as a string or as a number. Here are some examples of valid date and time literals:

exampleExplanation
'2019-08-19'Date literal formatted as 'YYYY-MM-DD'
'20190819'Date literal formatted as 'YYYYMMDD'
20190819Date literal formatted as YYYYMMDD
'19-08-19'Date literal formatted as 'YY-MM-DD'
'190819'Date literal formatted as 'YYMMDD'
190819Date literal formatted as YYMMDD
'2019-08-21 07:41:12'Datetime literal formatted as 'YYYY-MM-DD HH: MM: SS'
'20190821074112'Datetime literal formatted as 'YYYYMMDDHHMMSS'
20190821074112Datetime literal formatted as YYYYMMDDHHMMSS
'19-08-19 07:41:12'Datetime literal formatted as 'YY-MM-DD HH: MM: SS'
'190821074112'Datetime literal formatted as 'YYYYMMDDHHMMSS'
190821074112Datetime literal formatted as YYYYMMDDHHMMSS
'0 07:41:12'Time literal formatted as 'D HH: MM: SS', where D can be a day value between 0 and 34
'07:41:12'Time literal formatted as 'HH: MM: SS'
'07:41'Time literal formatted as 'HH: MM'
'0 07:41'Time literal formatted as 'D HH: MM', where D can be a day value between 0 and 34
'0 41'Time literal formatted as 'D HH', where D can be a day value between 0 and 34
'12'Time literal formatted as 'SS'
074112Time literal formatted as HHMMSS
4112Time literal formatted as MMSS
12Time literal formatted as SS

Boolean literals

Boolean literals are values ​​that result in either 1 or 0. Here are some examples of valid Boolean literals:

exampleExplanation
1Evaluates to 1
TRUEEvaluates to 1
trueEvaluates to 1
0Evaluates to 0
FALSEEvaluates to 0
falseEvaluates to 0
Filed under Programming MySQL | Permalink