7 Functions to Format a Number to 2 Decimal Places in MySQL

A common task when working with numbers is to format them to a certain amount of decimal places. Two decimal places seems to be the most common format, but we can format to any number of decimal places we want. MySQL provides us with a number of functions that can help us achieve this.

Below are seven functions that can be used to format a number to two decimal places in MySQL.

Continue reading

About the JSON_MERGE() Function in MySQL

In MySQL, JSON_MERGE() is a deprecated function that merges two or more JSON documents and returns the result.

It was deprecated in MySQL 8.0.3 and is subject to removal in a future release.

Fortunately, the JSON_MERGE_PRESERVE() function was added in MySQL 8.0.3 as a synonym for JSON_MERGE(), and it therefore does the same thing that JSON_MERGE() does/did.

Therefore, instead of using JSON_MERGE(), use JSON_MERGE_PRESERVE() instead.

Alternatively, you can use JSON_MERGE_PATCH(), which performs an RFC 7396 compliant merge of two or more JSON documents, without preserving members having duplicate keys.

Continue reading

How CAST() Works in MySQL

In MySQL, CAST() is a built in function that converts a value to another data type. It takes a value of one type and returns a value of the specified type.

You provide the value as an argument when you call the function, as well as the type that you’d like it converted to.

CAST() works similar to CONVERT(), except that the syntax used is slightly different.

Continue reading