How to Create a Generated Column in Oracle

Oracle Database supports the creation of generated columns. A generated column is a column whose value is derived from an expression that computes values from other columns.

In Oracle Database, generated columns are usually referred to as virtual columns. Generated columns can also be referred to as computed columns in other RDBMSs (such as SQL Server). Either way, they do pretty much the same thing – they contain an expression that computes a value based on values in other columns in the same table.

Continue reading

SQL NVL2() Explained

Some DBMSs have an NVL2() function that allows us to replace a value with another value, the new value being determined by whether or not the initial value is null.

It’s similar to the NVL() function, except that NVL2() accepts exactly three arguments. This allows us to specify a different value to return in the event the first argument is not null.

In contrast, with the NVL() function, some DBMSs accept only two arguments (which makes the function a synonym for the IFNULL() function) while others accept an unlimited number of arguments (which makes it a synonym for the COALESCE() function).

Continue reading