When using the TO_CHAR() function to format a number in Oracle Database, you can use the V format element to a return a value multiplied by 10n (and if necessary, round it up), where n is the number of 9s after the V.
DBMS
Database Management Systems
Get the Size of a Database in MariaDB
In MariaDB, we can query the information_schema.tables table to check the size of a database.
This table returns information about the tables and views in each database on the server. We can group the results and return the aggregate amounts for each database.
How to Create a Table Only if it Doesn’t Exist in PostgreSQL
In PostgreSQL, you can use the IF NOT EXISTS clause of the CREATE TABLE statement to check whether or not a table of the same name already exists in the database before creating it.
The table will only be created if no other table exists with the same name. If a table already exists with that name, a “notice” will be issued instead of an error.
Find a String within a String in SQL
Most of the major DBMSs provide us with a way to find a string within a string using SQL. By this, I mean use a SQL query to find the position of a substring within a string.
There are several SQL functions that allow us to do this, including INSTR(), LOCATE(), POSITION(), and CHARINDEX(). The function you use will depend on your DBMS, and possibly whether or not you need to specify a starting position.
How to Check if a Table Already Exists Before Creating it in MySQL
In MySQL, you can use the IF NOT EXISTS clause of the CREATE TABLE statement to check whether or not a table of the same name already exists in the database.
If the table doesn’t exist, it will be created. If it already exists, it won’t be created.
5 Ways to Check if a Table Exists in MySQL
Here are five ways to check whether or not a table exists in a MySQL database.
How to Return Query Results as a Comma Separated List in PostgreSQL
In Postgres, we can use the STRING_AGG() function to transform our query results into a comma separated list.
Instead of each value being output in a separate row (as with any regular query), the values are output to a single row, separated by a comma (or some other delimiter of our choosing).
How to Generate a Random Integer Within a Range in MariaDB
MariaDB includes a RAND() function that returns a random number. More precisely, it returns a DOUBLE precision floating point value v in the range 0 <= v < 1.0.
This is great, but what if you want to generate an integer within a larger range – and a range that you specify?
Fortunately, there’s an easy technique for doing this.
Fix: “operator does not exist: integer || integer” in PostgreSQL
If you get the “operator does not exist: integer || integer” error in PostgreSQL, it’s probably because you’re trying to concatenate two numbers.
If you really want to concatenate two numbers, the easiest way to overcome this issue is to cast at least one of them to a string data type first.
Another way to do it is to use the CONCAT() function.