0% found this document useful (0 votes)
24 views3 pages

NULL Value StudentNotes

This document summarizes four null value functions in Oracle SQL: NVL, NVL2, NULLIF, and COALESCE. It also discusses the CASE and DECODE functions. NVL replaces null values with a specified value. NVL2 returns one value if the first value is not null, and a second value if it is null. NULLIF returns null if two values are equal, otherwise it returns the first value. COALESCE returns the first non-null value from a list of values.

Uploaded by

MazMoh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

NULL Value StudentNotes

This document summarizes four null value functions in Oracle SQL: NVL, NVL2, NULLIF, and COALESCE. It also discusses the CASE and DECODE functions. NVL replaces null values with a specified value. NVL2 returns one value if the first value is not null, and a second value if it is null. NULLIF returns null if two values are equal, otherwise it returns the first value. COALESCE returns the first non-null value from a list of values.

Uploaded by

MazMoh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

4 NULL VALUE FUNCTIONS

NVL(value, replace with value of same datatype) NVL - if the value is NULL replace the value with, X ** data types must match in each list and can be number, char, varchar2 or date data types SELECT last_name, NVL(commission_pct, 10) FROM employees WHERE commission_pct IS NULL; SELECT last_name, NVL(hire_date, '10-FEB-02') FROM employees WHERE hire_date IS NULL; SELECT last_name, NVL(hire_date, TO_DATE('February 16, 2002', 'Month DD, YYY')) FROM employees WHERE hire_date IS NULL; SELECT last_name, NVL(first_name, 'James'') FROM employees WHERE first_name IS NULL; NVL2(value1, value2, value3) NVL2 - if the first value is not null, return value 2 if the first value is null, return value 3 SELECT department_name, manager_id, NVL2(manager_id, 'yes', 'no' ) AS "Has Manager" FROM departments WHERE department_id IN (110, 120, 130);

NULLIF(value1, value2) If the first value and the second value are equal return NULL Ifthe first value and the second value are not equal return first value
**remember NULLIFEQUAL

SELECT first_name, last_name, salary, NULLIF(salary,24000) AS "Salary Info" FROM employees WHERE last_name IN ('King', 'Kochhhar','Ernst') SELECT first_name, last_name, phone_number, NULLIF(SUBSTR(phone_number,1,3),'590') "Phone Null For 590 Area Codes" FROM employees; SELECT first_name, last_name, job_id, NULLIF(job_id,'ST_CLERK') title FROM employees; COALESCE(value1, value2, value3) COALESCE - from a list, return the first NOT NULL SELECT last_name, COALESCE(commission_pct, department_id, salary) info FROM employees WHERE employee_id = 100; SELECT last_name, COALESCE(commission_pct, manager_id, salary) info FROM employees WHERE employee_id = 100;

CASE - CASE X WHEN - THEN SELECT last_name, manager_id, salary, CASE manager_id WHEN 100 THEN salary*1.25 ELSE manager_id END AS "Raise Review" FROM employees; SELECT last_name, first_name, CASE first_name WHEN 'Neena' THEN 'needs raise' ELSE 'no raise' END AS "Raise Review" FROM employees WHERE last_name IN ('King', 'Kochhar'); SELECT last_name, first_name, hire_date, CASE hire_date WHEN (TO_DATE('JANUARY 13, 1993', 'Month DD, YYYY')) THEN (ADD_MONTHS(hire_date, 6)) ELSE (ADD_MONTHS(hire_date, 12)) END AS "Raise Review" FROM employees WHERE last_name IN ('De Haan', 'Ernst'); DECODE - form of IF-THEN but NO ELSE SELECT location_id, city, DECODE(TO_CHAR(location_id), TO_CHAR(1000), 'Roma', TO_CHAR(1100), 'Venice', TO_CHAR(1200), 'Toyko', 'UNDER CONSTRUCTION')AS "New Locations" FROM locations WHERE location_id < 1600;

You might also like