Oracle8i Time Series User's Guide Release 8.1.5 A67294-01 |
|
The Oracle8i Time Series library consists of:
Calendar functions are mainly used by product developers, such as ISVs, to develop new time series functions and to administer and modify calendars.
Time series and time scaling functions and the administrative tools procedures are used mainly by application developers.
Syntax notes:
select CAST(TimeSeries.ExtractTable(close) AS ORDTNumTab) select cast(TIMESERIES.extracttable(close) as ordtnumtab) select cast(TiMeSeRiEs.eXtRaCtTaBlE(ClosE) As ordtNUMtab)
All time series and time scaling functions accept both references and instances as parameters. (For example, an ORDTNumSeriesIOTRef parameter could also be ORDTNumSeries.) All time series functions return instances. Thus, if you nest functions, such as Cmax(Cmax(...), ...), the innermost nesting accepts a reference and returns an instance, and any other functions in the nesting accept an instance and return an instance.
For an explanation of the reference-based interface, see Section 2.7.2.
ORDSYS.TimeScale.ScaledownInterpolate(
[tsname VARCHAR2,]
inputTS ORDSYS.ORDTNumSeriesIOTRef,
targetCal ORDSYS.ORDTCalendar
[, startDate DATE
, endDate DATE]
) RETURN ORDSYS.ORDTNumSeries;
Given a time series, a calendar to be used for scaling, and optionally starting and ending dates, returns a time series in which data values are interpolated between values in the input time series. For example, in a semi-annual (January and July) to month scaledown, if the data value for a January input timestamp is 100 and the data value for the next (July) input timestamp is 160, the data values for the monthly timestamps for January through June will be 100, 110, 120, 130, 140, and 150.
Name of the returned time series. Specify this parameter if you need to assign a name to the resulting time series, for example, to insert it into an object table.
The input time series.
The calendar to be used for the scaling.
The starting date to be used. If startDate is specified, endDate must also be specified.
The ending date to be used. If endDate is specified, startDate must also be specified.
inputTS cannot be an irregular time series (a time series with no associated calendar).
An exception is returned for any of the following conditions:
For an explanation of concepts related to time scaling, see Section 2.11.
Scale quarterly unemployment rate values down to monthly values, using interpolation:
SELECT to_char(tstamp) tstamp, value FROM myts ts, tsdev.stockdemo_calendars cal, TABLE (CAST(ORDSYS.TimeSeries.ExtractTable( ORDSYS.TimeScale.ScaledownInterpolate(ts.unemployment_rate, VALUE(cal)) ) AS ORDSYS.ORDTNumTab)) t WHERE ts.region='1' AND cal.name ='Monthly';
Assume the following timestamps and values for unemployment_rate:
Timestamp | Value |
---|---|
01-Jan-1998 |
4.0 |
01-Apr-1998 |
3.2 |
01-Jul-1998 |
5.1 |
01-Oct-1998 |
3.9 |
This example might produce the following output:
TSTAMP VALUE --------- ---------- 01-JAN-98 4 01-FEB-98 3.72444444 01-MAR-98 3.47555556 01-APR-98 3.2 01-MAY-98 4.15604396 01-JUN-98 5.14395604 01-JUL-98 6.1 01-AUG-98 5.35869565 01-SEP-98 4.6173913 01-OCT-98 3.9 10 rows selected.
Note that only 10 rows are returned here, as opposed to 12 rows in the ScaledownRepeat example. Interpolation cannot be performed for the months of November and December in this example because the input time series does not contain a timestamp for the following January.
See also the Month function in Chapter 4 for an example of using a calendar-creation function (in this case, Month) to perform scaling, as opposed to specifying a stored calendar that has the desired frequency.
ORDSYS.TimeScale.ScaledownRepeat(
[tsname VARCHAR2,]
inputTS ORDSYS.ORDTNumSeriesIOTRef,
targetCal ORDSYS.ORDTCalendar
[, startDate DATE
, endDate DATE]
) RETURN ORDSYS.ORDTNumSeries;
Given a time series, a calendar to be used for scaling, and optionally starting and ending dates, returns a time series in which data values in the input time series are repeated. For example, in a semi-annual (January and July) to month scaledown, if the data value for a January input timestamp is 100 and the data value for the next (July) input timestamp is 160 (or any other value), the data values for the monthly timestamps for January through June will all be 100.
Name of the returned time series. Specify this parameter if you need to assign a name to the resulting time series, for example, to insert it into an object table.
The input time series.
The calendar to be used for the scaling.
The starting date to be used. If startDate is specified, endDate must also be specified.
The ending date to be used. If endDate is specified, startDate must also be specified.
inputTS cannot be an irregular time series (a time series with no associated calendar).
An exception is returned for any of the following conditions:
For an explanation of concepts related to time scaling, see Section 2.11.
Scale quarterly unemployment rate values down to monthly values, using repetition:
SELECT to_char(tstamp) tstamp, value FROM myts ts, tsdev.stockdemo_calendars cal, TABLE (CAST(ORDSYS.TimeSeries.ExtractTable( ORDSYS.TimeScale.ScaledownRepeat(ts.unemployment_rate, VALUE(cal)) ) AS ORDSYS.ORDTNumTab)) t WHERE ts.region='1' AND cal.name ='Monthly';
Assume the following timestamps and values for unemployment_rate:
Timestamp | Value |
---|---|
01-Jan-1998 |
4.0 |
01-Apr-1998 |
3.2 |
01-Jul-1998 |
5.1 |
01-Oct-1998 |
3.9 |
This example might produce the following output:
TSTAMP VALUE --------- ---------- 01-JAN-98 4 01-FEB-98 4 01-MAR-98 4 01-APR-98 3.2 01-MAY-98 3.2 01-JUN-98 3.2 01-JUL-98 6.1 01-AUG-98 6.1 01-SEP-98 6.1 01-OCT-98 3.9 01-NOV-98 3.9 01-DEC-98 3.9 12 rows selected.
Note that 12 rows are returned here, as opposed to only 10 rows in the ScaledownInterpolate example. Repetition is performed for the months of November and December based on the October value, and is not dependent on the value for the following January.
See also the Month function in Chapter 4 for an example of using a calendar-creation function (in this case, Month) to perform scaling, as opposed to specifying a stored calendar that has the desired frequency.
ORDSYS.TimeScale.ScaledownSplit(
[tsname VARCHAR2,]
inputTS ORDSYS.ORDTNumSeriesIOTRef,
targetCal ORDSYS.ORDTCalendar
[, startDate DATE
, endDate DATE]
) RETURN ORDSYS.ORDTNumSeries;
Given a time series, a calendar to be used for scaling, and optionally starting and ending dates, returns a time series in which data values reflect the division of the data value in the input time series by the number of associated timestamps in the resulting time series. For example, in a semi-annual (January and July) to month scaledown, if the data value for a January input timestamp is 100 and the data value for the next (July) input timestamp is 160 (or any other value), the data values for the monthly timestamps for January through June will all be 16.667 (1/6 of 100).
Name of the returned time series. Specify this parameter if you need to assign a name to the resulting time series, for example, to insert it into an object table.
The input time series.
The calendar to be used for the scaling.
The starting date to be used. If startDate is specified, endDate must also be specified.
The ending date to be used. If endDate is specified, startDate must also be specified.
inputTS cannot be an irregular time series (a time series with no associated calendar).
An exception is returned for any of the following conditions:
For an explanation of concepts related to time scaling, see Section 2.11.
Scale quarterly widget production values down to monthly values, dividing each quarter's value evenly among the three months in that quarter:
SELECT to_char(tstamp) tstamp, value FROM myts ts, tsdev.stockdemo_calendars cal, TABLE (CAST(ORDSYS.TimeSeries.ExtractTable( ORDSYS.TimeScale.ScaledownSplit(ts.widget_production, VALUE(cal)) ) AS ORDSYS.ORDTNumTab)) t WHERE ts.region='1' AND cal.name ='Monthly';
With quarterly widget_production values of 1000, 1500, 900, and 1200, this example might produce the following output:
TSTAMP VALUE --------- ---------- 01-JAN-98 333.333333 01-FEB-98 333.333333 01-MAR-98 333.333333 01-APR-98 500 01-MAY-98 500 01-JUN-98 500 01-JUL-98 300 01-AUG-98 300 01-SEP-98 300 01-OCT-98 400 01-NOV-98 400 01-DEC-98 400 12 rows selected.
For example, one-third (333.33...) of the quarterly value of 1000 for 01-Jan is returned as the monthly value for 01-Jan, 01-Feb, and 01-Mar.
See also the Month function in Chapter 4 for an example of using a calendar-creation function (in this case, Month) to perform scaling, as opposed to specifying a stored calendar that has the desired frequency.
ORDSYS.TimeScale.ScaleupAvg(
[tsname VARCHAR2,]
inputTS ORDSYS.ORDTNumSeriesIOTRef,
targetCal ORDSYS.ORDTCalendar
[, startDate DATE
, endDate DATE]
[,options]
) RETURN ORDSYS.ORDTNumSeries;
Given a time series, a calendar to be used for scaling, and optionally starting and ending dates, returns a time series reflecting the average value of each scaled group of values.
Name of the returned time series. Specify this parameter if you need to assign a name to the resulting time series, for example, to insert it into an object table.
The input time series.
The calendar to be used for the scaling.
The starting date to be used. If startDate is specified, endDate must also be specified.
The ending date to be used. If endDate is specified, startDate must also be specified.
Either or both of the following options:
See Section 2.11.2 for detailed information about these options and examples of their use.
An exception is returned for any of the following conditions:
For an explanation of concepts related to time scaling, see Section 2.11.
Return the average closing prices for stock SAMCO for each month for the entire time series:
SELECT to_char(tstamp) tstamp, value FROM tsdev.stockdemo_ts ts, tsdev.stockdemo_calendars cal, TABLE (CAST(ORDSYS.TimeSeries.ExtractTable( ORDSYS.TimeScale.ScaleupAvg(ts.close, VALUE(cal)) ) AS ORDSYS.ORDTNumTab)) t WHERE ts.ticker='SAMCO' and cal.name='Monthly';
This example might produce the following output:
TSTAMP VALUE --------- ---------- 01-NOV-96 39.83125 01-DEC-96 38.2738095 2 rows selected.
See also the Month function in Chapter 4 for an example of using a calendar-creation function (in this case, Month) to perform scaling, as opposed to specifying a stored calendar that has the desired frequency.
ORDSYS.TimeScale.ScaleupAvgX(
[tsname VARCHAR2,]
ts ORDSYS.ORDTNumSeriesIOTRef,
calendar ORDSYS.ORDTCalendar
[, startDate DATE
, endDate DATE]
[,options]
) RETURN ORDSYS.ORDTNumSeries;
Given a time series, a calendar to be used for scaling, and optionally starting and ending dates, returns a time series reflecting the average value of each scaled group of values plus the immediately preceding source period.
Name of the returned time series. Specify this parameter if you need to assign a name to the resulting time series, for example, to insert it into an object table.
The input time series.
The calendar to be used for the scaling.
The starting date to be used. If startDate is specified, endDate must also be specified.
The ending date to be used. If endDate is specified, startDate must also be specified.
Either or both of the following options:
See Section 2.11.2 for detailed information about these options and examples of their use.
ScaleupAvgX is like ScaleupAvg, except that ScaleupAvgX also considers the last timestamp before the current scaling period. For example:
An exception is returned for any of the following conditions:
For an explanation of concepts related to time scaling, see Section 2.11.
Return the average closing prices for stock SAMCO for each month plus the last trading day of the preceding month for the entire time series:
SELECT to_char(tstamp) tstamp, value FROM tsdev.stockdemo_ts ts, tsdev.stockdemo_calendars cal, TABLE (CAST(ORDSYS.TimeSeries.ExtractTable( ORDSYS.TimeScale.ScaleupAvgX(ts.close, VALUE(cal)) ) AS ORDSYS.ORDTNumTab)) t WHERE ts.ticker='SAMCO' and cal.name='Monthly';
This example might produce the following output:
TSTAMP VALUE --------- ---------- 01-NOV-96 39.83125 01-DEC-96 38.2727273 2 rows selected.
Note that the value for 01-Dec-1996 in this example is different from the value in the ScaleupAvg example, because this ScaleupAvgX value for 01-Dec considers the closing price for the last timestamp in November. (There is no October data in the stockdemo_ts table, and thus the 01-Nov values are the same in the ScaleupAvg and ScaleupAvgX examples.)
See also the Month function in Chapter 4 for an example of using a calendar-creation function (in this case, Month) to perform scaling, as opposed to specifying a stored calendar that has the desired frequency.
ORDSYS.TimeScale.ScaleupCount(
[tsname VARCHAR2,]
ts ORDSYS.ORDTNumSeriesIOTRef,
calendar ORDSYS.ORDTCalendar
[, startDate DATE
, endDate DATE]
[,options]
) RETURN ORDSYS.ORDTNumSeries;
Given a time series, a calendar to be used for scaling, and optionally starting and ending dates, returns a time series reflecting the count of non-null timestamps in each scaled group of values.
Name of the returned time series. Specify this parameter if you need to assign a name to the resulting time series, for example, to insert it into an object table.
The input time series.
The calendar to be used for the scaling.
The starting date to be used. If startDate is specified, endDate must also be specified.
The ending date to be used. If endDate is specified, startDate must also be specified.
Either or both of the following options:
See Section 2.11.2 for detailed information about these options and examples of their use.
An exception is returned for any of the following conditions:
For an explanation of concepts related to time scaling, see Section 2.11.
Return the monthly count of daily closing prices for stock SAMCO for the period 01-Nov-1996 through 31-December 1996:
SELECT to_char(tstamp) tstamp, value FROM tsdev.stockdemo_ts ts, tsdev.stockdemo_calendars cal, TABLE (CAST(ORDSYS.TimeSeries.ExtractTable( ORDSYS.TimeScale.ScaleupCount(ts.close, VALUE(cal), to_date('01-NOV-1996','DD-MON-YYYY'), to_date('31-DEC-1996','DD-MON-YYYY')) ) AS ORDSYS.ORDTNumTab)) t WHERE ts.ticker='SAMCO' and cal.name='Monthly';
This example might produce the following output:
TSTAMP VALUE --------- ---------- 01-NOV-96 20 01-DEC-96 21 2 rows selected.
See also the Month function in Chapter 4 for an example of using a calendar-creation function (in this case, Month) to perform scaling, as opposed to specifying a stored calendar that has the desired frequency.
ORDSYS.TimeScale.ScaleupFirst(
[tsname VARCHAR2,]
ts ORDSYS.ORDTNumSeriesIOTRef,
calendar ORDSYS.ORDTCalendar
[, startDate DATE
, endDate DATE]
[,options]
) RETURN ORDSYS.ORDTNumSeries;
Given a time series, a calendar to be used for scaling, and optionally starting and ending dates, returns a time series reflecting the first non-null value of each scaled group of values.
Name of the returned time series. Specify this parameter if you need to assign a name to the resulting time series, for example, to insert it into an object table.
The input time series.
The calendar to be used for the scaling.
The starting date to be used. If startDate is specified, endDate must also be specified.
The ending date to be used. If endDate is specified, startDate must also be specified.
Either or both of the following options:
If IgnoreNulls (the default) is enabled, the first non-null value of the group is returned (unless all values of the group are null, in which case a null is returned). If IgnoreNullsOFF is enabled, the first value of the group is returned.
See Section 2.11.2 for detailed information about these options and examples of their use.
An exception is returned for any of the following conditions:
For an explanation of concepts related to time scaling, see Section 2.11.
Return the first closing prices for stock SAMCO for the months of November and December of 1996:
SELECT to_char(tstamp) tstamp, value FROM tsdev.stockdemo_ts ts, tsdev.stockdemo_calendars cal, TABLE (CAST(ORDSYS.TimeSeries.ExtractTable( ORDSYS.TimeScale.ScaleupFirst(ts.close, VALUE(cal), to_date('01-NOV-1996','DD-MON-YYYY'), to_date('31-DEC-1996','DD-MON-YYYY')) ) AS ORDSYS.ORDTNumTab)) t WHERE ts.ticker='SAMCO' and cal.name='Monthly';
This example might produce the following output:
TSTAMP VALUE --------- ---------- 01-NOV-96 41.875 01-DEC-96 38.125 2 rows selected.
See also the Month function in Chapter 4 for an example of using a calendar-creation function (in this case, Month) to perform scaling, as opposed to specifying a stored calendar that has the desired frequency.
ORDSYS.TimeScale.ScaleupGMean(
[tsname VARCHAR2,]
ts ORDSYS.ORDTNumSeriesIOTRef,
calendar ORDSYS.ORDTCalendar
[, startDate DATE
, endDate DATE]
[,options]
) RETURN ORDSYS.ORDTNumSeries;
Given a time series, a calendar to be used for scaling, and optionally starting and ending dates, returns a time series reflecting the geometric mean of each scaled group of values.
Name of the returned time series. Specify this parameter if you need to assign a name to the resulting time series, for example, to insert it into an object table.
The input time series.
The calendar to be used for the scaling.
The starting date to be used. If startDate is specified, endDate must also be specified.
The ending date to be used. If endDate is specified, startDate must also be specified.
Either or both of the following options:
See Section 2.11.2 for detailed information about these options and examples of their use.
The geometric mean of each scaled group is computed by taking the sum of the logarithms (base 10) of the values for the corresponding source period, and then raising 10 to the power of the logarithm sum divided by the number of elements in the corresponding source period. That is: POWER(10, log_sum/number_elements).
An exception is returned for any of the following conditions:
For an explanation of concepts related to time scaling, see Section 2.11.
Return the geometric mean of closing prices for stock SAMCO for each month for the entire time series:
SELECT to_char(tstamp) tstamp, value FROM tsdev.stockdemo_ts ts, tsdev.stockdemo_calendars cal, TABLE (CAST(ORDSYS.TimeSeries.ExtractTable( ORDSYS.TimeScale.ScaleupGMean(ts.close, VALUE(cal)) ) AS ORDSYS.ORDTNumTab)) t WHERE ts.ticker='SAMCO' and cal.name='Monthly';
This example might produce the following output:
TSTAMP VALUE --------- ---------- 01-NOV-96 39.7833842 01-DEC-96 38.2719057 2 rows selected.
See also the Month function in Chapter 4 for an example of using a calendar-creation function (in this case, Month) to perform scaling, as opposed to specifying a stored calendar that has the desired frequency.
ORDSYS.TimeScale.ScaleupLast(
[tsname VARCHAR2,]
ts ORDSYS.ORDTNumSeriesIOTRef,
calendar ORDSYS.ORDTCalendar
[, startDate DATE
, endDate DATE]
[,options]
) RETURN ORDSYS.ORDTNumSeries;
Given a time series, a calendar to be used for scaling, and optionally starting and ending dates, returns a time series reflecting the last non-null value of each scaled group of values.
Name of the returned time series. Specify this parameter if you need to assign a name to the resulting time series, for example, to insert it into an object table.
The input time series.
The calendar to be used for the scaling.
The starting date to be used. If startDate is specified, endDate must also be specified.
The ending date to be used. If endDate is specified, startDate must also be specified.
Either or both of the following options:
If IgnoreNulls (the default) is enabled, the last non-null value of the group is returned (unless all values of the group are null, in which case a null is returned). If IgnoreNullsOFF is enabled, the last value of the group is returned.
See Section 2.11.2 for detailed information about these options and examples of their use.
An exception is returned for any of the following conditions:
For an explanation of concepts related to time scaling, see Section 2.11.
Return the last closing prices for stock SAMCO for the months of November and December of 1996:
SELECT to_char(tstamp) tstamp, value FROM tsdev.stockdemo_ts ts, tsdev.stockdemo_calendars cal, TABLE (CAST(ORDSYS.TimeSeries.ExtractTable( ORDSYS.TimeScale.ScaleupLast(ts.close, VALUE(cal), to_date('01-NOV-1996','DD-MON-YYYY'), to_date('31-DEC-1996','DD-MON-YYYY')) ) AS ORDSYS.ORDTNumTab)) t WHERE ts.ticker='SAMCO' and cal.name='Monthly';
This example might produce the following output:
TSTAMP VALUE --------- ---------- 01-NOV-96 38.25 01-DEC-96 39.75 2 rows selected.
Note that each timestamp reflects the first date of the month in the calendar (following the convention illustrated in Table 2-3 in Section 2.2.2), and each value in this case reflects the closing price on the last date for that month in the calendar.
See also the Month function in Chapter 4 for an example of using a calendar-creation function (in this case, Month) to perform scaling, as opposed to specifying a stored calendar that has the desired frequency.
ORDSYS.TimeScale.ScaleupMax(
[tsname VARCHAR2,]
ts ORDSYS.ORDTNumSeriesIOTRef,
calendar ORDSYS.ORDTCalendar
[, startDate DATE
, endDate DATE]
[,options]
) RETURN ORDSYS.ORDTNumSeries;
Given a time series, a calendar to be used for scaling, and optionally starting and ending dates, returns a time series reflecting the maximum value of each scaled group of values.
Name of the returned time series. Specify this parameter if you need to assign a name to the resulting time series, for example, to insert it into an object table.
The input time series.
The calendar to be used for the scaling.
The starting date to be used. If startDate is specified, endDate must also be specified.
The ending date to be used. If endDate is specified, startDate must also be specified.
Either or both of the following options:
See Section 2.11.2 for detailed information about these options and examples of their use.
An exception is returned for any of the following conditions:
For an explanation of concepts related to time scaling, see Section 2.11.
Return the highest (maximum) closing prices for stock SAMCO for each month in the entire time series:
SELECT to_char(tstamp) tstamp, value FROM tsdev.stockdemo_ts ts, tsdev.stockdemo_calendars cal, TABLE (CAST(ORDSYS.TimeSeries.ExtractTable( ORDSYS.TimeScale.ScaleupMax(ts.close, VALUE(cal)) ) AS ORDSYS.ORDTNumTab)) t WHERE ts.ticker='SAMCO' and cal.name='Monthly';
This example might produce the following output:
TSTAMP VALUE --------- ---------- 01-NOV-96 43.75 01-DEC-96 39.75 2 rows selected.
See also the Month function in Chapter 4 for an example of using a calendar-creation function (in this case, Month) to perform scaling, as opposed to specifying a stored calendar that has the desired frequency.
ORDSYS.TimeScale.ScaleupMin(
[tsname VARCHAR2,]
ts ORDSYS.ORDTNumSeriesIOTRef,
calendar ORDSYS.ORDTCalendar
[, startDate DATE
, endDate DATE]
[,options]
) RETURN ORDSYS.ORDTNumSeries;
Given a time series, a calendar to be used for scaling, and optionally starting and ending dates, returns a time series reflecting the minimum value of each scaled group of values.
Name of the returned time series. Specify this parameter if you need to assign a name to the resulting time series, for example, to insert it into an object table.
The input time series.
The calendar to be used for the scaling.
The starting date to be used. If startDate is specified, endDate must also be specified.
The ending date to be used. If endDate is specified, startDate must also be specified.
Either or both of the following options:
See Section 2.11.2 for detailed information about these options and examples of their use.
An exception is returned for any of the following conditions:
For an explanation of concepts related to time scaling, see Section 2.11.
Return the lowest (minimum) closing prices for stock SAMCO for each month in the entire time series:
SELECT to_char(tstamp) tstamp, value FROM tsdev.stockdemo_ts ts, tsdev.stockdemo_calendars cal, TABLE (CAST(ORDSYS.TimeSeries.ExtractTable( ORDSYS.TimeScale.ScaleupMin(ts.close, VALUE(cal)) ) AS ORDSYS.ORDTNumTab)) t WHERE ts.ticker='SAMCO' and cal.name='Monthly';
This example might produce the following output:
TSTAMP VALUE --------- ---------- 01-NOV-96 37.375 01-DEC-96 37.875 2 rows selected.
See also the Month function in Chapter 4 for an example of using a calendar-creation function (in this case, Month) to perform scaling, as opposed to specifying a stored calendar that has the desired frequency.
ORDSYS.TimeScale.ScaleupSum(
[tsname VARCHAR2,]
ts ORDSYS.ORDTNumSeriesIOTRef,
calendar ORDSYS.ORDTCalendar
[, startDate DATE
, endDate DATE]
[,options]
) RETURN ORDSYS.ORDTNumSeries;
Given a time series, a calendar to be used for scaling, and optionally starting and ending dates, returns a time series reflecting the sum of each scaled group of values.
Name of the returned time series. Specify this parameter if you need to assign a name to the resulting time series, for example, to insert it into an object table.
The input time series.
The calendar to be used for the scaling.
The starting date to be used. If startDate is specified, endDate must also be specified.
The ending date to be used. If endDate is specified, startDate must also be specified.
Either or both of the following options:
See Section 2.11.2 for detailed information about these options and examples of their use.
An exception is returned for any of the following conditions:
For an explanation of concepts related to time scaling, see Section 2.11.
Return the sum of the daily trade volume for stock SAMCO for each month in the time series:
SELECT to_char(tstamp) tstamp, value FROM tsdev.stockdemo_ts ts, tsdev.stockdemo_calendars cal, TABLE (CAST(ORDSYS.TimeSeries.ExtractTable( ORDSYS.TimeScale.ScaleupSum(ts.volume, VALUE(cal)) ) AS ORDSYS.ORDTNumTab)) t WHERE ts.ticker='SAMCO' and cal.name='Monthly';
This example might produce the following output:
TSTAMP VALUE --------- ---------- 01-NOV-96 10207000 01-DEC-96 3719450 2 rows selected.
Note that the following example uses the Month function to produce the same output. Using the Month function eliminates the need to have and specify a stored calendar with a month frequency.
SELECT to_char(tstamp) tstamp, value FROM tsdev.stockdemo_ts ts, TABLE (CAST(ORDSYS.TimeSeries.ExtractTable( ORDSYS.TimeScale.ScaleupSum(ts.volume, ORDSYS.Calendar.Month()) ) AS ORDSYS.ORDTNumTab)) t WHERE ts.ticker='SAMCO';
ORDSYS.TimeScale.ScaleupSumAnnual(
[tsname VARCHAR2,]
ts ORDSYS.ORDTNumSeriesIOTRef,
calendar ORDSYS.ORDTCalendar,
annualfactor
[, startDate DATE
, endDate DATE]
[,options]
) RETURN ORDSYS.ORDTNumSeries;
Given a time series, a calendar to be used for scaling, and optionally starting and ending dates, returns a time series reflecting the sum, expressed as an annual rate, of each scaled group of values.
Name of the returned time series. Specify this parameter if you need to assign a name to the resulting time series, for example, to insert it into an object table.
The input time series.
The calendar to be used for the scaling.
The factor by which to multiply the sum of each scaled group in order to obtain the desired annualized value. You must specify a value, either null or not null. If you specify a null value, a default value is used depending on the frequency of calendar, as shown in Table 6-1.
Frequency | annualfactor Default Value |
---|---|
second |
31536000 |
minute |
525600 |
hour |
8760 |
day |
365 |
week |
52 |
month |
12 |
quarter |
4 |
year |
1 |
10-day |
36 |
semi-monthly |
24 |
semi-annual |
2 |
The starting date to be used. If startDate is specified, endDate must also be specified.
The ending date to be used. If endDate is specified, startDate must also be specified.
Either or both of the following options:
See Section 2.11.2 for detailed information about these options and examples of their use.
ScaleupSumAnnual is like ScaleupSum, except that ScaleupSumAnnual converts each scaled group to an annual rate by multiplying the scaled group's value by the annualfactor value.
The pattern and exceptions lists of calendar are not considered.
An exception is returned for any of the following conditions:
For an explanation of concepts related to time scaling, see Section 2.11.
Return the sum of the daily trade volume for stock SAMCO for each month in the entire time series, with each month's value expressed as if it were an annual value. In this case, each monthly value is computed and then multiplied by 12, the default annualfactor for monthly data.
SELECT to_char(tstamp) tstamp, value FROM tsdev.stockdemo_ts ts, tsdev.stockdemo_calendars cal, TABLE (CAST(ORDSYS.TimeSeries.ExtractTable( ORDSYS.TimeScale.ScaleupSumAnnual(ts.volume, VALUE(cal), NULL) ) AS ORDSYS.ORDTNumTab)) t WHERE ts.ticker='SAMCO' and cal.name='Monthly';
This example might produce the following output. (Note that each value is 12 times the corresponding value in the ScaleupAvg example.)
TSTAMP VALUE --------- ---------- 01-NOV-96 122484000 01-DEC-96 44633400 2 rows selected.
See also the ScaleupSum function in this chapter and the Month function in Chapter 4 for examples of using a calendar-creation function (in this case, Month) to perform scaling, as opposed to specifying a stored calendar that has the desired frequency.