MariaDB has an LPAD()
function that allows us to pad the left part of a string or number with our chosen character or series of characters.
We can use this function on numeric values in order to add leading zeros.
Continue readingMariaDB has an LPAD()
function that allows us to pad the left part of a string or number with our chosen character or series of characters.
We can use this function on numeric values in order to add leading zeros.
Continue readingThere are many ways to perform date arithmetic in MariaDB. This includes adding or subtracting a certain number of a given date part from a date or datetime value.
In this article, I present 8 ways to add an hour to a datetime value in MariaDB.
Continue readingSome RDBMSs provide an LPAD()
and RPAD()
function that enables us to left pad or right pad a string. Some functions also allow us to add leading or trailing zeros numbers.
Below are examples of applying SQL padding in some of the more popular RDBMSs.
Continue readingMariaDB has the FORMAT()
function, which formats a number based on the given format string.
It returns the number as a formatted string, with thousands and decimal separators in the appropriate position and rounds the result to the specified decimal position.
You can optionally specify a locale value to format numbers to the pattern appropriate for the given region.
Continue readingMost of the major RDBMSs provide several options for concatenating two or more strings.
CONCAT()
function, which concatenates its arguments.CONCAT_WS()
that allows you to specify a separator that separates the concatenated strings.Below are examples of each method.
Continue readingMost of the major RDBMSs have functions that enable us to extract the day, month, and year from datetime values.
Some RDBMSs provide multiple ways to do this, and others are more limited. Below are examples of extracting the day, month, and year from date values in some of the most popular RDBMSs.
Continue readingBelow are examples that demonstrate how to use SQL to return the short month name from a date in the major RDBMSs.
Continue readingHere are two ways to concatenate strings and numbers in MariaDB:
CONCAT()
function, which concatenates its arguments.||
), which concatenates its operands.Below are examples of each.
Continue readingBy default, two pipe characters (||
) are treated as a logical OR
operator in MariaDB. However, you can change this behaviour if you like.
You can update your sql_mode
to include the PIPES_AS_CONCAT
option, in which case two pipes will be treated as a concatenation operator.
There are quite a few ways to add this option to your sql_mode
. You can add it explicitly. Or you can set your sql_mode
to an option that sets it implicitly.
I run through these options below.
Continue readingHere’s an example of formatting a number as currency in MariaDB.
Continue reading