single-row functions
DESCRIPTION
IT Program Portfolio-Class of 2013-Battlefield High School IT Portfolio, Class of 2013 A single row function is when a function is applied to only ONE row of data, and there is only ONE output. IT Portfolio, Class of 2013 UPPER makes the selected data in upper- case. SELECT UPPER(last_name) This could make Potts, POTTS IT Portfolio, Class of 2013 LOWER makes the selected data lower-case SELECT LOWER(last_name) ‘Potts’ to ‘potts’ IT Portfolio, Class of 2013TRANSCRIPT
![Page 1: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/1.jpg)
IT Program Portfolio-Class of 2013-Battlefield High School
IT Portfolio, Class of 2013
![Page 2: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/2.jpg)
A single row function is when a function is applied to only ONE row of data, and there is only ONE output.
IT Portfolio, Class of 2013
![Page 3: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/3.jpg)
UPPER makes the selected data in upper-case.
SELECT UPPER(last_name) This could make Potts, POTTS
IT Portfolio, Class of 2013
![Page 4: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/4.jpg)
LOWER makes the selected data lower-case SELECT LOWER(last_name) ‘Potts’ to ‘potts’
IT Portfolio, Class of 2013
![Page 5: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/5.jpg)
INITCAP makes selected data proper-case SELECT INITCAP(job_title) ‘manager’ to ‘Manager’.
IT Portfolio, Class of 2013
![Page 6: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/6.jpg)
CONCAT brings together selected data SELECT CONCAT (‘Hello’,’World’) FROM dual
IT Portfolio, Class of 2013
![Page 7: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/7.jpg)
SUBSTR is used to find a specific output based on a definite amount of values
SUBSTR(‘HelloWorld’,1,5)
IT Portfolio, Class of 2013
![Page 8: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/8.jpg)
LENGTH will give you the amount of characters on a specified value
LENGTH(‘HelloWorld’)
IT Portfolio, Class of 2013
![Page 9: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/9.jpg)
INSTR will give you a numerical amount from one point to another
INSTR(‘HelloWorld’, ‘W’)
IT Portfolio, Class of 2013
![Page 10: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/10.jpg)
LPAD fills unused space with specified character, to the left of the selected value.
SELECT LPAD(salary,10,’$’) FROM employees
IT Portfolio, Class of 2013
![Page 11: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/11.jpg)
RPAD fills unused space with specified character, to the right of the selected value.
SELECT RPAD(salary,10,’$’)
IT Portfolio, Class of 2013
![Page 12: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/12.jpg)
TRIM removes characters at the beginning or end of a string.
TRIM(‘H’ FROM ‘HelloWorld’)
IT Portfolio, Class of 2013
![Page 13: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/13.jpg)
Replaces a specified character with another SELECT REPLACE('Brian','Brian', 'Awesome') FROM dual
IT Portfolio, Class of 2013
![Page 14: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/14.jpg)
Rounds value to specified amount. SELECT ROUND(5.657, 1)
IT Portfolio, Class of 2013
![Page 15: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/15.jpg)
To truncate is to shorten or cut off a number. TRUNC(5.657, 1)
IT Portfolio, Class of 2013
![Page 16: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/16.jpg)
MOD = remainder of one value/another value MOD(700,200)
IT Portfolio, Class of 2013
![Page 17: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/17.jpg)
Functions pertaining to dates ◦ MONTHS_BETWEEN ◦ ADD_MONTHS ◦ NEXT_DAY ◦ LAST_DAY ◦ ROUND ◦ TRUNC
The SYSDATE used is 06-FEB-12 The date format is DD-MON-YY
IT Portfolio, Class of 2013
![Page 18: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/18.jpg)
Number of months between two dates. MONTHS_BETWEEN(SYSDATE, ‘06-JAN-12’)
IT Portfolio, Class of 2013
![Page 19: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/19.jpg)
Add calendar months to date ADD_MONTHS(SYSDATE,6)
IT Portfolio, Class of 2013
![Page 20: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/20.jpg)
Next day of the date specified NEXT_DAY(SYSDATE,'FRIDAY')
IT Portfolio, Class of 2013
![Page 21: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/21.jpg)
Last day of the month LAST_DAY(SYSDATE)
IT Portfolio, Class of 2013
![Page 22: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/22.jpg)
SYSDATE returns the current date SELECT SYSDATE FROM dual
IT Portfolio, Class of 2013
![Page 23: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/23.jpg)
Rounds date ROUND(sysdate, 'MONTH')
ROUND(sysdate, ‘YEAR’)
IT Portfolio, Class of 2013
![Page 24: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/24.jpg)
Truncates date select trunc(to_date('22-AUG-12'), 'YEAR') from dual
IT Portfolio, Class of 2013
![Page 25: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/25.jpg)
TO_CHAR is used to convert dates and numbers to an alternate specified format.
select to_char(sysdate, 'fmMonth dd, RRRR') from dual select to_char(1234, '00999') from dual
IT Portfolio, Class of 2013
![Page 26: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/26.jpg)
This converts a character string back to a number
select to_number('1210.73', '9999.99') from dual
IT Portfolio, Class of 2013
![Page 27: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/27.jpg)
Converts character string to date format TO_DATE(‘character string’, ‘format model’) select to_date('June 22, 1995', 'Month dd,
RRRR') from dual
IT Portfolio, Class of 2013
![Page 28: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/28.jpg)
NVL NVL2 NULLIF COALESCE
IT Portfolio, Class of 2013
![Page 29: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/29.jpg)
NVL detects if a value is null, and then replaces it if it is.
NVL(possibly null value, value to replace null) SELECT NVL(comments, 'no comment') from d_play_list_items
IT Portfolio, Class of 2013
![Page 30: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/30.jpg)
This has 3 expressions. If the first value is not null, then the second is returned. If the first value is null, the third expression is returnded.
SELECT last_name, salary, NVL2(commission_pct, salary + (salary*commission_pct), salary) AS income
FROM employees
IT Portfolio, Class of 2013
![Page 31: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/31.jpg)
This compares two expressions. If equal, the function returns null. If not equal, the function returns the first expression.
SELECT first_name, length(first_name) "Length FN", last_name, length(last_name) "LENGTH LN", NULLIF(length(first_name), length(last_name)) as "Compare Them"
FROM d_partners
IT Portfolio, Class of 2013
![Page 32: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/32.jpg)
If the first expression is null, the function goes down the line until the first not null function is found.
SELECT last_name, COALESCE(commission_pct, salary, 10) FROM employees ORDER BY commission_pct
IT Portfolio, Class of 2013
![Page 33: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/33.jpg)
CASE DECODE
IT Portfolio, Class of 2013
![Page 34: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/34.jpg)
The CASE is the SQL version of an “if-then-else” statement SELECT id,loc_type, rental_fee,
CASE loc_type WHEN 'Private Home' THEN 'No Increase' WHEN 'Hotel' THEN 'Increase 5%' ELSE rental_fee END AS "Revised Fee" FROM d_venues
IT Portfolio, Class of 2013
![Page 35: Single-Row Functions](https://reader033.vdocument.in/reader033/viewer/2022042903/568c531b1a28ab4916b96508/html5/thumbnails/35.jpg)
Similar to the CASE function with the “if, then, else” intention SELECT department_id, last_name, salary,
NVL(DECODE(department_id, 10, 1.25*salary, 90, 1.5*salary, 130,1.75*salary), salary) AS "New Salary" FROM employees
IT Portfolio, Class of 2013