Functions

There are various types of functions that you can use in expressions.

Topics:

Aggregate Functions

Aggregate functions perform operations on multiple values to create summary results.

Function Example Description Syntax

AGGREGATE AT

AGGREGATE(sales AT month, region)

This function aggregates columns based on the level or levels you specify.

measure is the name of a measure column. level is the level at which you want to aggregate. You can optionally specify more than one level. You cannot specify a level from a dimension that contains levels that are being used as the measure level for the measure you specified in the first argument. For example, you cannot write the function as AGGREGATE(yearly_sales AT month) because month is from the same time dimension that is being used as the measure level for yearly_sales.

AGGREGATE(measure AT level [, level1, levelN])

AVG

Avg(Sales)

Calculates the average (mean) of a numeric set of values.

AVG(expr)

AVGDISTINCT

 

Calculates the average (mean) of all distinct values of an expression.

AVG(DISTINCT expr)

BIN

BIN(revenue BY productid, year WHERE productid > 2 INTO 4 BINS RETURNING RANGE_LOW)

The BIN function classifies a given numeric expression into a specified number of equal width buckets. The function can return either the bin number or one of the two end points of the bin interval. numeric_expr is the measure or numeric attribute to bin BY grain_expr1,…, grain_exprN is a list of expressions that define the grain at which the numeric_expr will be calculated. BY is required for measure expressions and is optional for attribute expressions. WHERE a filter to apply to the numeric_expr before the numeric values are assigned to bins INTO number_of_bins BINS is the number of bins to return BETWEEN min_value AND max_value is the min and max values used for the end points of the outermost bins RETURNING NUMBER indicates that the return value should be the bin number (1, 2, 3, 4, etc.). This is the default. RETURNING RANGE_LOW indicates the lower value of the bin interval RETURNING RANGE_HIGH indicates the higher value of the bin interval

BIN(numeric_expr [BY grain_expr1, ..., grain_exprN] [WHERE condition] INTO number_of_bins BINS [BETWEEN min_value AND max_value] [RETURNING {NUMBER | RANGE_LOW | RANGE_HIGH}])

BottomN

Ranks the lowest n values of the expression argument from 1 to n, 1 corresponding to the lowest numerical value.

expr is any expression that evaluates to a numerical value. integer is any positive integer. Represents the bottom number of rankings displayed in the result set, 1 being the lowest rank.

BottomN(expr, integer)

COUNT

COUNT(Products)

Determines the number of items with a non-null value.

COUNT(expr)

COUNTDISTINCT

Adds distinct processing to the COUNT function.

expr is any expression.

COUNT(DISTINCT expr)

COUNT*

SELECT COUNT(*) FROM Facts

Counts the number of rows.

COUNT(*)

First

First(Sales)

Selects the first non-null returned value of the expression argument. The First function operates at the most detailed level specified in your explicitly defined dimension.

First([NumericExpression)]

Last

Last(Sales)

Selects the last non-null returned value of the expression.

Last([NumericExpression)]

MAVG

Calculates a moving average (mean) for the last n rows of data in the result set, inclusive of the current row.

expr is any expression that evaluates to a numerical value. integer is any positive integer. Represents the average of the last n rows of data.

MAVG(expr, integer)

MAX

MAX(Revenue)

Calculates the maximum value (highest numeric value) of the rows satisfying the numeric expression argument.

MAX(expr)

MEDIAN

MEDIAN(Sales)

Calculates the median (middle) value of the rows satisfying the numeric expression argument. When there are an even number of rows, the median is the mean of the two middle rows. This function always returns a double.

MEDIAN(expr)

MIN

MIN(Revenue)

Calculates the minimum value (lowest numeric value) of the rows satisfying the numeric expression argument.

MIN(expr)

NTILE

Determines the rank of a value in terms of a user-specified range. It returns integers to represent any range of ranks. NTILE with numTiles=100 returns what is commonly called the "percentile" (with numbers ranging from 1 to 100, with 100 representing the high end of the sort).

expr is any expression that evaluates to a numerical value. numTiles is a positive, nonnull integer that represents the number of tiles.

NTILE(expr, numTiles)

PERCENTILE

Calculates a percentile rank for each value satisfying the numeric expression argument. The percentile rank ranges are between 0 (0th percentile) to 1 (100th percentile).

expr is any expression that evaluates to a numerical value.

PERCENTILE(expr)

RANK

RANK(chronological_key, null, year_key_columns)

Calculates the rank for each value satisfying the numeric expression argument. The highest number is assigned a rank of 1, and each successive rank is assigned the next consecutive integer (2, 3, 4,...). If certain values are equal, they are assigned the same rank (for example, 1, 1, 1, 4, 5, 5, 7...).

expr is any expression that evaluates to a numerical value.

RANK(expr)

STDDEV

STDDEV(Sales) STDDEV(DISTINCT Sales)

Returns the standard deviation for a set of values. The return type is always a double.

STDDEV(expr)

STDDEV_POP

STDDEV_POP(Sales) STDDEV_POP(DISTINCT Sales)

Returns the standard deviation for a set of values using the computational formula for population variance and standard deviation.

STDDEV_POP([NumericExpression])

SUM

SUM(Revenue)

Calculates the sum obtained by adding up all values satisfying the numeric expression argument.

SUM(expr)

SUMDISTINCT

Calculates the sum obtained by adding all of the distinct values satisfying the numeric expression argument.

expr is any expression that evaluates to a numerical value.

SUM(DISTINCT expr)

TOPN

Ranks the highest n values of the expression argument from 1 to n, 1 corresponding to the highest numerical value.

expr is any expression that evaluates to a numerical value. integer is any positive integer. Represents the top number of rankings displayed in the result set, 1 being the highest rank.

TOPN(expr, integer)

Analytics Functions

Analytics functions allow you to explore data using models such as trendline and cluster.

Function Example Description Syntax

TRENDLINE

TRENDLINE(revenue, (calendar_year, calendar_quarter, calendar_month) BY (product), 'LINEAR', 'VALUE')

Fits a linear or exponential model and returns the fitted values or model. The numeric_expr represents the Y value for the trend and the series (time columns) represent the X value.

TRENDLINE(numeric_expr, ([series]) BY ([partitionBy]), model_type, result_type)

CLUSTER

CLUSTER((product, company), (billed_quantity, revenue), 'clusterName', 'algorithm=k-means;numClusters=%1;maxIter=%2;useRandomSeed=FALSE;enablePartitioning=TRUE', 5, 10)

Collects a set of records into groups based on one or more input expressions using K-Means or Hierarchical Clustering.

CLUSTER((dimension_expr1 , ... dimension_exprN), (expr1, ... exprN), output_column_name, options, [runtime_binded_options])

OUTLIER

OUTLIER((product, company), (billed_quantity, revenue), 'isOutlier', 'algorithm=kmeans')

This function classifies a record as Outlier based on one or more input expressions using K-Means or Hierarchical Clustering or Multi-Variate Outlier detection Algorithms.

OUTLIER((dimension_expr1 , ... dimension_exprN), (expr1, ... exprN), output_column_name, options, [runtime_binded_options])

REGR

REGR(revenue, (discount_amount), (product_type, brand), 'fitted', '')

Fits a linear model and returns the fitted values or model. This function can be used to fit a linear curve on two measures.

REGR(y_axis_measure_expr, (x_axis_expr), (category_expr1, ..., category_exprN), output_column_name, options, [runtime_binded_options])

Calendar Functions

Calendar functions manipulate data of the data types DATE and DATETIME based on a calendar year.

Function Example Description Syntax

CURRENT_Date

CURRENT_DATE

Returns the current date.

The date is determined by the system in which the Oracle BI is running.

CURRENT_DATE

CURRENT_TIME

CURRENT_TIME(3)

Returns the current time to the specified number of digits of precision, for example: HH:MM:SS.SSS

If no argument is specified, the function returns the default precision.

CURRENT_TIME(expr)

CURRENT_TIMESTAMP

CURRENT_TIMESTAMP(3)

Returns the current date/timestamp to the specified number of digits of precision.

CURRENT_TIMESTAMP(expr)

DAYNAME

DAYNAME(Order_Date)

Returns the name of the day of the week for a specified date expression.

DAYNAME(expr)

DAYOFMONTH

DAYOFMONTH(Order_Date)

Returns the number corresponding to the day of the month for a specified date expression.

DAYOFMONTH(expr)

DAYOFWEEK

DAYOFWEEK(Order_Date)

Returns a number between 1 and 7 corresponding to the day of the week for a specified date expression. For example, 1 always corresponds to Sunday, 2 corresponds to Monday, and so on through to Saturday which returns 7.

DAYOFWEEK(expr)

DAYOFYEAR

DAYOFYEAR(Order_Date)

Returns the number (between 1 and 366) corresponding to the day of the year for a specified date expression.

DAYOFYEAR(expr)

DAY_OF_QUARTER

DAY_OF_QUARTER(Order_Date)

Returns a number (between 1 and 92) corresponding to the day of the quarter for the specified date expression.

DAY_OF_QUARTER(expr)

HOUR

HOUR(Order_Time)

Returns a number (between 0 and 23) corresponding to the hour for a specified time expression. For example, 0 corresponds to 12 a.m. and 23 corresponds to 11 p.m.

HOUR(expr)

MINUTE

MINUTE(Order_Time)

Returns a number (between 0 and 59) corresponding to the minute for a specified time expression.

MINUTE(expr)

MONTH

MONTH(Order_Time)

Returns the number (between 1 and 12) corresponding to the month for a specified date expression.

MONTH(expr)

MONTHNAME

MONTHNAME(Order_Time)

Returns the name of the month for a specified date expression.

MONTHNAME(expr)

MONTH_OF_QUARTER

MONTH_OF_QUARTER(Order_Date)

Returns the number (between 1 and 3) corresponding to the month in the quarter for a specified date expression.

MONTH_OF_QUARTER(expr)

NOW

NOW()

Returns the current timestamp. The NOW function is equivalent to the CURRENT_TIMESTAMP function.

NOW()

QUARTER_OF_YEAR

QUARTER_OF_YEAR(Order_Date)

Returns the number (between 1 and 4) corresponding to the quarter of the year for a specified date expression.

QUARTER_OF_YEAR(expr)

SECOND

SECOND(Order_Time)

Returns the number (between 0 and 59) corresponding to the seconds for a specified time expression.

SECOND(expr)

TIMESTAMPADD

TIMESTAMPADD(SQL_TSI_MONTH, 12,Time."Order Date")

Adds a specified number of intervals to a timestamp, and returns a single timestamp.

Interval options are: SQL_TSI_SECOND, SQL_TSI_MINUTE, SQL_TSI_HOUR, SQL_TSI_DAY, SQL_TSI_WEEK, SQL_TSI_MONTH, SQL_TSI_QUARTER, SQL_TSI_YEAR

TIMESTAMPADD(interval, expr, timestamp)

TIMESTAMPDIFF

TIMESTAMPDIFF(SQL_TSI_MONTH, Time."Order Date",CURRENT_DATE)

Returns the total number of specified intervals between two timestamps.

Use the same intervals as TIMESTAMPADD.

TIMESTAMPDIFF(interval, expr, timestamp2)

WEEK_OF_QUARTER

WEEK_OF_QUARTER(Order_Date)

Returns a number (between 1 and 13) corresponding to the week of the quarter for the specified date expression.

WEEK_OF_QUARTER(expr)

WEEK_OF_YEAR

WEEK_OF_YEAR(Order_Date)

Returns a number (between 1 and 53) corresponding to the week of the year for the specified date expression.

WEEK_OF_YEAR(expr)

YEAR

YEAR(Order_Date)

Returns the year for the specified date expression.

YEAR(expr)

Conversion Functions

Conversion functions convert a value from one form to another.

Function Example Description Syntax

CAST

CAST(hiredate AS CHAR(40)) FROM employee

Changes the data type of an expression or a null literal to another data type. For example, you can cast a customer_name (a data type of CHAR or VARCHAR) or birthdate (a datetime literal).

Use CAST to change to a Date data type.

Don’t use TODATE.

CAST(expr AS type)

IFNULL

IFNULL(Sales, 0)

Tests if an expression evaluates to a null value, and if it does, assigns the specified value to the expression.

IFNULL(expr, value)

INDEXCOL

SELECT INDEXCOL(VALUEOF (NQ_SESSION.GEOGRAPHY_LEVEL), Country, State, City), Revenue FROM Sales

Uses external information to return the appropriate column for the signed-in user to see.

INDEXCOL([integer literal], [expr1] [, [expr2], ?-])

NULLIF

SELECT e.last_name, NULLIF(e.job_id, j.job_id) "Old Job ID" FROM employees e, job_history j WHERE e.employee_id = j.employee_id ORDER BY last_name, "Old Job ID";

Compares two expressions. If they’re equal, then the function returns NULL. If they’re not equal, then the function returns the first expression. You can’t specify the literal NULL for the first expression.

NULLIF([expression], [expression])

To_DateTime

SELECT To_DateTime ('2009-03-0301:01:00', 'yyyy-mm-dd hh:mi:ss') FROM sales

Converts string literals of DateTime format to a DateTime data type.

To_DateTime([expression], [literal])

VALUEOF

SalesSubjectArea.Customer.Region = VALUEOF("Region Security"."REGION")

References the value of an Oracle BI repository variable in a filter.

Use expr variables as arguments of the VALUEOF function. Refer to static repository variables by name.

VALUEOF(expr)

Display Functions

Display functions operate on the result set of a query.

Function Example Description Syntax

BottomN

BottomN(Sales, 10)

Returns the n lowest values of expression, ranked from lowest to highest.

BottomN([NumericExpression], [integer])

FILTER

FILTER(Sales USING Product = 'widget')

Computes the expression using the given preaggregate filter.

FILTER(measure USING filter_expr)

MAVG

MAVG(Sales, 10)

Calculates a moving average (mean) for the last n rows of data in the result set, inclusive of the current row.

MAVG([NumericExpression], [integer])

MSUM

SELECT Month, Revenue, MSUM(Revenue, 3) as 3_MO_SUM FROM Sales

Calculates a moving sum for the last n rows of data, inclusive of the current row.

The sum for the first row is equal to the numeric expression for the first row. The sum for the second row is calculated by taking the sum of the first two rows of data, and so on. When the n th row is reached, the sum is calculated based on the last n rows of data.

MSUM([NumericExpression], [integer])

NTILE

NTILE(Sales, 100)

Determines the rank of a value in terms of a user-specified range. It returns integers to represent any range of ranks. The example shows a range from 1 to 100, with the lowest sale = 1 and the highest sale = 100.

NTILE([NumericExpresssion], [integer])

PERCENTILE

PERCENTILE(Sales)

Calculates a percent rank for each value satisfying the numeric expression argument. The percentile rank ranges are from 0 (1st percentile) to 1 (100th percentile), inclusive.

PERCENTILE([NumericExpression])

RANK

RANK(Sales)

Calculates the rank for each value satisfying the numeric expression argument. The highest number is assigned a rank of 1, and each successive rank is assigned the next consecutive integer (2, 3, 4,...). If certain values are equal, they are assigned the same rank (for example, 1, 1, 1, 4, 5, 5, 7...).

RANK([NumericExpression])

RCOUNT

SELECT month, profit, RCOUNT(profit) FROM sales WHERE profit > 200

Takes a set of records as input and counts the number of records encountered so far.

RCOUNT([NumericExpression])

RMAX

SELECT month, profit, RMAX(profit) FROM sales

Takes a set of records as input and shows the maximum value based on records encountered so far. The specified data type must be one that can be ordered.

RMAX([NumericExpression])

RMIN

SELECT month, profit, RMIN(profit) FROM sales

Takes a set of records as input and shows the minimum value based on records encountered so far. The specified data type must be one that can be ordered.

RMIN([NumericExpression])

RSUM

SELECT month, revenue, RSUM(revenue) as RUNNING_SUM FROM sales

Calculates a running sum based on records encountered so far.

The sum for the first row is equal to the numeric expression for the first row. The sum for the second row is calculated by taking the sum of the first two rows of data, and so on.

RSUM([NumericExpression])

TOPN

TOPN(Sales, 10)

Returns the n highest values of expression, ranked from highest to lowest.

TOPN([NumericExpression], [integer])

Evaluate Functions

Evaluate functions are database functions that can be used to pass through expressions to get advanced calculations.

Embedded database functions can require one or more columns. These columns are referenced by %1 ... %N within the function. The actual columns must be listed after the function.

Function Example Description Syntax

EVALUATE

SELECT EVALUATE('instr(%1, %2)', address, 'Foster City') FROM employees

Passes the specified database function with optional referenced columns as parameters to the database for evaluation.

EVALUATE([string expression], [comma separated expressions])

EVALUATE_AGGR

EVALUATE_AGGR('REGR_SLOPE(%1, %2)', sales.quantity, market.marketkey)

Passes the specified database function with optional referenced columns as parameters to the database for evaluation. This function is intended for aggregate functions with a GROUP BY clause.

EVALUATE_AGGR('db_agg_function(%1...%N)' [AS datatype] [, column1, columnN])

Mathematical Functions

The mathematical functions described in this section perform mathematical operations.

Function Example Description Syntax

ABS

ABS(Profit)

Calculates the absolute value of a numeric expression.

expr is any expression that evaluates to a numerical value.

ABS(expr)

ACOS

ACOS(1)

Calculates the arc cosine of a numeric expression.

expr is any expression that evaluates to a numerical value.

ACOS(expr)

ASIN

ASIN(1)

Calculates the arc sine of a numeric expression.

expr is any expression that evaluates to a numerical value.

ASIN(expr)

ATAN

ATAN(1)

Calculates the arc tangent of a numeric expression.

expr is any expression that evaluates to a numerical value.

ATAN(expr)

ATAN2

ATAN2(1, 2)

Calculates the arc tangent of y /x, where y is the first numeric expression and x is the second numeric expression.

ATAN2(expr1, expr2)

CEILING

CEILING(Profit)

Rounds a non-integer numeric expression to the next highest integer. If the numeric expression evaluates to an integer, the CEILING function returns that integer.

CEILING(expr)

COS

COS(1)

Calculates the cosine of a numeric expression.

expr is any expression that evaluates to a numerical value.

COS(expr)

COT

COT(1)

Calculates the cotangent of a numeric expression.

expr is any expression that evaluates to a numerical value.

COT(expr)

DEGREES

DEGREES(1)

Converts an expression from radians to degrees.

expr is any expression that evaluates to a numerical value.

DEGREES(expr)

EXP

EXP(4)

Sends the value to the power specified. Calculates e raised to the n-th power, where e is the base of the natural logarithm.

EXP(expr)

ExtractBit

Int ExtractBit(1, 5)

Retrieves a bit at a particular position in an integer. It returns an integer of either 0 or 1 corresponding to the position of the bit.

ExtractBit([Source Number], [Digits])

FLOOR

FLOOR(Profit)

Rounds a non-integer numeric expression to the next lowest integer. If the numeric expression evaluates to an integer, the FLOOR function returns that integer.

FLOOR(expr)

LOG

LOG(1)

Calculates the natural logarithm of an expression.

expr is any expression that evaluates to a numerical value.

LOG(expr)

LOG10

LOG10(1)

Calculates the base 10 logarithm of an expression.

expr is any expression that evaluates to a numerical value.

LOG10(expr)

MOD

MOD(10, 3)

Divides the first numeric expression by the second numeric expression and returns the remainder portion of the quotient.

MOD(expr1, expr2)

PI

PI()

Returns the constant value of pi.

PI()

POWER

POWER(Profit, 2)

Takes the first numeric expression and raises it to the power specified in the second numeric expression.

POWER(expr1, expr2)

RADIANS

RADIANS(30)

Converts an expression from degrees to radians.

expr is any expression that evaluates to a numerical value.

RADIANS(expr)

RAND

RAND()

Returns a pseudo-random number between 0 and 1.

RAND()

RANDFromSeed

RAND(2)

Returns a pseudo-random number based on a seed value. For a given seed value, the same set of random numbers are generated.

RAND(expr)

ROUND

ROUND(2.166000, 2)

Rounds a numeric expression to n digits of precision.

expr is any expression that evaluates to a numerical value.

integer is any positive integer that represents the number of digits of precision.

ROUND(expr, integer)

SIGN

SIGN(Profit)

This function returns the following:

  • 1 if the numeric expression evaluates to a positive number

  • -1 if the numeric expression evaluates to a negative number

  • 0 if the numeric expression evaluates to zero

SIGN(expr)

SIN

SIN(1)

Calculates the sine of a numeric expression.

SIN(expr)

SQRT

SQRT(7)

Calculates the square root of the numeric expression argument. The numeric expression must evaluate to a nonnegative number.

SQRT(expr)

TAN

TAN(1)

Calculates the tangent of a numeric expression.

expr is any expression that evaluates to a numerical value.

TAN(expr)

TRUNCATE

TRUNCATE(45.12345, 2)

Truncates a decimal number to return a specified number of places from the decimal point.

expr is any expression that evaluates to a numerical value.

integer is any positive integer that represents the number of characters to the right of the decimal place to return.

TRUNCATE(expr, integer)

Running Aggregate Functions

Running aggregate functions perform operations on multiple values to create summary results.

Function Example Description Syntax

MAVG

 

Calculates a moving average (mean) for the last n rows of data in the result set, inclusive of the current row.

expr is any expression that evaluates to a numerical value. integer is any positive integer. Represents the average of the last n rows of data.

MAVG(expr, integer)

MSUM

select month, revenue, MSUM(revenue, 3) as 3_MO_SUM from sales_subject_area

This function calculates a moving sum for the last n rows of data, inclusive of the current row.

expr is any expression that evaluates to a numerical value. integer is any positive integer. Represents the sum of the last n rows of data.

MSUM(expr, integer)

RSUM

SELECT month, revenue, RSUM(revenue) as RUNNING_SUM from sales_subject_area

This function calculates a running sum based on records encountered so far.

expr is any expression that evaluates to a numerical value.

RSUM(expr)

RCOUNT

select month, profit, RCOUNT(profit) from sales_subject_area where profit > 200

This function takes a set of records as input and counts the number of records encountered so far.

expr is an expression of any datatype.

RCOUNT(expr)

RMAX

SELECT month, profit,RMAX(profit) from sales_subject_area

This function takes a set of records as input and shows the maximum value based on records encountered so far.

expr is an expression of any datatype.

RMAX(expr)

RMIN

select month, profit,RMIN(profit) from sales_subject_area

This function takes a set of records as input and shows the minimum value based on records encountered so far.

expr is an expression of any datatype.

RMIN(expr)

String Functions

String functions perform various character manipulations. They operate on character strings.

Function Example Description Syntax

ASCII

ASCII('a')

Converts a single character string to its corresponding ASCII code, between 0 and 255. If the character expression evaluates to multiple characters, the ASCII code corresponding to the first character in the expression is returned.

expr is any expression that evaluates to a character string.

ASCII(expr)

BIT_LENGTH

BIT_LENGTH('abcdef')

Returns the length, in bits, of a specified string. Each Unicode character is 2 bytes in length (equal to 16 bits).

expr is any expression that evaluates to a character string.

BIT_LENGTH(expr)

CHAR

CHAR(35)

Converts a numeric value between 0 and 255 to the character value corresponding to the ASCII code.

expr is any expression that evaluates to a numerical value between 0 and 255.

CHAR(expr)

CHAR_LENGTH

CHAR_LENGTH(Customer_Name)

Returns the length, in number of characters, of a specified string. Leading and trailing blanks aren’t counted in the length of the string.

expr is any expression that evaluates to a character string.

CHAR_LENGTH(expr)

CONCAT

SELECT DISTINCT CONCAT ('abc', 'def') FROM employee

Concatenates two character strings.

exprs are expressions that evaluate to character strings, separated by commas.

You must use raw data, not formatted data, with CONCAT.

CONCAT(expr1, expr2)

INSERT

SELECT INSERT('123456', 2, 3, 'abcd') FROM table

Inserts a specified character string into a specified location in another character string.

expr1 is any expression that evaluates to a character string. Identifies the target character string.

integer1 is any positive integer that represents the number of characters from the beginning of the target string where the second string is to be inserted.

integer2 is any positive integer that represents the number of characters in the target string to be replaced by the second string.

expr2 is any expression that evaluates to a character string. Identifies the character string to be inserted into the target string.

INSERT(expr1, integer1, integer2, expr2)

LEFT

SELECT LEFT('123456', 3) FROM table

Returns a specified number of characters from the left of a string.

expr is any expression that evaluates to a character string

integer is any positive integer that represents the number of characters from the left of the string to return.

LEFT(expr, integer)

LENGTH

LENGTH(Customer_Name)

Returns the length, in number of characters, of a specified string. The length is returned excluding any trailing blank characters.

expr is any expression that evaluates to a character string.

LENGTH(expr)

LOCATE

LOCATE('d' 'abcdef')

Returns the numeric position of a character string in another character string. If the character string isn’t found in the string being searched, the function returns a value of 0.

expr1 is any expression that evaluates to a character string. Identifies the string for which to search.

expr2 is any expression that evaluates to a character string.

Identifies the string to be searched.

LOCATE(expr1, expr2)

LOCATEN

LOCATE('d' 'abcdef', 3)

Like LOCATE, returns the numeric position of a character string in another character string. LOCATEN includes an integer argument that enables you to specify a starting position to begin the search.

expr1 is any expression that evaluates to a character string. Identifies the string for which to search.

expr2 is any expression that evaluates to a character string. Identifies the string to be searched.

integer is any positive (nonzero) integer that represents the starting position to begin to look for the character string.

LOCATEN(expr1, expr2, integer)

LOWER

LOWER(Customer_Name)

Converts a character string to lowercase.

expr is any expression that evaluates to a character string.

LOWER(expr)

OCTET_LENGTH

OCTET_LENGTH('abcdef')

Returns the number of bytes of a specified string.

expr is any expression that evaluates to a character string.

OCTET_LENGTH(expr)

POSITION

POSITION('d', 'abcdef')

Returns the numeric position of strExpr1 in a character expression. If strExpr1 isn’t found, the function returns 0.

expr1 is any expression that evaluates to a character string. Identifies the string to search for in the target string.

expr2 is any expression that evaluates to a character string. Identifies the target string to be searched.

POSITION(expr1 IN expr2)

REPEAT

REPEAT('abc', 4)

Repeats a specified expression n times.

expr is any expression that evaluates to a character string

integer is any positive integer that represents the number of times to repeat the character string.

REPEAT(expr, integer)

REPLACE

REPLACE('abcd1234', '123', 'zz')

Replaces one or more characters from a specified character expression with one or more other characters.

expr1 is any expression that evaluates to a character string. This is the string in which characters are to be replaced.

expr2 is any expression that evaluates to a character string. This second string identifies the characters from the first string that are to be replaced.

expr3 is any expression that evaluates to a character string. This third string specifies the characters to substitute into the first string.

REPLACE(expr1, expr2, expr3)

RIGHT

SELECT RIGHT('123456', 3) FROM table

Returns a specified number of characters from the right of a string.

expr is any expression that evaluates to a character string.

integer is any positive integer that represents the number of characters from the right of the string to return.

RIGHT(expr, integer)

SPACE

SPACE(2)

Inserts blank spaces.

integer is any positive integer that indicates the number of spaces to insert.

SPACE(expr)

SUBSTRING

SUBSTRING('abcdef' FROM 2)

Creates a new string starting from a fixed number of characters into the original string.

expr is any expression that evaluates to a character string.

startPos is any positive integer that represents the number of characters from the start of the left side of the string where the result is to begin.

SUBSTRING([SourceString] FROM [StartPostition])

SUBSTRINGN

SUBSTRING('abcdef' FROM 2 FOR 3)

Like SUBSTRING, creates a new string starting from a fixed number of characters into the original string.

SUBSTRINGN includes an integer argument that enables you to specify the length of the new string, in number of characters.

xpr is any expression that evaluates to a character string.

startPos is any positive integer that represents the number of characters from the start of the left side of the string where the result is to begin.

SUBSTRING(expr FROM startPos FOR length)

TrimBoth

Trim(BOTH '_' FROM '_abcdef_')

Strips specified leading and trailing characters from a character string.

char is any single character. If you omit this specification (and the required single quotes), a blank character is used as the default.

expr is any expression that evaluates to a character string.

TRIM(BOTH char FROM expr)

TRIMLEADING

TRIM(LEADING '_' FROM '_abcdef')

Strips specified leading characters from a character string.

char is any single character. If you omit this specification (and the required single quotes), a blank character is used as the default.

expr is any expression that evaluates to a character string.

TRIM(LEADING char FROM expr)

TRIMTRAILING

TRIM(TRAILING '_' FROM 'abcdef_')

Strips specified trailing characters from a character string.

char is any single character. If you omit this specification (and the required single quotes), a blank character is used as the default.

expr is any expression that evaluates to a character string.

TRIM(TRAILING char FROM expr)

UPPER

UPPER(Customer_Name)

Converts a character string to uppercase.

Expr is any expression that evaluates to a character string.

UPPER(expr)

System Functions

The USER system function returns values relating to the session.

It returns the user name you signed in with.

Function Example Description Syntax

DATABASE

 

Returns the name of the Oracle BI subject area to which you're logged on.

DATABASE()

USER

 

Returns the user name for the Oracle BI Repository to which you're logged on.

USER()

Time Series Functions

Time series functions are aggregate functions that operate on time dimensions.

The time dimension members must be at or below the level of the function. Because of this, one or more columns that uniquely identify members at or below the given level must be projected in the query.

Function Example Description Syntax

AGO

SELECT Year_ID, AGO(sales, year, 1)

Calculates the aggregated value of a measure from the current time to a specified time period in the past. For example, AGO can produce sales for every month of the current quarter and the corresponding quarter-ago sales.

AGO(expr, time_level, offset)

PERIODROLLING

SELECT Month_ID, PERIODROLLING (monthly_sales, -1, 1)

Computes the aggregate of a measure over the period starting x units of time and ending y units of time from the current time. For example, PERIODROLLING can compute sales for a period that starts at a quarter before and ends at a quarter after the current quarter.

measure is the name of a measure column.

x is an integer that specifies the offset from the current time.

y specifies the number of time units over which the function will compute.

hierarchy is an optional argument that specifies the name of a hierarchy in a time dimension, such as yr, mon, day, that you want to use to compute the time window.

PERIODROLLING(measure, x [,y])

TODATE

SELECT Year_ID, Month_ID, TODATE (sales, year)

Aggregates a measure from the beginning of a specified time period to the currently displayed time. For example, this function can calculate Year to Date sales.

expr is an expression that references at least one measure column.

time_level is the type of time period, such as quarter, month, or year.

TODATE(expr, time_level)

FORECAST Function

Creates a time-series model of the specified measure over the series using Exponential Smoothing (ETS) or Seasonal ARIMA or ARIMA, and outputs a forecast for a set of periods as specified by numPeriods.

Syntax FORECAST(numeric_expr, ([series]), output_column_name, options,[runtime_binded_options])])

Where:

  • numeric_expr indicates the measure to forecast, for example, revenue data to forecast.

  • series indicates the time grain at which the forecast model is built. This is a list of one or more time dimension columns. If you omit series, then the time grain is determined from the query.

  • output_column_name indicates the output column. The valid values are forecast, low, high, and predictionInterval.

  • options indicates a string list of name/value pairs separated by a semi-colon (;). The value can include %1 ... %N specified in runtime_binded_options.

  • runtime_binded_options indicates a comma separated list of runtime-binded columns and options.

FORECAST Function Options The following table list available options to use with the FORECAST function.

Option Name Values Description
numPeriods Integer The number of periods to forecast
predictionInterval 0 to 100, where higher values specify higher confidence The confidence level for the prediction.
modelType

ETS

SeasonalArima

ARIMA

The model to use for forecasting.
useBoxCox

TRUE

FALSE

If TRUE, then use Box-Cox transformation.
lambdaValue Not applicable

The Box-Cox transformation parameter.

Ignore if NULL or when useBoxCox is FALSE.

Otherwise the data is transformed before the model is estimated.

trendDamp

TRUE

FALSE

This is a parameter for ETS model.

If TRUE, then use damped trend. If FALSE or NULL, then use non-damped trend.

errorType

Not applicable

This is a parameter for ETS model.
trendType

none("N")

additive("A")

multiplicative("M")

automatically selected ("Z")

This is a parameter for ETS model.
seasonType

none("N")

additive("A")

multiplicative("M")

automatically selected("Z")

This is a parameter for ETS model.
modelParamIC

ic_auto

ic_aicc

ic_bic

ic_auto (this is the default)

The information criterion (IC) used in the model selection.

Revenue Forecast by Day Example

This example selects revenue forecast by day.

FORECAST("A - Sample Sales"."Base Facts"."1- Revenue" Target,
("A - Sample Sales"."Time"."T00 Calendar Date"),'forecast', 'numPeriods=30;predictionInterval=70;') ForecastedRevenue

Revenue Forecast by Year and Quarter Example

This example selects revenue forecast by year and quarter.

FORECAST("A - Sample Sales"."Base Facts"."1- Revenue",
("A - Sample Sales"."Time"."T01 Year" timeYear, "A - Sample Sales"."Time"."T02 Quarter" TimeQuarter),'forecast', 'numPeriods=30;predictionInterval=70;') ForecastedRevenue