Literals

Course- MariaDB >

This MariaDB tutorial explains how to use literals (string, number, ate, time, and boolean literals) in MariaDB with examples.

Description

In MariaDB, a literal is the same as a constant. We'll cover several types of literals - string literals, number literals, ate and time literals and boolean literals.

String Literals

String literals are always surrounded by either single quotes (') or double quotes ("). For example:

Example

Explanation

'Fastread.aitechtonic.com'

String literal with single quotes

"Fastread.aitechtonic.com"

String literal with double quotes

'Tech on the Net'

String literal with single quotes

"Tech on the Net"

String literal with double quotes

Number Literals

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

Example

Explanation

43

Integer literal with no sign (positive sign is assumed)

+43

Integer literal with positive sign

-43

Integer literal with negative sign

43e-03

Floating point literal

43.786

Decimal literal

Date and Time Literals

Date and time literals can be expressed as either strings or numbers. Here are some examples of valid date and time literals:

Example

Explanation

'2014-06-27'

Date literal formatted as 'YYYY-MM-DD'

'20140627'

Date literal formatted as 'YYYYMMDD'

20140627

Date literal formatted as YYYYMMDD

'14-06-27'

Date literal formatted as 'YY-MM-DD'

'140627'

Date literal formatted as 'YYMMDD'

140627

Date literal formatted as YYMMDD

'2014-06-27 14:52:34'

Datetime literal formatted as 'YYYY-MM-DD HH:MM:SS'

'20140627145234'

Datetime literal formatted as 'YYYYMMDDHHMMSS'

20140627145234

Datetime literal formatted as YYYYMMDDHHMMSS

'14-06-27 14:52:34'

Datetime literal formatted as 'YY-MM-DD HH:MM:SS'

'140627145234'

Datetime literal formatted as 'YYMMDDHHMMSS'

140627145234

Datetime literal formatted as YYMMDDHHMMSS

'0 14:52:34'

Time literal formatted as 'D HH:MM:SS' where D can be a day value between 0 and 34

'14:52:34'

Time literal formatted as 'HH:MM:SS'

'14:52'

Time literal formatted as 'HH:MM'

'0 14:52'

Time literal formatted as 'D HH:MM' where D can be a day value between 0 and 34

'0 14'

Time literal formatted as 'D HH' where D can be a day value between 0 and 34

'34'

Time literal formatted as 'SS'

145234

Time literal formatted as HHMMSS

5234

Time literal formatted as MMSS

34

Time literal formatted as SS

Boolean Literals

Boolean literals are values that evaluate to either 1 or 0. Here are some examples of valid boolean literals:

Example

Explanation

1

Evaluates to 1

TRUE

Evaluates to 1

true

Evaluates to 1

0

Evaluates to 0

FALSE

Evaluates to 0

false

Evaluates to 0