Sometimes we want to extract a literal value with a SELECT
. This works perfectly fine if the literal value is 1
or 'a'
, but it fails with an error if the value is NULL
. Let’s discuss why and how to solve the problem.
Tag: level-beginner
Simple articles that can be understood by beginners, but can be useful to experts as well.
Find Oracle version and edition
How to know Oracle edition and version number in use for this instance.
Find texts starting, ending or containing a given string
How to select rows where a text column starts by, ends by, or contains a string. Including slightly less trivial cases.
Find out if you’re running MariaDB, MySQL or Percona Server
MariaDB and MySQL are mostly compatible, while Percona Server is basically MySQL with some optimisations. For this reason, it’s quite common for developers not being sure which of them they are using.
MySQL: Find out which edition you are using
Sometimes, no one in a company knows how many databases they have, or how many commercial licenses they have. So you may be asked to write a report with all the existing MySQL instances, and whether they are Enterprise Editions or Community Editions.
Find texts that contain HTML tags
How to select text values that contain HTML tags. How to disallow inserting texts that contain HTML tags.
Find rows that (don’t) contain a value from a list
How to find rows that contain, or don’t contain, a value from a list. The list may be written in the query, or stored in a table.
Find the maximum text length in a column
How to get the length of the longest text in a column. Including Db2 specific syntax.
Find invalid emails
How to select invalid email addresses from a column. How to reject attempts to insert invalid emails into a column.
Aggregate a column data
How to get statistical data from a column in standard SQL. In particular it shows how to get the minimum, maximum, average values, and the standard deviation.