Tuesday, 13 January 2015

What is NULL Value in SQL?

If a table column lacks a value in it, that value is said to be NULL. Zeros or spaces cannot be defined  as NULL values, because zero is a number, and a space is a character. A null value can be defined as: A value that is inapplicable, unavailable, unknown, or unassigned. If you look at the COMMISSION_PCT column’s data in the Employees table, you’ll notice that employees other than sales personnel have null values in this column and this is because the commission percentage is inapplicable to these employees.

The following example calculates a null commission for employees who have no commission percentage (null) mentioned against their names. Salaries multiplied with NULL commission percentages resulted in null commission values.

    SQL Statement :

SELECT  last_name, job_id, salary, commission_pct, salary * commission_pct/100 “Commission”
FROM     employees;

    Output :





No comments:

Post a Comment