ORACLE SCALAR FUNCTIONS
Scalar Functions (Single row functions): These are the functions which act on only one value
at a time.
Mathematical functions:
1. ABS (n): Returns the absolute value of ‘n’.
Example: SELECT ABS(-15) “Absolute Value” FROM dual;
Note: (i) SELECT requires a table name in it’s FROM clause, oracle provides a dummy table
called dual for this purpose.
(ii) DUAL is a special one-row, one-column table present by default in Oracle. It has a
single VARCHAR2(1) column called DUMMY that has a value 'X'.
2. POWER (m, n): Returns mn.
Example: SELECT POWER (3, 2) “M to the power N” FROM dual;
3. ROUND (n, m): Return n, rounded to m places to the right of a decimal point.
Example: SELECT ROUND (15.19, 1) “Round of N” FROM dual;
4. SQRT(n): Returns square root of n.
Example: SELECT SQRT (25) “Square root of N” FROM dual;
5. EXTRACT: Returns a value extracted from a date.
Example: SELECT EXTRACT (YEAR FROM DATE ‘2004-07-02’) “Year”, EXTRACT
(MONTH FROM SYSDATE) “Month” FROM dual;
6. GREATEST: Returns the greatest value in a list of expressions.
Example: SELECT GREATEST (4, 5, 17) “Number”, GREATEST (‘4’, ‘5’, ‘17’) “Text”
FROM dual;
7. LEAST: Returns the least value in a list of expressions.
Example: SELECT LEAST (4, 5, 17) “Number”, LEAST (‘4’, ‘5’, ‘17’) “Text” FROM dual;
8. MOD (m, n): Returns the remainder of first number divided by second number.
Example: SELECT MOD (15, 7) “Mod of the number” FROM dual;
9. TRUNC: Returns a number truncated to a certain decimal places.
Example: SELECT TRUNC (125.879, 2) “Truncated Value” FROM dual;
10. FLOOR (n): Returns the largest value that is equal to or less than a number. eg. 24.8=24
Example: SELECT FLOOR (24.8) “Floor value of n” FROM dual;
11. CEIL (n): Returns the smallest integer greater than or equal to a number. eg. 13.15=14
Example: SELECT CEIL (13.15) “Ceil value of n” FROM dual;
String functions:
1. LENGTH (word): Returns length of a word.
Example: SELECT LENGTH (‘Bayross’) “Length” FROM dual;
2. LOWER (char): Returns char, with all letters in lowercase.
Example: SELECT LOWER (‘IVAN BAYROSS’) “Lower case” FROM dual;
3. INITCAP (char): Returns a string with the first letter of each word in upper case.
Example: SELECT INITCAP (‘IVAN BAYROSS’) “Title case” FROM dual;
4. UPPER (char): Returns char, with all letters in uppercase.
Example: SELECT UPPER (‘Ivan Bayross’) “Upper case” FROM dual;
5. SUBSTR: Returns a portion of characters beginning at character m, and going up to n.
Syntax: SUBSTR (<string>, <start position>, <length>)
Example: SELECT SUBSTR (‘SECURE’, 3, 4) “Substring” FROM dual;
6. ASCII: Returns the ASCII code of the character specified.
Example: SELECT ASCII (‘a’) “ASCII value” FROM dual;