The OLAP row functions extend the syntax of the SQL row functions for use with dimensional objects. If you use the SQL row functions, then this syntax is familiar. You can use these functions on relational data when loading it into cubes and cube dimensions, and with the OLAP functions when creating calculated measures.
This chapter describes the row functions of the OLAP expression syntax. It contains these topics:
A B C D E F G H I L M N O P R S T U V W
The row functions are grouped into the following categories:
These functions accept numeric input and return numeric values:
These functions accept character input and return character values:
These functions return information about a character set:
These functions accept character input and return numeric values:
These functions operate on date, timestamp, or interval values:
These functions determine the greatest or least value in a set of values:
These functions change a value from one data type to another:
These functions return a numeric value for each input value:
These functions facilitate null handling:
These functions provide information about the instance and the session:
ABS
returns the absolute value of a numeric expression.
ACOS
calculates the angle value in radians of a specified cosine.
ADD_MONTHS
returns a date that is a specified number of months after a specified date.
When the starting date is the last day of the month or when the returned month has fewer days, then ADD_MONTHS
returns the last day of the month. Otherwise, the returned day is the starting day.
date
is the starting date.
integer
is the number of months to be added to the starting date.
ASCII
returns the decimal representation of the first character of an expression.
ASCIISTR
converts a string in any character set to ASCII in the database character set. Non-ASCII characters are represented as \
xxxx, where xxxx is a UTF-16 code unit.
ASIN
calculates the angle value in radians of a specified sine.
n
is a numeric expression in the range of -1 to 1 that contains the decimal value of a sine.
ATAN
calculates the angle value in radians of a specified tangent.
Use ATAN2
to retrieve a full-range (0 - 2 pi) numeric value indicating the arc tangent of a given ratio.
ATAN2
returns a full-range (0 - 2 pi) numeric value of the arc tangent of a given ratio. The function returns values in the range of -pi to pi, depending on the signs of the arguments.
Use ATAN
to calculate the angle value (in radians) of a specified tangent that is not a ratio.
BIN_TO_NUM
converts a bit vector to its equivalent number.
expr
is a numeric expression with a value of 0 or 1 for the value of a bit in the bit vector.
BITAND
computes an AND
operation on the bits of two nonnegative integers, and returns an integer. This function is commonly used with the DECODE
function.
An AND
operation compares two bit values. If both values are 1, the operator returns 1. If one or both values are 0, the operator returns 0.
CAST
converts values from one data type to another.
expr
can be an expression in one of the data types.
type_name
is one of the data types listed in Table 1-2, "Dimensional Data Types".
Table 3-1 shows which data types can be cast into which other built-in data types. NUMBER
includes NUMBER
, DECIMAL
, and INTEGER
. DATETIME
includes DATE
, TIMESTAMP
, TIMESTAMP WITH TIMEZONE
, and TIMESTAMP WITH LOCAL TIMEZONE
. INTERVAL
includes INTERVAL DAY TO SECOND
and INTERVAL YEAR TO MONTH
.
Table 3-1 Compatible Data Types
From | To BINARY_FLOAT, BINARY_DOUBLE | To CHAR, VARCHAR2 | To NUMBER | To DATETIME, INTERVAL | To NCHAR, NVARCHAR2 |
---|---|---|---|---|---|
BINARY_FLOAT, BINARY_DOUBLE |
yes |
yes |
yes |
no |
yes |
CHAR, VARCHAR2 |
yes |
yes |
yes |
yes |
no |
NUMBER |
yes |
yes |
yes |
no |
yes |
DATETIME, INTERVAL |
no |
yes |
no |
yes |
yes |
NCHAR, NVARCHAR2 |
yes |
no |
yes |
no |
yes |
CEIL
returns the smallest whole number greater than or equal to a specified number.
CHARTOROWID
converts a value from a text data type to a ROWID
data type.
For more information about the ROWID
pseudocolumn, refer to the Oracle Database SQL Language Reference.
CHR
converts an integer to the character with its binary equivalent in either the database character set or the national character set.
For single-byte character sets, if n
> 256, then CHR
converts the binary equivalent of mod(n, 256)
.
For the Unicode national character sets and all multibyte character sets, n
must resolve to one entire code point. Code points are not validated, and the result of specifying invalid code points is indeterminate.
n
is a numeric expression.
USING NCHAR_CS
returns a character in the national character set. Otherwise, the return value is in the database character set. The OLAP engine uses the UTF8 national character set, so the return value may be different from the SQL CHR
function, which uses the database UTF16 national character set.
COALESCE
returns the first non-null expression in a list of expressions, or NULL
when all of the expressions evaluate to null.
CONCAT
joins two expressions as a single character string. The data type of the return value is the same as the expressions, or if they are mixed, the one that results in a lossless conversion.
COS
calculates the cosine of an angle.
COSH
calculates the cosine of a hyperbolic angle.
CURRENT_DATE
returns the current date in the session time zone.
CURRENT_TIMESTAMP
returns the current date and time in the session time zone. The time zone offset identifies the current local time of the session.
precision
specifies the fractional second precision of the returned time value. The default value is 6.
DBTIMEZONE
returns the value of the database time zone as either a time zone offset from Coordinated Universal Time (UTC) or a time zone region name.
To obtain other time zone offsets, use TZ_OFFSET
.
DECODE
compares an expression to one or more search strings one by one.
If expr
is search
, then DECODE
returns the corresponding result
. If there is no match, then DECODE
returns default
. If you omit default
, then DECODE
returns NULL
.
expr
is an expression that is compared to one or more search strings.
search
is a string that is searched for a match to expr
.
result
is the return value when expr
matches the corresponding search string.
default
is the return value when expr
does not match any of the search strings. If default
is omitted, then DECODE
returns NULL
.
The arguments can be any numeric or character type. Two nulls are equivalent. If expr
is null, then DECODE
returns the result
of the first search
that is also null.
The maximum number of components, including expr
, searches
, results
, and default
, is 255.
EXP
returns e
raised to the n
th power, where e
= 2.71828183. The function returns a value of the same type as the argument.
EXTRACT
returns the value of a specified field from a datetime or interval expression.
EXTRACT( { { YEAR | MONTH | DAY | HOUR | MINUTE | SECOND } | { TIMEZONE_HOUR | TIMEZONE_MINUTE } | { TIMEZONE_REGION | TIMEZONE_ABBR } } FROM { datetime_value_expression | interval_value_expression } )
datetime_value_expression
is an expression with a datetime data type.
interval_value_expression
is an expression with an interval data type.
FLOOR
returns the largest integer equal to or less than a specified number.
FROM_TZ
converts a timestamp value and a time zone to a TIMESTAMP WITH TIME ZONE
data type.
timestamp_value
is an expression with a TIMESTAMP
data type.
time_zone_value
is a text expression that returns a string in the format TZH:TZM
or in TZR
with optional TZD
format.
GREATEST
returns the largest expression in a list of expressions. All expressions after the first are implicitly converted to the data type of the first expression before the comparison. Text expressions are compared character by character.
To retrieve the smallest expression in a list of expressions, use LEAST
.
HEXTORAW
converts a hexadecimal value to a raw value.
INITCAP
returns a specified text expression, with the first letter of each word in uppercase and all other letters in lowercase. Words are delimited by white space or non-alphanumeric characters. The data type of the return value is the same as the original text.
The INSTR
functions search string
for substring
. The function returns an integer indicating the position of the character in string
, or a zero (0) if does not find a match.
INSTR
calculates strings using characters as defined by the input character set.
INSTRB
uses bytes instead of characters.
INSTRC
uses Unicode complete characters.
REGEXP_INSTR
provides additional options.
string
is the text expression to search.
substring
is the text string to search for.
position
is a nonzero integer indicating the character in string
where the function begins the search. When position is negative, then INSTR
counts and searches backward from the end of string. The default value of position is 1, which means that the function begins searching at the first character of string.
occurrence
is an integer indicating which occurrence of string the function should search for. The value of occurrence must be positive. The default values of occurrence is 1, meaning the function searches for the first occurrence of substring
.
LAST_DAY
returns the last day of the month in which a particular date falls.
LEAST
returns the smallest expression in a list of expressions. All expressions after the first are implicitly converted to the data type of the first expression before the comparison. Text expressions are compared character by character.
To retrieve the largest expression in a list of expressions, use GREATEST
.
The LENGTH
functions return the length of a text expression.
LENGTH
counts the number of characters.
LENGTHB
uses bytes instead of characters.
LENGTHC
uses Unicode complete characters.
LN
returns the natural logarithm of a number greater than 0.
LNNVL
evaluates a condition when one or both operands of the condition may be null. LNNVL
can be used anywhere a scalar expression can appear, even in contexts where the IS [NOT] NULL
, AND
, or OR
conditions are not valid but would otherwise be required to account for potential nulls.
NOTE: This function returns 1
(true) if the condition is false or unknown, and 0
(false) if the condition is true.
LOCALTIMESTAMP
returns the current date and time in the session time zone.
LOG
computes the logarithm of an expression.
n2
is the base by which to compute the logarithm.
n1
is the value whose logarithm is calculated. It can be any numeric expression that is greater than zero. When the value is equal to or less than zero, LOG
returns a null value.
LOWER
converts all alphabetic characters in a text expression to lowercase. The data type of the return value is the same as the original text.
LPAD
adds characters to the left of an expression to a specified length. The data type of the return value is the same as the original text.
Use RPAD
to add characters to the right.
expr1
is a text expression for the base string.
n
is the total length of the returned expression. If expr1
is longer than n
, then this function truncates expr1
to n
characters.
expr2
is a text expression for the padding characters. By default, it is a space.
LTRIM
scans a text expression from left to right and removes all the characters that match the characters in the trim expression, until it finds an unmatched character. The data type of the return value is the same as the original text.
char
is the text expression to be trimmed.
set
is a text expression with the characters to remove. The default value of set
is a single blank.
MOD
returns the remainder after a number is divided by another, or the number if the divisor is 0 (zero).
n2
is a numeric expression for the number to be divided.
n1
is a numeric expression for the divisor.
MONTHS_BETWEEN
calculates the number of months between two dates. When the two dates have the same day component or are both the last day of the month, then the return value is a whole number. Otherwise, the return value includes a fraction that considers the difference in the days based on a 31-day month.
date1
and date2
are datetime expressions. If date1
is later than date2
, then the result is positive. If date1
is earlier than date2
, then the result is negative.
NANVL
checks if a value is a number. If it is, then NANVL
returns that value. If not, it returns an alternate value. This function is typically used to convert a binary double or binary float NaN (Not a Number) value to zero or null.
NEW_TIME
converts the date and time from one time zone to another. Before using this function, set the NLS_DATE_FORMAT
parameter to display 24-hour time.
date
is a datetime expression to be converted to a new time zone.
timezone1
is the time zone of date
.
timezone2
is the new time zone.
The time zone arguments are limited to the values in Table 3-2. For other time zones, use FROM_TZ
.
Time Zone | Abbreviation |
---|---|
Alaska-Hawaii Daylight Time |
HDT |
Alaska-Hawaii Standard Time |
HST |
Atlantic Daylight Time |
ADT |
Atlantic Standard Time |
AST |
Bering Daylight Time |
BDT |
Bering Standard Time |
BST |
Central Daylight Time |
CDT |
Central Standard Time |
CST |
Eastern Daylight Time |
EDT |
Eastern Standard Time |
EST |
Greenwich Mean Time |
GMT |
Mountain Daylight Time |
MDT |
Mountain Standard Time |
MST |
Newfoundland Standard Time |
NST |
Pacific Daylight Time |
PDT |
Pacific Standard Time |
PST |
Yukon Daylight Time |
YDT |
Yukon Standard Time |
YST |
NEXT_DAY
returns the date of the first instance of a particular day of the week that follows the specified date.
date
is a datetime expression.
char
is a text expression that identifies a day of the week (for example, Monday) in the language of your session.
NLS_CHARSET_ID
returns the identification number corresponding to a specified character set name.
NLS_CHARSET_NAME
returns the name corresponding to a specified character set number.
charset_id
is a valid character set number or one of these keywords:
CHAR_CS
represents the database character set.
NCHAR_CS
represents the national character set. The national character set for the database can be either UTF-8 or AL16UTF16 (default). However, the national character set for analytic workspaces is always UTF-8.
If the number does not correspond to a character set, then the function returns NULL
.
NLS_INITCAP
returns a string in which each word begins with a capital followed by lower-case letters. White space and nonalphanumeric characters delimit the words.
char
can be any text string.
nlsparam
can have the form 'NLS_SORT =
sort
'
where sort
is either a linguistic sort sequence or BINARY
. The linguistic sort sequence handles special linguistic requirements for case conversions. These requirements can result in a return value of a different length than char
. If you omit nlsparam
, then this function uses the default sort sequence for your session.
NLS_LOWER
converts all alphabetic characters in a text expression to lowercase. The data type of the return value is the same as the original text.
char
can be any text expression.
nlsparam
is a linguistic sort sequence in the form NLS_SORT =
sort
[_ai |_ci]
, where sort
is an NLS language. You can add a suffix to the language to modify the sort: _ai
for an accent-insensitive sort, or _ci
for a case-insensitive sort.
NLS_UPPER
converts all alphabetic characters in a text expression to uppercase. The data type of the return value is the same as the original text.
char
can be any text expression.
nlsparam
is a linguistic sort sequence in the form NLS_SORT =
sort
[_ai |_ci]
, where sort
is an NLS language. You can add a suffix to the language to modify the sort: _ai
for an accent-insensitive sort, or _ci
for a case-insensitive sort.
NLSSORT
returns the string of bytes used to sort a text string. You can use this function to specify sorting and comparison operations based on a linguistic sort sequence rather than on the binary value of a string.
Note: NLSSORT
returns a RAW
value, which you may pass to another function. To create a measure or a calculated measure for the values returned by NLSSORT
, use the RAWTOHEX
function.
For more information about linguistic sorting, refer to the Oracle Database Globalization Support Guide.
char
is a text expression.
nlsparam
is a linguistic sort sequence in the form NLS_SORT =
sort
[_ai |_ci]
, where sort
is an NLS language. You can add a suffix to the language to modify the sort: _ai
for an accent-insensitive sort, or _ci
for a case-insensitive sort.
NULLIF
compares one expression with another. It returns NULL
when the expressions are equal, or the first expression when they are not.
expr1
is the base expression. It cannot be a literal null.
expr2
is the expression to compare with the base expression.
NUMTODSINTERVAL
converts a number to an INTERVAL DAY TO SECOND
data type.
n
can be any numeric expression.
interval_unit
is a text expression that specifies the units. It must resolve to one of the following values:
DAY
HOUR
MINUTE
SECOND
These values are case insensitive.
NUMTOYMINTERVAL
converts a number to an INTERVAL YEAR TO MONTH
data type.
n
can be any numeric expression.
interval_unit
is a text expression that specifies the units. It must resolve to one of the following values:
YEAR
MONTH
These values are case insensitive.
NVL
replaces a null with a string. NVL
returns the replacement string when the base expression is null, and the value of the base expression when it is not null.
To replace an expression with one value if it is null and a different value if it is not, use NVL2
.
expr1
is the base expression that is evaluated.
expr2
is the replacement string that is returned when expr1
is null.
NVL2
returns one value when the value of a specified expression is not null, or another value when the value of the specified expression is null.
To replace a null value with a string, use NVL
.
expr1
is the base expression whose value this function evaluates.
expr2
is an expression whose value is returned when expr1
is not null.
expr3
is an expression whose value is returned when expr1
is null.
ORA_HASH
generates hash values for an expression. You can use it to randomly assign a set of values into several buckets for analysis, or to generate a set of random numbers.
expr
can be any expression that provides the data for generating the hash values.
max_bucket
is the maximum bucket number. For example, when max_bucket
is set to 5, ORA_HASH
returns values of 0 to 5, creating six buckets. Set this value from 0 to 4294967295 or 2^32-1 (default).
seed_value
is a value used by ORA_HASH
to generate the hash values. Enter a different seed_value
for different results. Set this value from 0 (default) to 4294967295 or 2^32-1.
ORA_HASH(PRODUCT_CUBE.PRICES, 5)
returns a value in the range of 0 to 5 for each value of the Prices measure, as shown in the Hash 5 column. The rows are also sorted on the Hash 5 column.
ORA_HASH(PRODUCT_CUBE.PRICES, 5, 13)
also returns values in the range of 0 to 5, but uses a different seed.
Product | Prices | Hash 5 | Seed 13 |
---|---|---|---|
ENVY STD | 200539.83 | 0 | 4 |
ENVY EXE | 255029.31 | 0 | 5 |
1GB USB DRV | 44645.65 | 1 | 2 |
DLX MOUSE | 1379.49 | 2 | 2 |
144MB DISK | 3011.43 | 2 | 5 |
512 USB DRV | 22139.99 | 2 | 2 |
19 SVGA | 34837.16 | 3 | 0 |
56KPS MODEM | 12478 | 3 | 2 |
ENVY EXT KBD | 4312.22 | 3 | 5 |
17 SVGA | 22605.55 | 4 | 1 |
EXT CD ROM | 17990.14 | 4 | 0 |
ENVY ABM | 205462.25 | 5 | 1 |
POWER
raises a number to a power.
RAWTOHEX
converts raw data to a character value containing its hexadecimal representation.
REGEXP_COUNT
searches a string for a regular pattern and returns the number of times the pattern occurs. If no match is found, the function returns 0.
The function evaluates strings using characters as defined by the input character set.
source_char
is the text expression to search.
pattern
is the string to search for. A period matches any character. For a list of operators, refer to the Oracle Database SQL Language Reference, Appendix D, "Oracle Regular Expression Support."
position
is a nonzero integer indicating the character of source_char
where the function begins the search. When position
is negative, then the function counts and searches backward from the end of string. The default value of position
is 1, which means that the function begins searching at the first character of source_char
.
match_parameter
is a text literal that lets you change the default matching behavior of the function. You can specify one or more of the following values:
c
: Case-sensitive matching.
i
: Case-insensitive matching.
m
: Treat the source string as multiple lines. The function interprets ^
and $
as the start and end, respectively, of any line anywhere in the source string, rather than only at the start or end of the entire source string. By default, the function treats the source string as a single line.
n
: New-line character is among the characters matched by a period (the wildcard character). By default, it is not.
x
: Ignore whitespace characters.
REGEXP_INSTR
searches a string for a regular pattern. It can return an integer indicating either the beginning or the ending position of the matched substring. If no match is found, then the function returns 0.
The function evaluates strings using characters as defined by the input character set.
REGEXP_INSTR (source_char, pattern
[, position
[, occurrence
[, return_option
[, match_parameter ]
]
]
]
)
source_char
is the text expression to search.
pattern
is the string to search for. A period matches any character. For a list of operators, refer to the Oracle Database SQL Language Reference, Appendix D, Oracle Regular Expression Support.
position
is a nonzero integer indicating the character of source_char
where the function begins the search. When position
is negative, then the function counts and searches backward from the end of string. The default value of position
is 1, which means that the function begins searching at the first character of source_char
.
occurrence
is an integer indicating which occurrence of pattern
the function should search for. The value of occurrence
must be positive. The default values of occurrence
is 1, meaning the function searches for the first occurrence of pattern
.
return_option
is either 0 to return the position of the match (default), or 1 to return the position of the character following the match.
match_parameter
is a text literal that lets you change the default matching behavior of the function. You can specify one or more of the following values:
c
: Case-sensitive matching.
i
: Case-insensitive matching.
m
: Treat the source string as multiple lines. The function interprets ^
and $
as the start and end, respectively, of any line anywhere in the source string, rather than only at the start or end of the entire source string. By default, the function treats the source string as a single line.
n
: New-line character is among the characters matched by a period (the wildcard character). By default, it is not.
x
: Ignore whitespace characters.
REGEXP_REPLACE
searches a string for a regular pattern and replaces it with another string. By default, the function returns source_char
with every occurrence of the regular expression pattern replaced with replace_string
.
REGEXP_REPLACE(source_char, pattern
[, replace_string
[, position
[, occurrence
[, match_parameter ]
]
]
]
)
source_char
is the text expression that is searched.
pattern
is the text expression to search for. It is usually a text literal and can contain up to 512 bytes. For a list of operators, refer to the Oracle Database SQL Language Reference, Appendix D, "Oracle Regular Expression Support."
replace_string
is the text that replaces pattern
in source_char
.
position
is a nonzero integer indicating the character of source_char
where the function begins the search. When position
is negative, then the function counts and searches backward from the end of string. The default value of position
is 1, which means that the function begins searching at the first character of source_char
.
occurrence
is an integer indicating which occurrence of pattern
the function should search for. The value of occurrence
must be positive. The default values of occurrence
is 1, meaning the function searches for the first occurrence of pattern
.
match_parameter
is a text literal that lets you change the default matching behavior of the function. You can specify one or more of the following values:
c
: Case-sensitive matching.
i
: Case-insensitive matching.
m
: Treat the source string as multiple lines. The function interprets ^
and $
as the start and end, respectively, of any line anywhere in the source string, rather than only at the start or end of the entire source string. By default, the function treats the source string as a single line.
n
: New-line character is among the characters matched by a period (the wildcard character). By default, it is not.
x
: Ignore whitespace characters.
REGEXP_SUBSTR
searches a string for a pattern and returns the matching string.
source_char
is the text expression that is searched.
pattern
is the text expression to search for. It is usually a text literal and can contain up to 512 bytes. For a list of operators, refer to the Oracle Database SQL Language Reference, Appendix D, "Oracle Regular Expression Support."
position
is a nonzero integer indicating the character of source_char
where the function begins the search. When position
is negative, then the function counts and searches backward from the end of string. The default value of position
is 1, which means that the function begins searching at the first character of source_char
.
occurrence
is an integer indicating which occurrence of pattern
the function should search for. The value of occurrence
must be positive. The default values of occurrence
is 1, meaning the function searches for the first occurrence of pattern
.
match_parameter
is a text expression that lets you change the default matching behavior of the function. You can specify one or more of the following values:
c
: Case-sensitive matching.
i
: Case-insensitive matching.
m
: Treat the source string as multiple lines. The function interprets ^
and $
as the start and end, respectively, of any line anywhere in the source string, rather than only at the start or end of the entire source string. By default, the function treats the source string as a single line.
n
: New-line character is among the characters matched by a period (the wildcard character). By default, it is not.
x
: Ignore whitespace characters.
REGEXP_SUBSTR('7 W 96th St, New York, NEW YORK', 'new york', 10, 2, 'i')
starts searching at the tenth character and matches NEW YORK
in a case-insensitive match.
REGEXP_SUBSTR('parsley, sage, rosemary, thyme', 's[^,]+e', 1, 2)
starts searching at the first character and matches the second substring consisting of the letter s
, any number of characters that are not commas, and the letter e
. In this example, the function returns the value sage
.
REMAINDER
returns a rounded remainder when one number is divided by another using this equation:
n2 - (n1 * N)
where N
is the integer nearest n2/n1
.
REPLACE
searches a string for a regular pattern, replaces it with another string, and returns the modified string.
char
is the text expression that is searched.
search_string
is the text expression to search for.
replacement_string
is the text expression that replaces search_string
in char
.
ROUND
returns a date rounded to the unit specified by the date format.
date
is an expression that identifies a date and time.
fmt
is a text literal with a date format, as described in the Oracle Database SQL Language Reference.
ROUND
returns a number rounded to a specified number of places.
n
is the number to round.
integer
is the number of decimal places of the rounded number. A negative value rounds to the left of the decimal point. The default value is 0.
ROWIDTOCHAR
converts a row address from a ROWID
data type to text.The return value is always 18 characters long in the database character set.
ROWIDTONCHAR
converts a row address from the ROWID
data type to text. The return value is always 18 characters in the national character set.
RPAD
adds characters to the right of an expression to a specified length. The data type of the return value is the same as the original text.
Use LPAD
to add characters to the left.
expr1
is a text expression for the base string.
n
is the total length of the returned expression. If expr1
is longer than n
, then this function truncates expr1
to n
characters.
expr2
is a text expression for the padding characters. By default, it is a space.
RTRIM
scans a text expression from right to left and removes all the characters that match the characters in the trim expression, until it finds an unmatched character. The data type of the return value is the same as the original text.
char
is the text expression to be trimmed.
set
is a text expression with the characters to remove. The default value of set
is a single blank.
SESSIONTIMEZONE
returns the time zone of the current session. The return type is a time zone offset from Coordinated Universal Time (UTC) or a time zone region name.
SIGN
returns a value that indicates whether a specified number is less than, equal to, or greater than 0 (zero):
-1
if n < 0
0
if n = 0
1
if n > 0
SIN
returns the sine of an angle.
SINH
returns the sine of a hyperbolic angle.
SOUNDEX
returns a character string containing the phonetic representation of a text expression. This function lets you compare words that are spelled differently but sound alike.
The function is based on the algorithm described in Donald Knuth's The Art of Computer Programming. This algorithm was designed specifically for English. Its results for other languages other than English are unpredictable and typically unsatisfactory.
SQRT
returns the square root of a number.
SUBSTR
returns a portion of string, beginning at a specified character position and extending a specified number of characters.
SUBSTR
calculates lengths using characters as defined by the input character set.
SUBSTRB
uses bytes instead of characters.
SUBSTRC
uses Unicode complete characters.
char
is a text expression that provides the base string from which the substring is derived.
position
identifies the first character of the substring:
When position
is positive, then the function counts from the beginning of char
to find the first character.
When position
is negative, then the function counts backward from the end of char
.
When position
is 0 (zero), then the first character is the beginning of the substring.
substring_length
is the number of characters in the returned string. By default, the function returns all characters to the end of the base string. If you specify a value less than 1, then the function returns a null.
SYS_CONTEXT
returns the value of an attribute of a named context. The context, attribute, and value must already be defined in the database. If the context is not defined, SYS_CONTEXT
returns NULL
.
namespace
can be any named context in the database. USERENV
is a built-in context that describes the current session.
parameter
is a defined attribute of namespace
. Table 3-3 describes the predefined attributes of USERENV
that are most likely to have values. For a complete list, refer to the SYS_CONTEXT
entry in the Oracle Database SQL Language Reference.
USERENV Attribute | Description |
---|---|
|
The identity used for authentication, such as database user name, schema name, or operating system login name. |
|
The method of authentication, such as |
|
The session edition identifier, such as |
|
The session edition name, such as |
|
The name of the currently active default schema, such as |
|
The numeric identifier of the currently active default schema, such as |
|
The name of the database user whose privileges are currently active, such as |
|
The numeric identifier of the database user whose privileges are currently active, such as |
|
Data Guard role of the database: |
|
The network domain of the database as specified by the |
|
The name of the database as specified by the |
|
The unique name of the database within the domain as specified by the |
|
The enterprise-wide identity of the user, or |
|
Job identifier of the current session if a client foreground process opened it; otherwise, |
|
The number used in the System Global Area by the globally accessed context. |
|
The global user identification from Oracle Internet Directory for Enterprise User Security logins; otherwise, |
|
The name of the client host computer. |
|
The way the user schema was created in the database: |
|
The identification number of the current instance, such as |
|
The name of the database instance. |
|
The IP address of the client, such as |
|
|
|
A short name for the session language, such as |
|
The language, territory, and database character set in the form |
|
The application name set through the |
|
The network protocol being used for communication, such as |
|
The session calendar, such as |
|
The session currency mark, such as |
|
The session date format, such as |
|
The session date language, such as |
|
|
|
The session territory, such as |
|
The operating system user name of the client process that initiated the database session. |
|
The host name of the computer where the database instance is running. |
|
The name of the service the session is connected to, such as |
|
The database user name or schema name that identified the user at login, such as |
|
The session identifier, such as |
|
The session number, such as |
SYSDATE
returns the current date and time of the operating system on which the database resides. The format of the value depends on the value of the NLS_DATE_FORMAT
initialization parameter.
SYSTIMESTAMP
returns the system date, including fractional seconds and time zone, of the system on which the database resides.
TAN
returns the tangent of an angle.
TANH
returns the tangent of a hyperbolic angle.
TO_BINARY_DOUBLE
converts a text or numeric expression to a double-precision floating-point number.
n
can be any text or numeric expression.
fmt
is a text expression that identifies a number format model as described in the Oracle Database SQL Language Reference.
nlsparam
specifies the characters used by these number format elements:
Decimal character
Group separator
Local currency symbol
International currency symbol
This argument has the format shown here:
'NLS_NUMERIC_CHARACTERS = ''dg'' NLS_CURRENCY = ''text'' NLS_ISO_CURRENCY = territory '
The d
is the decimal character, and the g
is the group separator. They must be different single-byte characters. Within the quoted string, use two single quotation marks around the parameter values. Ten characters are available for the currency symbol.
If you omit this argument or any of the NLS parameters, then this function uses the default values for your session to interpret expr
.
TO_BINARY_FLOAT
converts a text or numeric expression to a single-precision floating-point number.
n
can be any text or numeric expression.
fmt
is a text expression that identifies a number format model as described in the Oracle Database SQL Language Reference.
nlsparam
specifies the characters used by these number format elements:
Decimal character
Group separator
Local currency symbol
International currency symbol
This argument has the format shown here:
'NLS_NUMERIC_CHARACTERS = ''dg'' NLS_CURRENCY = ''text'' NLS_ISO_CURRENCY = territory '
The d
is the decimal character, and the g
is the group separator. They must be different single-byte characters. Within the quoted string, use two single quotation marks around the parameter values. Ten characters are available for the currency symbol.
If you omit this argument or any of the NLS parameters, then this function uses the default values for your session to interpret expr
.
TO_CHAR(character)
converts a text expression to the database character set.
char
is a text expression. If it contains characters that are not represented in the database character set, then the conversion results in a loss of data.
TO_CHAR('¡Una qué sorpresa!')
returns the value ?Una qu? sorpresa!
Two letters are lost in the conversion (¡
and é
) because they are not in the database character set.
TO_CHAR('David Ortiz')
returns the value David Ortiz
in the database character set. No characters are lost in this conversion because all of them are in the database character set.
TO_CHAR(datetime)
converts a datetime or interval expression to a text string in a specified format.
datetime
is a datetime expression to be converted to text.
interval
is an interval expression to be converted to text.
fmt
is a datetime model format specifying the format of char
. The default date format is determined implicitly by the NLS_TERRITORY
initialization parameter or can be set explicitly by the NLS_DATE_FORMAT
parameter. For data type formats, refer to the Oracle Database SQL Language Reference.
nlsparam
specifies the language in which month and day names and abbreviations are returned. This argument can have this form:
'NLS_DATE_LANGUAGE = language'
By default, the return value is in the session date language.
TO_CHAR(number)
converts a numeric expression to a text value in the database character set.
n
is a numeric expression to be converted.
fmt
is a text expression that identifies a number format model as described in the Oracle Database SQL Language Reference.
nlsparam
specifies the characters that are returned by these number format elements:
Decimal character
Group separator
Local currency symbol
International currency symbol
This argument has the format shown here:
'NLS_NUMERIC_CHARACTERS = ''dg'' NLS_CURRENCY = ''text'' NLS_ISO_CURRENCY = territory '
The characters d
and g
represent the decimal character and group separator, respectively. They must be different single-byte characters. Within the quoted string, use two single quotation marks around the parameter values. Ten characters are available for the currency symbol.
If you omit this argument or any of the NLS parameters, then this function uses the default values for your session.
TO_DATE
converts a text expression to a DATE
data type.
char
is a text expression that represents a date.
fmt
is a datetime model format specifying the format of char
. The default date format is determined implicitly by the NLS_TERRITORY
initialization parameter or can be set explicitly by the NLS_DATE_FORMAT
parameter. For data type formats, refer to the Oracle Database SQL Language Reference.
nlsparam
specifies the language of char
. This argument can have this form:
'NLS_DATE_LANGUAGE = language'
By default, char
is in the session date language.
TO_DSINTERVAL
converts a text expression to an INTERVAL DAY TO SECOND
data type.
TO_NCHAR(character)
converts a character string to the national character set.
exp
is a text expression. If it contains characters that are not represented in the national character set, then the conversion results in a loss of data.
TO_NCHAR(datetime)
converts a datetime or interval value to the national character set.
datetime
is a datetime expression to be converted to text.
interval
is an interval expression to be converted to text.
fmt
is a datetime model format specifying the format of char
. The default date format is determined implicitly by the NLS_TERRITORY
initialization parameter or can be set explicitly by the NLS_DATE_FORMAT
parameter. For data type formats, refer to the Oracle Database SQL Language Reference.
nlsparam
specifies the language in which month and day names and abbreviations are returned. This argument can have this form:
'NLS_DATE_LANGUAGE = language'
By default, the return value is in the session date language.
TO_NCHAR(number)
converts a number to the national character set.
n
is a numeric expression to be converted.
fmt
is a text expression that identifies a number format model as described in the Oracle Database SQL Language Reference.
nlsparam
is a text expression that specifies the characters that are returned by these number format elements:
Decimal character
Group separator
Local currency symbol
International currency symbol
This argument has the format shown here:
'NLS_NUMERIC_CHARACTERS = ''dg'' NLS_CURRENCY = ''text'' NLS_ISO_CURRENCY = territory '
The characters d
and g
represent the decimal character and group separator, respectively. They must be different single-byte characters. Within the quoted string, use two single quotation marks around the parameter values. Ten characters are available for the currency symbol.
If you omit this argument or any of the NLS parameters, then this function uses the default values for your session.
TO_NUMBER
converts a text expression containing a number to a value of NUMBER
data type.
expr
is an expression to be converted to a number.
fmt
is a text expression that identifies a number format model as described in the Oracle Database SQL Language Reference.
nlsparam
specifies the characters used by these number format elements:
Decimal character
Group separator
Local currency symbol
International currency symbol
This argument has the format shown here:
'NLS_NUMERIC_CHARACTERS = ''dg'' NLS_CURRENCY = ''text'' NLS_ISO_CURRENCY = territory '
The d
is the decimal character, and the g
is the group separator. They must be different single-byte characters. Within the quoted string, use two single quotation marks around the parameter values. Ten characters are available for the currency symbol.
If you omit this argument or any of the NLS parameters, then this function uses the default values for your session to interpret expr
.
TO_TIMESTAMP
converts a text expression to a value of TIMESTAMP
.
char
is a text expression to be converted.
fmt
is a datetime model format specifying the format of char
. The default date format is determined implicitly by the NLS_TERRITORY
initialization parameter or can be set explicitly by the NLS_DATE_FORMAT
parameter. For data type formats, refer to the Oracle Database SQL Language Reference.
nlsparam
specifies the language in which month and day names and abbreviations given in char
. This argument has this form:
'NLS_DATE_LANGUAGE = language'
By default, char
is in the session date language.
TO_TIMESTAMP_TZ
converts a text expression to a value of TIMESTAMP
WITH
TIME
ZONE
data type.
char
is a text expression to be converted.
fmt
is a datetime model format specifying the format of char
. The default date format is determined implicitly by the NLS_TERRITORY
initialization parameter or can be set explicitly by the NLS_DATE_FORMAT
parameter. For data type formats, refer to the Oracle Database SQL Language Reference.
nlsparam
specifies the language in which month and day names and abbreviations given in char
. This argument has this form:
'NLS_DATE_LANGUAGE = language'
By default, char
is in the session date language.
TO_TIMESTAMP_TZ('2006-03-26 7:33:00 -4:00', 'YYYY-MM-DD HH:MI:SS TZH:TZM')
returns the value 26-MAR-06 07.33.00.000000 AM -04:00
.
TO_TIMESTAMP_TZ('2006-AGOSTO-13 7:33:00 -4:00', 'YYYY-MONTH-DD HH:MI:SS TZH:TZM', 'NLS_DATE_LANGUAGE=SPANISH')
returns the value 13-AUG-06 07.33.00.000000 AM -04:00
.
TO_YMINTERVAL
converts a text expression to an INTERVAL YEAR TO MONTH
data type. The function accepts argument in one of the two formats:
SQL interval format compatible with the SQL standard (ISO/IEC 9075:2003)
ISO duration format compatible with the ISO 8601:2004 standard
TO_YMINTERVAL ( ' { sql_format | ym_iso_format } ' ) sql_format::= [+|-] years - months ym_iso_format::= [-] P [ years Y ] [months M ] [days D ] [ T [hours H ] [minutes M ] [seconds [. frac_secs] S ] ]
In SQL format:
years
is an integer between 0 and 999999999
months
is an integer between 0 and 11.
Additional blanks are allowed between format elements.
In ISO format:
years
and months
are integers between 0 and 999999999.
days
, hours
, minutes
, seconds
, and frac_secs
are nonnegative integers and are ignored.
No blanks are allowed in the value.
TO_YMINTERVAL('1-6')
and TO_YMINTERVAL('P1Y6M')
return the value +01-06
for 1 year and 6 months.
SYSDATE + TO_YMINTERVAL('1-6')
adds one year and six months to the current date. When SYSDATE
is 15-APR-08
, the value is 15-OCT-09
.
SYSDATE + TO_YMINTERVAL('P1Y6M')
adds one year and six months to the current date using ISO format. When SYSDATE
is 15-APR-08
, the value is 15-OCT-09
.
SYSDATE + TO_YMINTERVAL('-1-2')
subtracts one year and two months from the current date. When SYSDATE
is 15-APR-08
, the value is 15-FEB-07
.
TRANSLATE
enables you to make several single-character, one-to-one substitutions in one operation. This expression returns an expression with all occurrences of each character in one string replaced by its corresponding character in a second string.
expr
is a text expression to be modified.
from_string
consists of one or more characters to be replaced in expr
.
to_string
consists of one or more characters that replace the corresponding characters in from_string
. This string can be shorter than from_string
, so that a null replaces the extra characters. However, to_string
cannot be empty.
TRANSLATE
converts a text string between the database character set and the national character set.
Note: The TRANSLATE USING
function is supported primarily for ANSI compatibility. Oracle recommends that you use the TO_CHAR
and TO_NCHAR
functions for converting data to the database or national character sets. TO_CHAR
and TO_NCHAR
can take as arguments a greater variety of data types than TRANSLATE USING
, which accepts only character data.
char
is a text expression to be converted to the database character set (USING CHAR_CS
) or the national character set (USING NCHAR_CS
).
TRIM
removes leading or trailing characters (or both) from a character string.
TRIM([ { { LEADING | TRAILING | BOTH }[ trim_character ] | trim_character } FROM ] trim_source )
LEADING
removes matching characters from the beginning of the string.
TRAILING
removes matching characters from the end of the string.
BOTH
removes matching characters from both the beginning and the end of the string. (Default)
trim_character
is a single character to be removed. By default, it is a space.
trim_source
is the text expression to be trimmed.
TRUNC
shortens a numeric expression to a specified number of decimal places.
n1
is the numeric expression to be truncated.
n2
is the number of decimal places. A positive number truncates digits to the right of the decimal point, and a negative number replaces digits to the left of the decimal point. The default value is zero (0).
TZ_OFFSET
returns the time zone offset from Coordinated Universal Time (UTC).
time_zone_name
is the name of a time zone.
hh:mm
are hours and minutes. This argument simply returns itself.
SESSIONTIMEZONE
returns the session time zone.
DBTIMEZONE
returns the database time zone.
UID
returns a unique identifier (UID) for the session user (the user who logged on).
UNISTR
converts a text string to the national character set.
string
can be any text expression. For portability, Oracle recommends using only ASCII characters and Unicode encoding values as text literals. A Unicode encoding value has the form \xxxx where xxxx is the hexadecimal value of a character. Supplementary characters are encoded as two code units, the first from the high-surrogates range (U+D800 to U+DBFF), and the second from the low-surrogates range (U+DC00 to U+DFFF). To include a literal backslash in the string, precede it with another backslash (\\).
UPPER
converts all alphabetic characters in a text expression to uppercase. The data type of the return value is the same as the original text.
USER
returns the name of the session user (the user who logged on).
VSIZE
returns the number of bytes in the internal representation of an expression. It returns NULL
for a null expression.
WIDTH_BUCKET
enables you to construct a histogram range divided into intervals of identical size. The function returns the bucket number into which the value of an expression falls.
When needed, WIDTH_BUCKET
creates an underflow bucket numbered 0 and an overflow bucket numbered num_buckets
+1. These buckets handle values outside the specified range and are helpful in checking the reasonableness of the end points.
expr
is the expression for which the histogram is being created. This expression must evaluate to a numeric or datetime value or to a value. If expr
evaluates to null, then the function returns NULL
.
min_value
and max_value
are expressions for the end points of the acceptable range for expr
. Both of these expressions must evaluate to numeric or datetime values, and neither can evaluate to null.
num_buckets
is an expression for the number of buckets. This expression must evaluate to a positive integer.