Oracle SQL Functions
The Oracle implementation of SQL provides a number of functions that can be used in SELECT statements. Functions are typically grouped into the following:
ABS (x) - Absolute Value of x CEIL (x) - Smallest integer greater than or equal to x. COS (x) - Cosine of x FLOOR (x) - Largest integer less than or equal to x. LOG (x) - Log of x LN (x) - Natural Log of x ROUND (x, n) - Round x to n decimal places to the right of the decimal point. SIN (x) - Sine of x TAN (x) - Tangent of x TRUNC (x, n) - Truncate x to n decimal places to the right of the decimal point. CHR (x) - Character for ASCII value x. INITCAP (s) - String s with the first letter of each word capitalized. LOWER (s) - Converts string s to all lower case letters. LPAD (s, x) - Pads string s with x spaces to the left. LTRIM (s) - Removes leading spaces from s. REPLACE (s1, s2, s3) - Replace occurrences of s1 with s2 in string s. RPAD (s, x) - Pads string s with x spaces to the right. RTRIM (s) - Removes trailing spaces from s. SUBSTR (s, x1, x2) - Return a portion of string s starting at position x1 and ending with position x2. If x2 is omitted, it's value defaults to the end of s. UPPER (s) - Converts string s to all upper case letters. ASCII (c) - Returns the ASCII value of c INSTR (s1, s2, x) - Returns the position of s2 in s1 where the search starts at position x. LENGTH (s) - Length of s TO_CHAR (date, format) - Converts a date column to a string of characters. format is a set of Date formatting codes where: YYYY is a 4 digit year. NM is a month number. MONTH is the full name of the month. MON is the abbreviated month. DDD is the day of the year. DD is the day of the month. D is the day of the week. DAY is the name of the day. HH is the hour of the day (12 hour clock) HH24 is the hour of the day (24 hour clock) MI is the minutes. SS is the seconds. TO_CHAR (number, format)
- Converts a numeric column to a string of characters. format is
a set of number formatting codes where:
SYSDATE - Returns the current date (and time if the TO_CHAR function is used) from the system clock. DECODE (s, search1, result1, search2, result2) - Compares s with search1, search2, etc. and returns the corresponding result when there is a match. NVL (s, expression) - If s is NULL, return expression. If s is not null, then return s. USER - Returns the username of the current user.
Examples of functions are given in the following section. Exercise 7: FunctionsFor this exercise, use the various functions to display the following:
Congratulations Bill, your grade point average is 3.45 You'll need to use the TO_CHAR function to convert the GPA column (which is a NUMBER data type) to a set of characters. Hint: You'll need to use the SUBSTR function on the COURSENUMBER column to extract the first three letters. Then compare this to 'CIS'. Have a Oracle Question
Oracle Books
Oracle Application
Oracle Home
All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.
|