SQLite has a PRINTF()
function (and now a FORMAT()
function) that allows us to format a number based on a format string. For example, we can use this to format the number to a given number of decimal places, plus add a currency symbol to it.
Author: Ian
How CONCAT_WS() Works in PostgreSQL
In PostgreSQL, the CONCAT_WS()
function concatenates two or more strings, placing a separator between each one. The separator is specified by the first argument.
Concatenate a String and a Number in MySQL
There are a couple of approaches we can use to concatenate strings and numbers in MySQL.
- We can use the
CONCAT()
function, which concatenates its arguments. - We can use the pipe concatenation operator (
||
), which concatenates its operands.
Below are examples of each.
Continue reading2 Functions that Get the Day, Month, and Year from a Date in Oracle
Oracle Database has the TO_CHAR(datetime)
function that enables us to get various date parts from a datetime value.
There’s also the EXTRACT(datetime)
function that extracts a specific datetime unit (e.g. day, month, year, etc).
2 Ways to Format your Query Results in SQLcl (Oracle)
When using SQLcl to run queries against Oracle Database, you can specify the output of the query results using the following two options:
- The
SET SQLFORMAT
command - Add a comment shortcut to your query
How the CONCAT() Function Works in PostgreSQL
In PostgreSQL, the CONCAT()
function concatenates the text representations of its arguments.
7 Options for Enabling Pipes (||) as the Concatenation Operator in MariaDB
By 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 readingHow to Extract the Day, Month, and Year from a Date in SQLite
In SQLite, we can use the strftime()
function to return datetime values in our chosen format.
Therefore, we can use it to extract the day, month, and year from a date.
Continue readingHow to Format Numbers with a Minus/Plus Sign in Oracle
When using the TO_CHAR()
function to format a number in Oracle Database, you can use the S
format element to return its sign (i.e. a plus sign for positive values, and a minus sign for negative values).
You can also use the MI
format element to return negative values with a trailing negative sign, and positive values with a trailing blank.
How to Enable the Pipe Concatenation Operator in MySQL
MySQL supports the use of the pipe concatenation operator (||
) for concatenating its operands. However, you need to enable it first.