Home
Oracle8 Time Series Cartridge User's Guide
Contents
1. DECLARE tstCal ORDSYS ORDTCalendar tstDatel DATE tstDate2 DATE result INTEGER dummyVal INTEGER BEGIN Select a Calendar say GENERIC CAL1 into tstCal from stockdemo calendars SELECT value cal INTO tstCal FROM ORDTDEV stockdemo_calendars cal WHERE cal name GENERIC CAL1 Display the calendar SELECT ORDSYS TimeSeries Display tstCal INTO dummyVal FROM dual DBMS_OUTPUT NEW_LINE Get the number of Valid timestamps between 03 FEB 1996 and 16 MAY 1996 tstDatel TO_DATE 02 03 1996 tstDate2 TO_DATE 05 16 1996 result ORDSYS Calendar NumTimeStampsBetween tstCal tstDatel tstDate2 DBMS_OUTPUT PUT_LINE NumTimeStampsBetween tstDatel tstDate2 Il 7 result END This example might produce the following output In this example there are 74 valid timestamps in the specified date range Calendar Name GENERIC CAL1 Calendar Functions Reference 4 53 NumTimeStampsBetween Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1996 00 00 00 pa pa on of Exceptions tBits 0111110 tAnchor 01 0 01 21 1996 0 04 27 1996 0 07 07 1996 0 fExceptions 01 08 1996 0 04 04 1996 0 07 09 1996 0 7 1996 00 00 00 0 00 00 0 00 00 0 00 00 0 00 00 0 00
2. pattern ORDTPatternBits and ORDTPattern CREATE TYPE ORDSYS ORDTPatternBits AS VARRAY 32500 OF INTEGER CREATE TYPE ORDSYS ORDTPattern AS OBJECT patBits ORDSYS ORDTPatternBits patAnchor DATE exception ORDTExceptions Time Series Concepts 2 7 Calendars CREATE TYPE ORDSYS ORDTExceptions AS VARRAY 32500 OF DATE All Time Series cartridge datatypes are installed under the ORDSYS schema and all users must include the ORDSYS schema name when referring to these datatypes 2 2 3 Overview of Calendar Definition To define a calendar you create a table in which to store calendar definitions and then store a row for each calendar to be defined The following example creates a table named stockdemo_calendars and defines a cal endar named BusinessDays The BusinessDays calendar includes Mondays through Fridays but excludes 28 Nov 1996 and 25 Dec 1996 Explanatory notes follow the example Example 2 1 Overview of Calendar Definition CREATE TABLE stockdemo_calendars of ORDSYS ORDTCalendar name CONSTRAINT calkey PRIMARY KEY INSERT INTO stockdemo_calendars VALUES ORDSYS ORDTCalendar 0 BusinessDays 9 4 Q ORDSYS ORDTPattern ORDSYS ORDTPatternBits 0 1 1 1 1 1 0 TO_DATE 01 JAN 1995 DD MON YYYY O_DATE 01 JAN 1990 DD MON YYYY Q O_DATE 01 JAN 2001 DD MON YYYY ORDSY
3. DECLARE numTS ORDSYS ORDTNumSeries tempVal integer retIsValid integer retValTS integer loDateTab ORDSYS ORDTDateTab NULL hiDateTab ORDSYS ORDTDateTab NULL impDateTab ORDSYS ORDTDateTab NULL dupDateTab ORDSYS ORDTDateTab NULL extraDateTab ORDSYS ORDTDateTab NULL missingDateTab ORDSYS ORDTDateTab NULL outMesg varchar2 2000 BEGIN Set the buffer size DBMS_OUTPUT ENABLE 100000 NOTE Here an instance of the time series is materialized so that it could be modified to generate an invalid time series SELECT ORDSYS TIMESERIES GetSeries ts open INTO numTS FROM ordtdev stockdemo_ts ts WHERE ts ticker ACME lt Example of validating a valid time series SELECT ordsys timeseries display numIS A VALID TIME SERIES INTO tempVal 5 52 Oracle8 Time Series Cartridge User s Guide IsValidTS FROM dual retIsValid ORDSYS TIMESE retValTS ORDSYS TIMESERI RIES IsValidTS numTS ES ValidateTS numTS outMesg loDateTab hiDateTab impDateTab dupDateTab extraDateTab missingDateTab DBMS_OUTPUT PUT_LINE Value returned by IsValid retIsValid DBMS_OUTPUT PUT_LINE Value returned by ValidateTS retValTS ORDSYS TIMESERIES DisplayValTS retValTS outMesg loDateTab hiDa
4. Display the calendar SELECT ORDSYS TimeSeries Display tstCal INTO dummyVal FROM dual DBMS_OUTPUT NEW_LINE Get all the invalid timestamps between 03 MAR 1996 and 03 JUN 1996 tstDatel TO_DATE 03 03 1996 tstDate2 TO_DATE 06 03 1996 resultDTab ORDSYS Calendar InvalidTimeStampsBetween tstCal tstDatel tstDate2 SELECT ORDSYS TimeSeries Display resultDTab InValid timestamps INTO dummyVal FROM dual 4 32 Oracle8 Time Series Cartridge User s Guide InvalidTimeStampsBetween END This example might produce the following output Calendar Name GENERIC CAL1 Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1996 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions 01 21 1996 00 00 00 02 03 1996 00 00 00 03 24 1996 00 00 00 04 27 1996 00 00 00 05 19 1996 00 00 00 06 23 1996 00 00 00 07 07 1996 00 00 00 08 04 1996 00 00 00 09 15 1996 00 00 00 offExceptions 01 08 1996 00 00 00 02 02 1996 00 00 00 03 05 1996 00 00 00 04 04 1996 00 00 00 05 08 1996 00 00 00 06 25 1996 00 00 00 07 09 1996 00 00 00 InValid timestamps 03 03 1996 00 00 00 03 05 1996 00 00 00 03 09 1996 00 00 00 03 10 1996 00 00 00 03 16 1996 00 00 00 03 17 1996 00 00 00 03 23 1996 00 00 00 03 30 1996 00 00 00 03 31 1996 00 00 00 04 04 1996 00 00 00 04 06 1996 00 00 00 04 07 1996 00 00 00 04 13 1996 00 00 00 04 14 1996 00
5. This example might produce the following output TSCOUNT 22 1 row selected 5 100 Oracle8 Time Series Cartridge User s Guide TSDivide TSDivide Format Description Parameters ORDSYS TimeSeries TSDivide ts1 ORDSYS ORDTNumSerieslOTRef ts2 ORDSYS ORDTNumsSerieslOTRef startDate DATE endDate DATE RETURN ORDSYS ORDTNumSeries or ORDSYS TimeSeries TSDivide ts1 ORDSYS ORDTNumSerieslOTRef k NUMBER startDate DATE endDate DATE RETURN ORDSYS ORDTNumSeries Given two input time series or a time series and a constant and optionally starting and ending dates returns a time series that reflects the division of the first parame ter by the second parameter ts1 The time series or first time series whose elements are to be divided by either the corresponding elements in the second time series or a constant ts2 The time series whose elements are to be divided into corresponding elements in the first time series k A constant to be divided into corresponding elements in the first time series Time Series and Time Scaling Functions Reference 5 101 TSDivide startDate Starting date within the time series for which the division is to be performed If startDate is specified endDate must also be specified endDate Ending date within the time series for which the division is to be performed If end Date is specified startDate must also be specified Usage The function perfo
6. This example might produce the following output 104434900 1 row selected 5 128 Oracle8 Time Series Cartridge User s Guide TSVariance TSVariance Format Description Parameters Usage ORDSYS TimeSeries TS Variance ts ORDSYS ORDTNumSeries OT Ref startDate DATE endDate DATE RETURN NUMBER Given an input ORDTNumsSeries and optionally starting and ending dates returns a number corresponding to the variance of all non null time series entries This function is analogous to the SOL group function VAR ts The input time series startDate Starting date within the time series for which the variance is to be calculated If startDate is specified endDate must also be specified endDate Ending date within the time series for which the variance is to be calculated If end Date is specified startDate must also be specified If the date range refers to a time series with fewer than two timestamps a null is returned An exception is returned if any of the following conditions is true a The time series ts is null a The time series ts does not have an associated calendar a endDate is earlier than startDate Time Series and Time Scaling Functions Reference 5 129 TSVariance Example Return the average variance and standard deviation of the closing price of stock ACME Compute various aggregate statistics SELECT ORDSYS TimeSeries TSAvg close ORDSYS TimeSeries TSV
7. For a numeric time series the time series data is contained in the ORDTNumTab structure This structure is a table of a DATE column and a NUMBER column and is also known as a collection Figure 2 4 shows an example of an ORDTNumTab collection type Time Series Concepts 2 13 Interfaces to Time Series and Time Scaling Functions Figure 2 4 Example of ORDTNumTab Collection Type Tstamp Value 01 01 1996 22 00 01 02 1996 23 00 12 31 1996 Functions such as Mavg Moving Average described in Section 2 8 9 use the ORDTNumTab structure as the source data for performing computations and they use the ORDTCalendar type to enable navigation through the time series data The calendar based navigation is especially useful for functions such as Mavg which has as input parameters the starting date startDate and ending date endDate for which to return moving averages and an integer k indicating the look back win dow k denoting the number of timestamps including the current one over which to compute the moving average Calendar based navigation is used to determine the date that is k 1 timestamps previous to startDate Although time series functions operate on time series instances they are invoked from SQL using a REF to a time series For a numeric time series this type is an ORDTNumSeriesIOTRef Section 2 5 2 explains the use of REFs in the reference based interface The REF contains enough information so that time
8. 1 An exception is the Fill function which can be used to add pairs of timestamps and values to make a time series consistent with the calendar 2 18 Oracle8 Time Series Cartridge User s Guide Consistency of Time Series Data The cartridge demo see Section 1 6 includes a security view defined in the file demo usage securevw sql This security view a enables view updates to be propagated to the underlying table a ensures that the underlying table can only be updated using a view mecha nism provided that users are granted update access to the security view and not granted update access to the underlying table a ensures that update delete and insert operations affecting time series data are constrained to conform to the calendar associated with the time series purifies timestamps to match the precision of the calendar 2 6 2 1 Precision Timestamps are purified to match the precision of the calendar For example for a calendar with a day frequency any hour minute and second values in the input timestamp are set to zero Only purified timestamps are inserted into a time series and timestamps are purified if necessary before insert and delete operations 2 6 2 2 INSTEAD OF Triggers INSTEAD OF triggers enforce rules on insert delete and update operations These rules maintain time series data that conforms to the associated calendar For insert operations the following rules apply a For an empty time series
9. MM DD YY Time Series Usage 3 7 Using the Cartridge to date 12 31 96 MM DD YY 10 as ORDSYS ORDTNumt ab FROM stockdemo_ts WHERE ticker ACME 01 NOV 96 04 NOV 96 05 NOV 96 06 NOV 96 07 NOV 96 08 NOV 96 11 NOV 96 12 NOV 96 13 NOV 96 14 NOV 96 63 5 15 NOV 96 64 5 18 NOV 96 65 5 19 NOV 96 66 5 20 NOV 96 67 5 21 NOV 96 68 5 22 NOV 96 69 5 25 NOV 96 70 5 26 NOV 96 71 5 27 NOV 96 72 5 29 NOV 96 73 9 02 DEC 96 74 5 03 DEC 96 75 5 04 DEC 96 76 5 05 DEC 96 pS 06 DEC 96 78 5 09 DEC 96 79 5 10 DEC 96 80 5 11 DEC 96 81 5 12 DEC 96 82 5 13 DEC 96 83 5 16 DEC 96 84 5 17 DEC 96 85 5 18 DEC 96 86 5 19 DEC 96 87 5 20 DEC 96 88 5 23 DEC 96 89 5 24 DEC 96 90 5 3 8 Oracle8 Time Series Cartridge User s Guide Loading Time Series Data 26 DEC 96 91 5 27 DEC 96 92 5 30 DEC 96 93 5 31 DEC 96 94 5 41 rows selected SELECT FROM THE SELECT CAST ORDSYS TimeSeries ExtractTable ORDSYS TimeSeries ScaleupSum volume value cal as ORDSYS ORDTNumt ab FROM stockdemo_ts stockdemo_calendars cal WHERE ticker ACME AND cal name MONTHLY 01 NOV 96 20000 01 DEC 96 21000 2 rows selected 3 2 Loading Time Series Data This section describes how to use the SQL Loader utility to perform bulk loading and incremental loading of time series data To ensure the consistency of time s
10. validFlag integer tstCall ORDSYS ORDTCalendar ORDSYS ORDTCalendar 0 CALENDAR FOO 4 ORDSYS ORDTPattern ORDSYS ORDIPatternBits 1 1 1 1 1 0 0 TO_DATE 01 08 1996 01 01 01 TO_DATE 01 01 1975 06 18 1996 02 02 1996 01 01 03 04 1996 01 01 04 05 1996 02 02 03 29 1996 y TO_DATE 01 01 1999 ORDSYS ORDT O_DATE O_DATE 02 14 1969 O_DATE 02 03 1999 O_DATE 02 17 1999 O_DATE 12 31 1995 O_DATE 01 13 1996 O_DATE 02 24 1996 O_DATE 03 30 1996 O_DATE O_DATE O_DATE O_DATE O_DATE 01 22 1996 O_DATE 02 12 1996 O_DATE 04 30 1996 NULL O_DATE 02 12 1996 NULL O_DATE 04 30 1996 NULL O_DATE 03 25 1996 O_DATE 01 22 1996 O_DATE 01 17 1996 O_DATE 05 28 1996 O_DATE O_DATE 04 23 1996 O_DATE 02 02 1996 O_DATE 03 04 1996 O_DATE 05 06 1997 ORDSYS ORDTExceptions O_DATE 02 08 1969 O_DATE 02 15 1969 O_DATE 02 13 1999 O_DATE 02 20 1999 4 12 Oracle8 Time Series Cartridge User s Guide Exceptions 02 03 1969 Date Date
11. 00 01 01 00 00 00 00 01 01 the messag 03 18 1996 00 05 28 1996 00 02 24 1996 00 05 26 1996 01 04 05 1996 02 refer invalidOffExc refer impreciseOff for details refer invalidOnExc refer impreciseOnExc TS WRN the on exceptions list was trimmed between calendar minDate maxDate TS WRN the off exceptions list was trimmed between calendar minDate amp maxDate 00 00 00 00 00 00 01 01 02 02 IsValidCal MaxDate 01 01 1999 00 00 00 patBits 1111100 patAnchor 01 08 1996 00 00 00 onExcept ions 01 06 1996 00 00 00 01 13 1996 00 00 00 01 14 1996 00 00 00 02 03 1996 00 00 00 02 18 1996 00 00 00 02 24 1996 00 00 00 03 23 1996 00 00 00 05 26 1996 00 00 00 05 04 1997 00 00 0 offExceptions 01 17 1996 00 00 00 01 22 1996 00 00 00 02 02 1996 00 00 00 02 12 1996 00 00 00 03 04 1996 00 00 00 03 25 1996 00 00 00 04 05 1996 00 00 00 04 23 1996 00 00 00 04 30 1996 00 00 00 05 28 1996 00 00 00 06 18 1996 00 00 00 05 06 1997 00 00 00 Calendar Functions Reference 4 39 IsValidDate IsValidDate Format Description Parameters Usage Example ORDSYS Calendar IsValidDate inputCal IN ORDSYS ORDT Calendar checkDate IN DATE RETURN BINARY_INTEGER Checks whether an input date is valid or invalid according to the specified calendar inputCal The calendar to be used to determine whether the input timestamp is valid
12. 1 6 Time Series Cartridge Demos Demonstrations Table 1 1 shows the demos SQL scripts and related files that demonstrate capabili ties included with the Time Series cartridge This table includes a description of each demo and the default directory in which its files are installed The exact loca tion and directory syntax are platform dependent Table 1 1 Time Series Cartridge Demos Description Directory Usage demo for end users and product developers who want to demo usage use existing cartridge feature Advanced developer demo for those who want to extend the car demo extend tridge features OCI demo showing how to call cartridge functions using the Ora demo oci cle Call Interface PRO C C demo showing how to call cartridge functions in demo proc applications created using the Oracle Pro C C Precompiler Developer 2000 demo showing how to call cartridge functions demo dev2k in an Oracle Forms application 1 4 Oracle8 Time Series Cartridge User s Guide Time Series Cartridge Demos Demonstrations Each demo is described in a README file in its directory The usage demo described in this section is a working example of the usage of the cartridge The example models a historical database of stock pricing and provides sample queries over this stock database The usage demo is designed to guide you through the cartridge in a step by step fashion It includes example code for creating and populating
13. a Function calls are not case sensitive except for any quoted literal values For example the following code line excerpts are valid and semantically identical select CAST TimeSeries ExtractTable close AS ORDTNumTab select cast TIMESERIES extracttable close as ordtnumtab Time Series and Time Scaling Functions Reference 5 1 select cast TiMeSeRiEs eXtRaCtTaBlE ClosE As ordtNUMtab a The syntax and examples show the reference based interface types ORDT NumsSerieslIOTRef and ORDTVarchar2SeriesIOTRef Usage note All time series 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 outputs an instance and any other functions in the nesting accept an instance and output an instance For an explanation of the reference based interface see Section 2 5 2 5 2 Oracle8 Time Series Cartridge User s Guide Cavg Cavg Format Description Parameters Usage ORDSYS TimeSeries Cavg ts ORDSYS ORDTNumSeries OT Ref stariDate DATE endDate DATE RETURN ORDSYS ORDTNumSeries Given a time series returns an ORDTNumeSeries with each element containing the cumulative average up to and including the corresponding element in the input ORDTN
14. startDate Starting date within the time series for which the minimum is to be calculated If startDate is specified endDate must also be specified endDate Ending date within the time series for which the minimum is to be calculated If endDate is specified startDate must also be specified An exception is returned if any of the following conditions is true a The time series ts is null a The time series ts does not have an associated calendar a endDate is earlier than startDate Return the lowest closing price for stock AONE for the month of January 1990 SELECT ORDSYS TimeSeries TSMin close Time Series and Time Scaling Functions Reference 5 111 TSMin FROM ORDTD WHERE ticker AON EV Stoc to date 01 01 1990 00 00 00 MM DD YYYY HH24 MI SS to_date 01 31 1990 23 59 59 MM DD YYYY HH24 MI SS TSMin ks_TS Tl Do This example might produce the following output 15 1038 1 row selected 5 112 Oracle8 Time Series Cartridge User s Guide TSMinN TSMinN Format Description Parameters Usage ORDSYS TimeSeries TSMinN ts ORDSYS ORDTNumSerieslOTRef NumValues INTEGER startDate DATE endDate DATE RETURN ORDSYS ORDTNumTab Given an input ORDTNumSeries a number of values to return and optionally starting and ending dates returns an ORDTNumTab with the specified number NumValues of the bottom lowest values ts The input time series
15. BEGIN E E Set tstDate values tS ts S Datel Date2 F HO Erm d FRO TO tmp O_DATE 12 01 1996 00 00 00 MM DD YYYY HH24 MI SS O_DATE 12 31 1996 00 00 00 MM DD YYYY HH24 MI SS ECT ORDSYS TimeSeries Display RDSYS TimeSeries TrimSeries open tstDatel tstDate2 ORDTDEV stocks_ts WHERE ticker AONI END This statement might produce the following output Calendar Calendar Name AON Data Frequency 4 MinDate 01 JAN 80 E lt E MaxDate 01 JAN 01 patBits 0111110 patAnchor 06 APR 97 onExceptions offExceptions 19 FEB 90 13 APR 90 04 JUL 90 03 SEP 90 25 DEC 90 01 JAN 91 29 MAR 91 27 MAY 91 02 SEP 91 28 NOV 91 01 JAN 92 17 FEB 92 25 MAY 92 03 JUL 92 26 NOV 92 25 DEC 92 15 FEB 93 09 APR 93 05 JUL 93 06 SEP 93 28 MAY 90 22 NOV 90 18 F EB 91 04 JUL 91 25D EC 91 17 APR 92 07 SI EP 92 01 JAN 93 31 MAY 93 25 NOV 93 Time Series and Time Scaling Functions Reference 5 91 TrimSeries 24 DEC 93 21 FEB 94 27 APR 94 30 MAY 94 05 SEP 94 24 NOV 94 02 JAN 95 20 FEB 95 29 MAY 95 04 JUL 95 23 NOV 95 25 DEC 95 19 FEB 96 05 APR 96 04 JUL 96 02 SEP 96 28 NOV 96 25 DEC 96 Series Data Date Value 02 DEC 96 59 875 03 DEC 96 60 875 04 DEC 96 60 625 05 DEC 96 SITO 06 DEC 96 56 5 09
16. CombineCals CombineCals Format Description Parameters ORDSYS Calendar CombineCals call ORDSYS ORDTCalendar cal2 ORDSYS ORDTCalendar startDate DATE endDate DATE equalFlag OUT INTEGER RETURN ORDSYS ORDT Calendar Combines two calendars The CombineCals function is provided primarily for use in developing functions that operate on two time series such as the TSAdd func tion cal1 The first calendar to be combined cal2 The second calendar to be combined startDate Starting date for the resulting calendar If startDate is not specified the starting date is the starting date for the calendars or the higher later of the starting dates if they are different endDate Ending date for the resulting calendar If endDate is not specified the ending date is the ending date for the calendars or the lower earlier of the ending dates if they are different 4 2 Oracle8 Time Series Cartridge User s Guide CombineCals Usage Example equalFlag Contains 1 if the input calendars are equal and 0 if the input calendars are not equal If the frequencies of the two calendars are not equal the function returns NULL If the aligned patterns of the two calendars are not equal the function returns NULL If startDate is not specified the starting date of the resulting calendar is the later of the starting dates of the two calendars that is resulting minDate max minDatel minDate2 If e
17. Date laps to 0 in laps to 0 in laps to 0 in laps to 0 in lt minDate lt minDate Date gt maxDate gt maxDate pattern pattern pattern pattern Sunday Saturday Saturday Saturday 01 Imprecise 01 Imprecise 02 Imprecise Valid off exception Valid but out of sequence Null date Duplicate date within OFF s Null date Duplicate off exception Null date Duplicate off exception Duplicate off exception Added to on Added to on Added to on Added to on and off exceptions and off exceptions and off exceptions and off exceptions Date lt minDate Date lt minDate Date gt maxDate Date gt maxDate DisplayValCal Procedure O_DATE 01 03 1996 Maps to 1 in pattern Wednesday O_DATE 02 19 1996 Maps to 1 in pattern Monday O_DATE 03 18 1996 Maps to 1 in pattern Monday O_DATE 05 27 1996 Maps to 1 in pattern Monday O_DATE 03 23 1996 01 01 01 Imprecise O_DATE 02 18 1996 01 01 01 Imprecise O_DATE 05 26 1996 01 01 01 Imprecise O_DATE 01 13 1996 Valid on exception O_DATE 01 14 1996 Valid on exception NULL Null date NULL Null date O_DATE 02 24 1996 Valid on exception O_DATE 03 23 1996 Val
18. MM DD YYYY HH24 MI SS DECLARE 5 94 Oracle8 Time Series Cartridge User s Guide TSAdd tstCal ORDSYS ORDTCalendar startDate date endDate date dummyval INTEGER BEGIN startDate TO_DATE 11 14 1996 endDate TO_DATE 12 14 1996 SELECT ORDSYS TimeSeries Display ORDSYS TimeSeries TSAdd tsl high ts2 low startDate endDate TSAdd Results INTO dummyval FROM ORDTDEV stockdemo_ts tsl ORDIDEV stockdemo_ts ts2 WHERE tsl ticker ACME and ts2 ticker FUNCO END This example might produce the following output TSAdd Results Calendar Data Frequency 4 MinDate 01 01 1990 00 00 00 MaxDate 01 01 2001 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions offExceptions 11 28 1996 00 00 00 12 25 1996 00 00 00 Series Data Date Value 11 14 1996 00 00 00 92 87 11 15 1996 00 00 00 93 84 11 18 1996 00 00 00 94 87 11 19 1996 00 00 00 95 85 11 20 1996 00 00 00 96 82 11 21 1996 00 00 00 97 84 11 22 1996 00 00 00 98 85 11 25 1996 00 00 00 99 81 11 26 1996 00 00 00 100 78 11 27 1996 00 00 00 101 71 Time Series and Time Scaling Functions Reference 5 95 TSAdd 1 29 1996 00 00 00 102 2 02 1996 00 00 00 103 2 03 1996 00 00 00 105 2 04 1996 00 00 00 106 2 05 1996 00 00 00 107 2 06 1996 00 00 00 107 2 09 1996 00 00 00 108
19. ORDSYS Calendar NumTimeStampsBetween ts cal first_tstamp lead_date last_lead_date ORDSYS Calendar OffsetDate ts cal last_tstamp units if last_lead date is null then Raise Application Error ERR_LEAD_TSTAMP_BOUNDS ERR_LEAD_TSTAMP_BOUNDS_MSG end if Instantiate output time series outts ORDSYS ORDTNumSeries Lead Result ts cal ORDSYS ORDTNumTab outts series extend last_index Assign the first timestamp of the output time series to first_lead_date Copy value from input time series to output Time Series Usage 3 17 Using Product Developer Functions time series new_tstamp lead_date outts series 1 ORDSYS ORDTNumCell new_tstamp ts series 1 value Assign subsequent timestamps by calling OffsetDate with the previous date and an offset of 1 for i in 2 outts series last loop new_tstamp ORDSYS Calendar OffsetDate ts cal outts series i 1 tstamp 1 outts series i ORDSYS ORDINumCe11 new_tstamp ts series 1 value end loop return outts end For other examples of using product developer functions see the files for the advanced developer demo described briefly in Table 1 1 in Section 1 6 3 18 Oracle8 Time Series Cartridge User s Guide 4 Calendar Functions Reference The Oracle8 Time Series Cartridge library consists of the following a datatypes described in Section 2
20. onExcept ions 01 21 1 04 27 1 07 07 1 offExceptions 01 08 1 04 04 1 07 09 1 Calendar Name GE 111110 01 0 996 0 996 0 996 0 996 0 996 0 996 0 Frequency 4 MinDate MaxDate patBits 11 patAnchor onExcept ions 07 07 1 10 13 1 01 04 1 04 05 1 offExceptions 07 09 1 10 23 1 01 01 1 04 07 1 111100 01 0 996 996 997 997 CG O O OOO fo 996 996 997 997 e E E e e O OO ERIC CAL1 01 01 1996 00 00 00 12 31 1996 00 00 00 7 1996 00 00 00 0 00 0 00 0 00 0 00 0 00 0 00 00 00 00 00 00 00 NERIC CAL2 02 03 1996 05 19 1996 08 04 1996 02 02 1996 05 08 1996 01 01 1996 00 00 00 12 31 1997 00 00 00 8 1996 00 00 00 result of UnionCals Frequency 4 MinDate 01 01 1996 MaxDate 12 31 1996 patBits 1111100 00 00 00 00 00 00 00 00 00 08 04 1996 00 11 10 1996 00 02 09 1997 00 05 11 1997 00 08 05 1996 00 11 19 1996 00 02 12 1997 00 05 05 1997 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 24 1996 06 23 1996 09 15 1996 03 05 1996 06 25 1996 09 15 1 12 14 1 03 08 1 06 08 1 996 996 997 997 09 10 1 12 12 1 03 04 1 06 09 1 996 996 997 997 00 00 00 00 00 OOOO
21. 00 00 00 00 00 00 02 00 00 00 00 01 00 00 00 00 00 00 00 02 00 01 17 1996 00 00 00 04 23 1996 00 00 00 05 06 1997 00 00 00 02 13 1 02 19 1 03 23 1 01 13 1 01 13 1 03 23 1 06 18 1 02 03 1 02 03 1 01 13 1 02 02 1 03 25 1 04 30 1 05 28 1 02 02 1 999 996 996 996 996 996 996 996 999 996 996 996 996 996 996 O O gt lt A gt A ses UN d OO O Cy a RR E E e 1 e so E e e YE 00 00 00 01 00 00 00 00 GQ O O HO 6 oo 0 Om a Ca E 00 00 OI 00 00 00 00 o DS CO OOO Coe o JUE io A e l ValidateCal DisplayValCal Your Message TS WRN the input calendar has rectifiable errors See the message for details message output by validateCal S WRN S WRN S WRN S WRN S WRN S WRN fixed precision of the pattern anchor date removed superfluous dates in the on exception list refer invalidOnExc fixed imprecise dates in the on exception list refer impreciseOnExc removed null dates in the on exception list sorted the on exceptions list removed duplicate dates in the on exceptions list S WRN S WRN S WRN S WRN S WRN S WRN removed superfluous dates in off exceptions list refer invalidOffExc fixed imprecise dates in the off exception list refer impreciseOf fl removed null dates in the off e
22. 00 00 00 00 00 00 00 00 00 00 00 01 14 1 02 24 1 05 04 1 02 02 1 03 25 1 04 30 1 05 06 1 996 996 997 996 996 996 997 CO AO 00 00 00 00 00 00 00 OOOO a E eo ia o DE e 9 Time Series and Time Scaling Functions Reference The Oracle8 Time Series Cartridge library consists of a datatypes described in Section 2 2 2 a calendar functions described in Chapter 4 a time series and time scaling functions described in this chapter Two separate reference chapters are provided for the functions because the func tions described in each are typically done at different times in the application devel opment cycle and by people performing different job roles a Calendar functions are mainly used by product developers such as ISVs to develop new time series functions and to administer and modify calendars a Time series and time scaling functions are used mainly by application develop ers and some end users after the associated calendar or calendars have been defined Syntax notes a The ORDSYS schema name and the package name must be used with the func tion name although public synonyms can be created to eliminate the need for specifying the schema name see Section 1 4 Each function is included in a PL SQL package such as Calendar or TimeSeries The ORDSYS schema name and the package name are included in the Format and in any examples
23. ORDSYS TIM validFlag outMessage outMessage invOn ESERIES DisplayValCal EXC INTO dummyval invOffExc impOnExc impOffExc Calendar Functions Reference 4 73 ValidateCal invOnExc invof impOnExc impoff tstCall EXC EXC Your Message di END IF END This example might produce the following output tstCall Calendar Name Frequency 4 CALENDAR FOO MinDate 01 01 1975 00 00 00 MaxDate patBits 1111100 patAnchor 01 0 onExcept ions 02 08 1969 2 20 1999 3 18 1996 2 18 1996 1 14 1996 2 24 1996 1 14 1996 1 17 1996 4 23 1996 05 04 1997 E A A SS Sa e offExceptions 02 03 1969 2 17 1999 2 24 1996 3 04 1996 1 22 1996 4 30 1996 1 22 1996 6 18 1996 3 04 1996 es UE ar E do E a DO OO 1 Et CS OS DO PA O O O 0 0 0 0 0 00 00 00 00 0 0 O al 0 00 00 00 00 00 00 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 01 00 00 02 12 1996 00 00 00 00 00 00 00 00 00 00 00 4 74 Oracle8 Time Series Cartridge User s Guide 01 01 1999 00 00 00 8 1996 01 01 01 02 15 1969 01 03 1996 05 27 1996 05 26 1996 03 23 1996 02 24 1996 05 28 1996 01 06 1996 02 14 1969 12 31 1995 03 30 1996 04 05 1996 02 12 1996 03 25 1996 00 00 00 00 00 00 01 00 00 00 00 00 00 00 02 00 00 00 00 01 00
24. ie Oo o o QA O CAS DO O AOS o Fill Backward Calendar Data Calendar Name FOO CALENDAR Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 01 01 1997 00 00 00 patBits 1111111 Time Series and Time Scaling Functions Reference 5 37 Fill patAnchor 01 07 1996 00 00 00 onExcept ions offExceptions Series Data Date Value 2 02 1996 00 00 00 1 2 03 1996 00 00 00 2 2 04 1996 00 00 00 3 2 05 1996 00 00 00 4 2 06 1996 00 00 00 5 2 07 1996 00 00 00 6 2 08 1996 00 00 00 6 2 09 1996 00 00 00 6 2 10 1996 00 00 00 7 2 11 1996 00 00 00 8 2 12 1996 00 00 00 9 2 13 1996 00 00 00 10 Null Fill Calendar Data Calendar Name FOO CALENDAR Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 01 01 1997 00 00 00 patBits 1111111 patAnchor 01 07 1996 00 00 00 onExcept ions offExceptions Series Data Date Value 12 02 1996 00 00 00 1 12 03 1996 00 00 00 2 12 04 1996 00 00 00 3 12 05 1996 00 00 00 4 12 06 1996 00 00 00 5 12 07 1996 00 00 00 12 08 1996 00 00 00 12 09 1996 00 00 00 6 12 10 1996 00 00 00 7 12 11 1996 00 00 00 8 5 38 Oracle8 Time Series Cartridge User s Guide Fill 12 12 1996 00 00 00 9 12 13 1996 00 00 00 10 Time Series and Time Scaling Functions Reference 5 39 First First Format Description Parameters Usage Example ORDSYS TimeSeries First ts ORDSYS ORDTNumsSeri
25. 2 10 1996 00 00 00 109 2 11 1996 00 00 00 110 2 12 1996 00 00 00 LTI 2 13 1996 00 00 00 LLZ 5 96 Oracle8 Time Series Cartridge User s Guide 75 88 03 13 75 77 41 4 TSAvg TSAvg Format Description Parameters Usage Example ORDSYS TimeSeries TSAvg ts ORDSYS ORDTNumSeries OT Ref startDate DATE endDate DATE RETURN NUMBER Given an input ORDTNumSeries and optionally starting and ending dates returns a number corresponding to the average of all non null time series entries ts The input time series startDate Starting date within the time series for which the average is to be calculated If start Date is specified endDate must also be specified endDate Ending date within the time series for which the average is to be calculated If end Date is specified startDate must also be specified An exception is returned if any of the following conditions is true a The time series ts is null a The time series ts does not have an associated calendar a endDate is earlier than startDate Return the average variance and standard deviation of the closing price of stock ACME Time Series and Time Scaling Functions Reference 5 97 TSAvg Compute various aggregate statistics SELECT ORDSYS TimeSeries TSAvg close ORDSYS TimeSeries TSVariance close ORDSYS TimeSeries TSStdDev close FROM ORDTDEV stockdemo_ts WHERE ticker ACME This example mi
26. 2 10 1996 00 00 00 62 2 2 11 1996 00 00 00 63 5 2 12 1996 00 00 00 64 59 2 13 1996 00 00 00 65 6 5 126 Oracle8 Time Series Cartridge User s Guide TSSum TSSum Format Description Parameters Usage Example ORDSYS TimeSeries TSSum ts ORDSYS ORDTNumSeries OT Ref startDate DATE endDate DATE RETURN NUMBER Given an input ORDTNumsSeries and optionally starting and ending dates returns a number corresponding to the sum of all non null time series entries ts The input time series startDate Starting date within the time series for which the sum is to be calculated If start Date is specified endDate must also be specified endDate Ending date within the time series for which the sum is to be calculated If endDate is specified startDate must also be specified An exception is returned if any of the following conditions is true a The time series ts is null a The time series ts does not have an associated calendar a endDate is earlier than startDate Return the sum of the daily trading volumes for stock AONE for the month of Janu ary 1990 that is the total AONE volume for the month Time Series and Time Scaling Functions Reference 5 127 TSSum SELECT ORDSYS TimeSeries TSSum volume to date 01 01 1990 00 00 00 MM DD YYYY HH24 MI SS to_date 01 31 1990 23 59 59 MM DD YYYY HH24 MI SS TSSum FROM ORDTDEV Stocks_TS WHERE ticker AONE
27. 2 32 Oracle8 Time Series Cartridge User s Guide Time Scaling Functions 01 OCT 96 42 375 01 NOV 96 38 25 01 DEC 96 39 75 3 rows selected Note that each timestamp reflects the first date of the month in the calendar follow ing the rules explained in Section 2 2 1 and each value in this case reflects the clos ing price on the last date for that month in the calendar Scaleup functions ignore nulls For example ScaleupAvg returns a time series reflecting the average value of each scaled group of non null values Table 2 14 Scaleup Functions for Collections Function Description ScaleupAvg Returns the average value of each group ScaleupCount Returns the count of timestamps in each group ScaleupSum Returns the sum of each group ScaleupMin Returns the minimum of each group ScaleupMax Returns the maximum of each group ScaleupFirst Returns the first value of each group ScaleupLast Returns the last value of each group 2 9 2 Time Scaling in the GROUP BY Clause Time scaling in the GROUP BY clause supports statements such as the following SELECT sum volume max high min low FROM StockTab CalendarTab cal WHERE ticker XYZ AND cal name Monthly GROUP BY ORDSYS TimeSeries Scaleup tstamp cal This statement scans the daily data stored in StockTab and sums the volume attribute on a monthly basis The calendar to be scaled up to is a parameter of the Scaleup function and is ext
28. If endDate is specified startDate must also be specified An exception is returned if any of the following conditions is true a The time series ts is null a The time series ts does not have an associated calendar a endDate is earlier than startDate Return the highest closing price for stock AONE for the month of January 1990 Time Series and Time Scaling Functions Reference 5 105 TSMax SELECT ORDSYS TimeSeries TSMax close to date 01 01 1990 00 00 00 MM DD YYYY HH24 MI SS to_date 01 31 1990 23 59 59 MM DD YYYY HH24 MI SS TSMax FROM ORDTDEV Stocks_TS WHERE ticker AONE This example might produce the following output 16 3914 1 row selected 5 106 Oracle8 Time Series Cartridge User s Guide TSMaxN TSMaxN Format Description Parameters Usage ORDSYS TimeSeries TSMaxN ts ORDSYS ORDTNumSerieslOTRef NumValues INTEGER startDate DATE endDate DATE RETURN ORDSYS ORDTNumTab Given an input ORDTNumsSeries a number of values to return and optionally starting and ending dates returns an ORDTNumTab with the specified number NumValues of the top highest values ts The input time series NumValues Number of values to return startDate Starting date within the time series for which the top values are to be calculated If startDate is specified endDate must also be specified endDate Ending date within the time series for which the to
29. NumlnvalidTstampsBetween Returns the number of invalid timestamps between two dates NumTstampsBetween Returns the number of valid timestamps between two dates TstampsBetween Returns the valid timestamps between two dates InvalidTstampsBetween Returns the invalid timestamps between two dates SetPrecision Sets the precision of the input timestamp to correspond to the input frequency For an example of using product developer functions see Section 3 4 2 22 Oracle8 Time Series Cartridge User s Guide Time Series Functions 2 8 Time Series Functions Time series functions operate on a time series the input parameter to a time series function A time series type is always used as Reference information for all time series functions is in Chapter 5 2 8 1 Time Series Datatypes Time series functions are defined over datatypes that contain a calendar and a col lection The Time Series cartridge provides the Calendar datatypes are described in Section 2 pol CREA YPI tstamp La E ORDSYS ORI DAT DTNumCell AS OBJECT E Value NUMBER E E CREA YPE ORDSYS ORI ORDSYS ORDT DTNumTab AS TABL NumCell OF a CREA name cal YPE ORDSYS ORDTNumSeries AS OBJI VARCHAR2 256 ORDSYS ORDTCalendar series ORDSYS ORDTNumTab CREATI name cal table_name tstamp_colname value_colname TYPI ry VARCHAR2 256
30. R VARCHAR2 256 VARCHAR2 30 VARCHAR2 30 VARCHAR2 30 VARCHAR2 4000 qualifier_colname qualifier value E CREA YP tstamp E ORDSYS ORI DAT DTVarchar2Cell AS OBJI E value VARCHAR2 4000 E E CREA YPE ORDSYS ORI ORDSYS ORDT DTVarchar2Tab AS TABLI Varchar2Cell CREA YPE ORDSYS ORDTVarchar2Series AS OBJI E ORDSYS ORDTNumSeriesIOTRef AS OBJ following time series datatypes 2 2 l CT EF ORDSYS ORDTCalendar Time Series Concepts 2 23 Time Series Functions name VARCHAR2 256 cal ORDSYS ORDTCalendar series ORDSYS ORDTVarchar2Tab y CREATE TYPE ORDSYS ORDTVarchar2SeriesIOTRef AS OBJECT name VARCHAR2 256 Cal REF ORDSYS ORDTCalendar table _name VARCHAR2 256 tstamp_colname VARCHAR2 30 value_colname VARCHAR2 30 qualifier_colname VARCHAR2 30 qualifier_value VARCHAR2 4000 y CREATE TYPE ORDSYS ORDTDateTab AS TABLE OF DATE The preceding statements show the definition of a numeric time series and a charac ter time series instance based and reference based interfaces each composed of a calendar instance and a collection The collection ORDTxxxTab is defined as a table of ORDTxxxCell except for ORDTDateTab which is a table of DATE Time Series cartridge datatypes such as ORDTNumSeries and ORDTVarchar2Series are input and output parameters of time seri
31. Time Series and Time Scaling Functions Reference 5 53 IsValidTS numTS series numTS series count tstamp TO_DATE 01 04 1997 Example of validating an invalid time series SELECT ordsys timeseries display numTS AN INVALID TIME SERIES INTO tempVal FROM dual retIsValid ORDSYS TIMESERIES IsValidTS numTS retValTS ORDSYS TIMESERIES ValidateTS numTS outMesg loDateTab hiDateTab impDateTab dupDateTab extraDateTab missingDateTab DBMS_OUTPUT PUT_LINE Value returned by IsValid retIsValid DBMS_OUTPUT PUT_LINE Value returned by ValidateTS retValTS ORDSYS TIMESERIES DisplayValTS retValTS outMesg loDateTab hiDateTab impDateTab dupDateTab extraDateTab missingDateTab Testing DisplayValTS END This example might produce the following output A VALID TIME SERIES Name ACME open NumSeries Calendar Data Calendar Name BUSINESS 96 Frequency 4 MinDate 01 01 1990 00 00 00 MaxDate 01 01 2001 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions offExceptions 11 28 1996 00 00 00 12 25 1996 00 00 00 Series Data Date Value 11 01 1996 00 00 00 59 11 04 1996 00 00 00 60 11 05 1996 00 00 00 61 11 06 1996 00 00 00 62 11 07 1996 00 00 00 63 11 08 1996 00 00 00 64 11 11 1996 00 00 00 65 11 12 1996 00 00 00 66 11 13
32. ous specified number of timestamps minus one For example a 30 day moving average of closing prices for a stock on any given date is the average of that day s closing price and the 29 preceding closing prices ts The input time series startDate Starting date within the time series for which to return moving averages If start Date is specified endDate must also be specified endDate Ending date within the time series for which to return moving averages If endDate is specified startDate must also be specified k Positive integer specifying the look back window number of timestamps includ ing the current one over which to compute the moving average Time Series and Time Scaling Functions Reference 5 69 Mavg Usage The returned time series has nulls for any entry where there are not k 1 timestamps preceding it in the calendar For example if a stock trading calendar for 1997 starts on 02 Jan 1997 the series of 5 day moving averages of the closing price for a stock for the year has nulls for the closing price for the first four timestamps 02 Jan 03 Jan 06 Jan and 07 Jan because there are insufficient timestamps for computing the average Any nulls in the entries for the k timestamps are ignored as explained in Section 2 8 2 1 An exception is returned if any of the following conditions is true a The time series ts is null a The time series ts does not have an associated calendar a endDate is earlier th
33. 00 00 00 03 27 1996 00 00 00 03 28 1996 00 00 00 03 29 1996 00 00 00 04 01 1996 00 00 00 04 02 1996 00 00 00 04 03 1996 00 00 00 04 05 1996 00 00 00 04 08 1996 00 00 00 04 09 1996 00 00 00 04 10 1996 00 00 00 04 11 1996 00 00 00 04 12 1996 00 00 00 04 15 1996 00 00 00 04 16 1996 00 00 00 04 17 1996 00 00 00 04 18 1996 00 00 00 04 19 1996 00 00 00 04 22 1996 00 00 00 04 23 1996 00 00 00 04 24 1996 00 00 00 04 25 1996 00 00 00 04 26 1996 00 00 00 04 27 1996 00 00 00 04 29 1996 00 00 00 04 30 1996 00 00 00 05 01 1996 00 00 00 05 02 1996 00 00 00 05 03 1996 00 00 00 05 06 1996 00 00 00 05 07 1996 00 00 00 05 09 1996 00 00 00 05 10 1996 00 00 00 05 13 1996 00 00 00 05 14 1996 00 00 00 05 15 1996 00 00 00 05 16 1996 00 00 00 05 17 1996 00 00 00 05 19 1996 00 00 00 05 20 1996 00 00 00 05 21 1996 00 00 00 05 22 1996 00 00 00 05 23 1996 00 00 00 05 24 1996 00 00 00 05 27 1996 00 00 00 05 28 1996 00 00 00 05 29 1996 00 00 00 05 30 1996 00 00 00 05 31 1996 00 00 00 06 03 1996 00 00 00 Calendar Functions Reference 4 63 TimeStampsBetween Section 3 3 2 contains an example showing the use of TimeStampsBetween to create a time series for use with the DeriveExceptions function 4 64 Oracle8 Time Series Cartridge User s Guide UnionCals UnionCals Format Description Parameters Usage ORDSYS Calendar UnionCals cali ORDSYS ORDTCalendar cal2 ORDSYS ORDTCalendar RETURN ORDSYS ORDTCalendar Returns a
34. 00 00 00 86 12 12 1996 00 00 00 87 5 22 Oracle8 Time Series Cartridge User s Guide DisplayValTS Procedure 12 13 1996 00 00 00 88 2 16 1996 00 00 00 89 2 17 1996 00 00 00 90 2 18 1996 00 00 00 91 2 19 1996 00 00 00 92 2 20 1996 00 00 00 93 2 23 1996 00 00 00 94 2 24 1996 00 00 00 95 2 26 1996 00 00 00 96 2 27 1996 00 00 00 97 2 30 1996 00 00 00 98 2 31 1996 00 00 00 99 Value returned by IsValid 1 Value returned by ValidateTS 1 DisplayValTS Testing DisplayValTS TS SUC the input time series is a valid time series AN INVALID TIME SERIES Name ACME open NumSeries Calendar Data Calendar Name BUSINESS 96 Frequency 4 MinDate 10 28 1996 00 00 00 MaxDate 01 05 1997 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions offExceptions 11 28 1996 00 00 00 12 25 1996 00 00 00 Series Data Date Value 11 01 1996 00 00 00 59 11 04 1996 00 00 00 60 11 05 1996 00 00 00 61 11 06 1996 00 00 00 62 11 07 1996 00 00 00 63 11 08 1996 00 00 00 64 Time Series and Time Scaling Functions Reference 5 23 DisplayValTS Procedure 11 11 1996 00 00 00 65 11 12 1996 00 00 00 66 11 13 1996 00 00 00 67 10 27 1996 00 00 00 68 10 26 1996 00 00 00 69 01 06 1997 00 00 00 70 01 07 1997 00 00 00 71 72 73 11 22 1996 00 00 00 74 11 22 1996 01 00 00 75 11 22 1996 15 00 00 76 11 22 1996 15 00 00 77 11 29 1996 00 00 00 78 11
35. 02 12 1997 00 00 00 03 04 1997 00 00 00 04 07 1997 00 00 00 05 05 1997 00 00 00 06 09 1997 00 00 00 EqualCals GENERIC CAL1 GENERIC CAL2 0 Calendar Functions Reference 4 19 GetOffset GetOffset Format Description Parameters Usage ORDSYS TimeSeries GetOffset inputCal INORDSYS ORDTCalendar origin_date IN DATE reference_date IN DATE RETURN INTEGER Given a calendar one date origin_date and another date reference_date returns the number of timestamps that the second date is offset from the first inputCal The input calendar origin_date Date from which the offset is to be computed reference_date Date whose offset from origin_date is to be returned The function considers the frequency pattern and exceptions of the calendar The returned integer is positive if reference_date is one or more timestamps in the future with respect to origin_date and negative if it is in the past with respect to origin_date For example assume that the calendar includes Mondays through Fri days that 04 Jul 1997 Friday is an off exception and that 03 Jul 1997 Thursday is the origin_date If 10 Jul 1997 Thursday is the reference_date the returned offset is 4 if the reference_date is 01 Jul 1997 Monday the returned offset is 2 If origin_date and reference_date are the same the function returns 0 zero An exception is returned if the calendar has an empt
36. 03 24 1996 00 00 00 04 27 1996 00 00 00 05 19 1996 00 00 00 06 23 1996 00 00 00 07 07 1996 00 00 00 08 04 1996 00 00 00 09 15 1996 00 00 00 offExceptions 01 08 1996 00 00 00 02 02 1996 00 00 00 03 05 1996 00 00 00 04 04 1996 00 00 00 05 08 1996 00 00 00 06 25 1996 00 00 00 07 09 1996 00 00 00 Calendar Name GENERIC CAL2 Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1997 00 00 00 patBits 1111100 patAnchor 01 08 1996 00 00 00 Calendar Functions Reference 4 29 IntersectCals onExceptions 07 07 1996 00 00 00 08 04 1996 10 13 1996 00 00 00 11 10 1996 01 04 1997 00 00 00 02 09 1997 04 05 1997 00 00 00 05 11 1997 offExceptions 07 09 1996 00 00 00 08 05 1996 10 23 1996 00 00 00 11 19 1996 01 01 1997 00 00 00 02 12 1997 04 07 1997 00 00 00 05 05 1997 result of CombineCals Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1996 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions 07 07 1996 00 00 00 08 04 1996 offExceptions 01 08 1996 00 00 00 02 02 1996 04 04 1996 00 00 00 05 08 1996 07 09 1996 00 00 00 08 05 1996 10 23 1996 00 00 00 11 19 1996 equalFlag 0 result of IntersectCals Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1996 00 00 00 patBits 1111100 patAnchor 01 08 1996 00 00 00 onExcept ions 07 07 1996 00 00 00 08 04 1996 offExceptions 01 08 1996 00 00 00 02 02 1996 04 04 1996 00
37. 15 00 00 list of duplicate dates duplicateDateTab 11 22 1996 15 00 00 11 29 1996 00 00 00 ExtraDateTab 12 28 1996 00 00 00 12 29 1996 00 00 00 01 04 1997 00 00 00 MissingDateTab 10 28 1996 00 00 00 10 29 1996 00 00 00 10 30 1996 00 00 00 10 31 1996 00 00 00 11 14 1996 00 00 00 11 15 1996 00 00 00 11 18 1996 00 00 00 11 19 1996 00 00 00 11 20 1996 00 00 00 11 21 1996 00 00 00 11 25 1996 00 00 00 11 26 1996 00 00 00 11 27 1996 00 00 00 12 02 1996 00 00 00 12 23 1996 00 00 00 12 24 1996 00 00 00 12 31 1996 00 00 00 01 01 1997 00 00 00 01 02 1997 00 00 00 01 03 1997 00 00 00 Time Series and Time Scaling Functions Reference 5 139 ValidateTS 5 140 Oracle8 Time Series Cartridge User s Guide A Error Messages This appendix lists the Time Series cartridge error messages including the cause and recommended user action for each TS 00500 internal error Cause This is the generic internal error number for Time Series exceptions This indicates that a process has encountered an exceptional condition Action Report as a bug TS 00501 the input patterns are not of the same length Cause The input calendars have patterns of different lengths For example 0 1 1 1 1 1 0 and 0 1 1 1 1 0 were specified Action Use calendars with patterns of the same length TS 00503 patanchor can be null only if patbits count 1 or all patbits are the same Cause Pattern anchor was null and pattern was not
38. 32 Prada 5 34 PIES E REEE arabic peace b ens Leda dina da cobeg sbiedhess shoss A dai dbz 5 40 Att NR NON 5 42 GetDatedElemen i AS e ahi bia ea iid ciel cade 5 44 GetNthElement cia iii 5 46 GOA A A AA 5 48 IV ad TS o da 5 51 VA A A A E AA A A 5 59 A NR O 5 62 PasiNeatit tae leia esla desd elias 5 64 Di A AA 5 66 Ma 8 iii E E I E E EEA AE E E AAA dents 5 69 EAE i na A EE EE EE E E E T ved icy 5 72 CALCU iss merest O ae aR e E E E A 5 74 SCALSUP AY Gi aee ea droit pia de a T AA Eea AA AE a aN E NAAT AEE ea a 5 76 ScaleupC ounte e decian 5 78 ScaleUp Firsts nisale A n aaa van acl a A R A A ites 5 80 Scaleupl ast nT Aae A daria 5 82 ScaleupM aX nais iei ids Hines aus See leds eatin iia 5 84 SCALE AA E EER 5 86 AA ara ia i i e R A N a a 5 88 EN a eE 5 90 TA E AU eee E E E E 5 93 TSANG stay athe Shen ath ae Nani di ica ho iat nish AO its 5 97 TOO A A A AA ieena iora Re 5 99 TOD iii A A a A IA 5 101 SM E A A A AA AS 5 105 FSMaXIN bes A A AE tas 5 107 TM TA te ta aa aaa e ie A dectedtetes 5 109 MA de la e de 5 111 SMN A A A AS 5 113 TSIM I PY 0 A A A AAA E E ad 5 115 ESPOSA AS 5 119 TOM AD Mii A AAA 5 121 TSS btract iee nedora a i alec sola a ai a ia 5 123 MO de de a eo eaa 5 127 TOMAN C SAE A ERA ES is 5 129 Vat a 5 131 A Error Messages vii Examples 2 1 Overview of Calendar Definition c cccccccccessccsseessscssscessecessecsseeesscsseeecaeceseecssseessecnseeens 2 8 3 1 Create a Stock Data Table cuina dietista
39. 86 Oracle8 Time Series Cartridge User s Guide ScaleupMin Example The frequency of the calendar on which the time series is based is greater than the frequency of the specified calendar for example the time series calendar s frequency is month and the specified calendar s frequency is day For an explanation of concepts related to time scaling see Section 2 9 Return the lowest minimum closing prices for stock SAMCO for each month in the entire time series SELECT FROM THE SELECT CAST ORDSYS TimeSeries Extract Table ORDSYS TimeSeries ScaleupMin ts close sc calendar AS ORDSYS ORDTNumTab FROM ORDTDEV stocks_ts ts ordtdev scale sc WHERE ts ticker SAMCO and sc name MONTHLY This example might produce the following output 01 JAN 90 27 6875 01 FEB 90 28 2813 01 MAR 90 30 0938 01 APR 90 30 1875 01 MAY 90 30 7813 01 JUN 90 32 0938 01 JUL 90 32 2813 01 AUG 90 28 5938 01 OCT 96 42 01 NOV 96 37 315 01 DEC 96 37 875 84 rows selected Time Series and Time Scaling Functions Reference 5 87 ScaleupSum ScaleupSum Format Description Parameters Usage ORDSYS TimeSeries ScaleupSum ts ORDSYS ORDTNumSerieslOTRef calendar ORDSYS ORDTCalendar stariDate 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 ser
40. 90 1395875 01 JUL 90 1088125 01 AUG 90 1503000 01 OCT 96 1615350 01 NOV 96 10207000 01 DEC 96 3719450 84 rows selected Time Series and Time Scaling Functions Reference 5 89 TrimSeries TrimSeries Format Description Parameters Usage ORDSYS TimeSeries TrimSeries ts ORDSYS ORDTNumsSerieslOTRef startDate DATE endDate DATE RETURN ORDSYS ORDTNumSeries or ORDSYS TimeSeries TrimSeries ts ORDSYS ORDTVarchar2SerieslOTRef startDate DATE endDate DATE RETURN ORDSYS ORDTVarchar2Series Given an input ORDT series returns an ORDT series of the same type with all data outside of the given date range removed The calendar of the returned series will be the same as that of the original series ts The input time series startDate Starting date within the time series If startDate is specified endDate must also be specified endDate Ending date within the time series If endDate is specified startDate must also be specified An exception is returned if any of the following conditions is true a The time series ts is null a The time series ts does not have an associated calendar 5 90 Oracle8 Time Series Cartridge User s Guide TrimSeries Example a endDate is earlier than startDate Return the opening prices for stock AONE for dates in the calendar from 01 Dec 1996 through 31 Dec 1996 SET SERVE ROUTPUT ON DECLARE tmp INTEGER tstDatel DATE tstDate2 DATE
41. Display the calendar SELECT ORDSYS TimeSeries Display tstCal into tstCal INTO dummyVal FROM dual DBMS_OUTPUT NEW_LINE Get the number of invalid timestamps between 03 FEB 1996 and 16 MAY 1996 tstDatel TO_DATE 02 03 1996 tstDate2 TO_DATE 05 16 1996 result ORDSYS Calendar NumInvalidTimeSt ampsBetween tstCal tstDatel tstDate2 DBMS_OUTPUT PUT_LINE NumInvalidTimeStampsBetween tstDatel tstDate2 result END This example might produce the following output In this example there are 30 invalid timestamps in the specified date range 4 44 Oracle8 Time Series Cartridge User s Guide NuminvalidTimeStampsBetween Calendar Name GENERIC CAL1 Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1996 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions 01 21 1996 00 00 00 02 03 1996 00 00 00 03 24 1996 00 00 00 04 27 1996 00 00 00 05 19 1996 00 00 00 06 23 1996 00 00 00 07 07 1996 00 00 00 08 04 1996 00 00 00 09 15 1996 00 00 00 offExceptions 01 08 1996 00 00 00 02 02 1996 00 00 00 03 05 1996 00 00 00 04 04 1996 00 00 00 05 08 1996 00 00 00 06 25 1996 00 00 00 07 09 1996 00 00 00 NumInvalidTimeStampsBetween 02 03 1996 00 00 00 05 16 1996 00 00 00 30 Calendar Functions Reference 4 45 NumOffExceptions NumOffExceptions Format ORD
42. END This example might produce the following output In this example the hour minute and second components of the timestamp are set to zeroes because the cal endar frequency is 4 day Calendar Name GENERIC CAL1 Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1996 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions 01 21 1996 00 00 00 02 03 1996 04 27 1996 00 00 00 05 19 1996 07 07 1996 00 00 00 08 04 1996 offExceptions 01 08 1996 00 00 00 02 02 1996 04 04 1996 00 00 00 05 08 1996 07 09 1996 00 00 00 SetPrecision 03 03 1996 01 01 01 4 4 60 Oracle8 Time Series Cartridge User s Guide 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 24 1996 00 00 00 06 23 1996 00 00 00 09 15 1996 00 00 00 03 05 1996 00 00 00 06 25 1996 00 00 00 03 03 1996 00 00 00 TimeStampsBetween TimeStampsBetween Format ORDSYS Calendar TimeStampsBetween inputCal INORDSYS ORDTCalendar startDate IN DATE endDate IN DATE RETURN ORDSYS ORDTDateTab Description Given starting and ending input timestamps returns a table ORDTDateTab con taining the valid timestamps within that range according to the specified calendar Parameters inputCal The calendar to be used to determine whether a timestamp is valid or invalid startDate Starting date in the range to be checked for valid timestamps endDate Ending date in the range to be checked for valid t
43. HiDateTab TS ERR the tim ries has imprecise timestamps refer impreciseDateTab TS ERR the tim ries has duplicate timestamps refer DuplicateDateTab An AN HN list of dates lt calendar minDate lowDateTab 10 26 1996 00 00 00 10 27 1996 00 00 00 list of dates gt calendar maxDate hiDateTab 1 06 1997 00 00 00 01 07 1997 00 00 00 o list of imprecise dates impreciseDateTab m 1 22 1996 01 00 00 11 22 1996 15 00 00 list of duplicate dates duplicateDateTab bh 1 22 1996 15 00 00 11 29 1996 00 00 00 ExtraDateTab Time Series and Time Scaling Functions Reference 5 57 IsValidTS 12 28 1 MissingDateT 10 28 1 10 31 1 11 18 1 11 21 1 11 27 1 12 24 1 01 02 1 5 58 Oracle8 Time Series Cartridge User s Guide 996 ab s 996 996 996 996 996 996 997 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 12 29 1996 10 29 1996 11 14 1996 11 19 1996 11 25 1996 12 02 1996 12 31 1996 00 00 00 00 00 00 00 01 03 1997 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 04 1997 10 30 1996 11 15 1996 11 20 1996 11 26 1996 12 23 1996 01 01 1997 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Lag Lag Format ORDSYS TimeSeries Lag ts ORDSYS ORDTNumS
44. Insert some exceptions in tstCal 4 24 Oracle8 Time Series Cartridge User s Guide InsertExceptions resultCal ORDSYS Calendar InsertExceptions tstCal tstDTab SELECT ORDSYS TimeSeries Display resultCal INTO dummyVal FROM dual END This example might produce the following output The second display of informa tion about GENERIC CAL1 includes the added on exceptions and off exceptions Calendar Name GENERIC CAL1 Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1996 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExceptions 01 21 1996 00 00 00 02 03 1996 00 00 00 03 24 1996 00 00 00 04 27 1996 00 00 00 05 19 1996 00 00 00 06 23 1996 00 00 00 07 07 1996 00 00 00 08 04 1996 00 00 00 09 15 1996 00 00 00 offExceptions 01 08 1996 00 00 00 02 02 1996 00 00 00 03 05 1996 00 00 00 04 04 1996 00 00 00 05 08 1996 00 00 00 06 25 1996 00 00 00 07 09 1996 00 00 00 Input DateTab 02 10 1996 00 00 00 07 09 1996 00 00 00 03 17 1996 00 00 00 04 08 1996 00 00 00 Calendar Name GENERIC CAL1 Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1996 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions 01 21 1996 00 00 00 02 03 1996 00 00 00 02 10 1996 00 00 00 03 17 1996 00 00 00 03 24 1996 00 00 00 04 27 1996 00 00 00 05 19 1996 00 00 00 06 23 1996 00 00 00 07 07 1996 00 00 00 08 04 1996 00 00 00 09 15 1996 00 00 00 of
45. Loader see the Oracle8 Server Utilities manual The SQL Loader script contains the following o sqlldr userid ordtdev ordtdev control stockdat ct1l log stockdat log bad stockdat bad errors 1000 The stockdat dat sample data file includes the following ACME 01 NOV 96 59 00 60 00 58 00 59 00 1000 ACME 04 NOV 96 60 00 61 00 59 00 60 00 1000 ACME 05 NOV 96 61 00 62 00 60 00 61 00 1000 The stockdat ctl file contains the following options direct true unrecoverable load data infile stockdat dat replace into table stockdemo sorted indexes StockTabx fields terminated by whitespace ticker tstamp DATE 13 DD MON YY open high low close volume SQL Loader can handle many file formats and delimiters as documented in the Oracle8 Utilities manual After the load has completed you may want to choose one of the following approaches for ensuring calendar consistency a Adjust calendars to conform to time series data see Section 3 2 1 1 a Validate that the time series conforms to the calendar see Section 3 2 1 2 In either case you may need to update the exception lists of your calendars 3 10 Oracle8 Time Series Cartridge User s Guide Loading Time Series Data 3 2 1 1 Adjusting Calendars to Conform to Time Series Data Often you will want to create calendars that conform to the time series data that you are receiving In this case you usually know the frequency an
46. NumValues Number of values to return startDate Starting date within the time series for which the bottom values are to be calcu lated If startDate is specified endDate must also be specified endDate Ending date within the time series for which the bottom values are to be calculated If endDate is specified startDate must also be specified An exception is returned if any of the following conditions is true a The time series ts is null a The time series ts does not have an associated calendar Time Series and Time Scaling Functions Reference 5 113 TSMinN a endDate is earlier than startDate NumValues is zero 0 or negative Example Return the 10 lowest closing prices for stock AONE for the month of January 1996 SELECT FROM THE SELECT CAST ORDSYS TimeSeries TSMinN close 10 to date 01011996 MMDDYYYY to date 01311996 MMDDYYYY as ORDSYS ORDTNumTab FROM ORDTDEV stocks_ts WHERE ticker AONE This example might produce the following output STAMP VALUE 15 JAN 96 37 8 09 JAN 96 37 9675 04 JAN 96 38 3025 10 JAN 96 38 47 03 JAN 96 38 6375 16 JAN 96 38 9725 11 JAN 96 39 0563 08 JAN 96 39 3075 12 JAN 96 39 5588 17 JAN 96 39 6425 10 rows selected 5 114 Oracle8 Time Series Cartridge User s Guide TSMultiply TSMultiply Format Description Parameters ORDSYS TimeSeries TSM
47. ORDSYS ORDTCalendar resultCal ORDSYS ORDTCalendar equalFlag INTEGER dummyVal INTEGER BEGIN Select the calendars GENERIC CAL1 into tstCall and GENERIC CAL2 into tstCal2 from stockdemo_calendars SELECT value cal INTO tstCall FROM ORDTDEV stockdemo_calendars cal WHERE cal name GENERIC CAL1 SELECT value cal INTO tstCal2 FROM ORDTIDEV stockdemo_calendars cal WHERE cal name GENERIC CAL2 Display the calendars tstCall and tstCal2 SELECT ORDSYS TimeSeries Display tstCall INTO dummyVal FROM dual SELECT ORDSYS TimeSeries Display tstCal2 INTO dummyVal FROM dual Combine tstCall and tstCal2 resultCal ORDSYS Calendar CombineCals tstCall tstCal2 equalFlag SELECT ORDSYS TimeSeries Display resultCal result of CombineCals INTO dummyVal FROM dual DBMS_OUTPUT PUT_LINE equalFlag equalFlag Intersect tstCall and tstCal2 resultCal ORDSYS Calendar IntersectCals tstCall tstCal2 SELECT ORDSYS TimeSeries Display resultCal result of IntersectCals INTO dummyVal FROM dual END This example might produce the following output Calendar Name GENERIC CAL1 Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1996 00 00 00 patBits 4 4 Oracle8 Time Series Cartridge User s Guide CombineCals 0111110 patAnchor 01 07
48. Oracle8 Time Series Cartridge User s Guide TSStdDev TSStdDev Format Description Parameters Usage ORDSYS TimeSeries TSStdDev ts ORDSYS ORDTNumSeries OT Ref startDate DATE endDate DATE RETURN NUMBER Given an input ORDTNumsSeries and optionally starting and ending dates returns a number corresponding to the standard deviation of all non null time series entries This function returns a value that is the square root of the value returned by the TSVar function ts The input time series startDate Starting date within the time series for which the standard deviation is to be calcu lated If startDate is specified endDate must also be specified endDate Ending date within the time series for which the standard deviation is to be calcu lated If endDate is specified startDate must also be specified If the date range refers to a time series with fewer than two timestamps a null is returned An exception is returned if any of the following conditions is true a The time series ts is null a The time series ts does not have an associated calendar a endDate is earlier than startDate Time Series and Time Scaling Functions Reference 5 121 TSStdDev Example Return the average variance and standard deviation of the closing price of stock ACME Compute various aggregate statistics SELECT ORDSYS TimeSeries TSAvg close ORDSYS TimeSeries TSVariance close ORDSYS TimeSeries T
49. Time Series and Time Scaling Functions Reference 5 83 ScaleupMax ScaleupMax Format Description Parameters Usage ORDSYS TimeSeries ScaleupMax ts ORDSYS ORDTNumSerieslOTRef calendar ORDSYS ORDTCalendar stariDate 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 reflecting the maximum value of each scaled group of values ts The input time series calendar The calendar to be used for the scaling startDate The starting date to be used If startDate is specified endDate must also be specified endDate The ending date to be used If endDate is specified startDate must also be specified An exception is returned for any of the following conditions a The input time series the calendar on which the input time series in based or the specified calendar is null 5 84 Oracle8 Time Series Cartridge User s Guide ScaleupMax Example The frequency of the calendar on which the time series is based is greater than the frequency of the specified calendar for example the time series calendar s frequency is month and the specified calendar s frequency is day For an explanation of concepts related to time scaling see Section 2 9 Return the highest maximum closing prices for stock SAMCO for each month in the entire time series SELECT FROM THE SELECT CAST ORDSYS
50. TimeSeries Extract Table ORDSYS TimeSeries ScaleupMax ts close sc calendar AS ORDSYS ORDTNumTab FROM ORDTDEV stocks_ts ts ordtdev scale sc WHERE ts ticker SAMCO and sc name MONTHLY This example might produce the following output 01 JAN 90 31 2813 01 FEB 90 29 7813 01 MAR 90 31 1875 01 APR 90 31 5938 01 MAY 90 32 875 01 JUN 90 33 7813 01 JUL 90 34 6875 01 AUG 90 31 875 01 OCT 96 43 375 01 NOV 96 43 75 01 DEC 96 39 75 84 rows selected Time Series and Time Scaling Functions Reference 5 85 ScaleupMin ScaleupMin Format Description Parameters Usage ORDSYS TimeSeries ScaleupMin ts ORDSYS ORDTNumSerieslOTRef calendar ORDSYS ORDTCalendar stariDate 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 reflecting the minimum value of each scaled group of values ts The input time series calendar The calendar to be used for the scaling startDate The starting date to be used If startDate is specified endDate must also be specified endDate The ending date to be used If endDate is specified startDate must also be specified An exception is returned for any of the following conditions a The input time series the calendar on which the input time series in based or the specified calendar is null 5
51. Value 11 01 1996 00 00 00 59 11 04 1996 00 00 00 60 11 05 1996 00 00 00 61 11 06 1996 00 00 00 62 11 07 1996 00 00 00 63 11 08 1996 00 00 00 64 11 11 1996 00 00 00 65 11 12 1996 00 00 00 66 11 13 1996 00 00 00 67 10 27 1996 00 00 00 68 10 26 1996 00 00 00 69 01 06 1997 00 00 00 70 01 07 1997 00 00 00 71 72 73 11 22 1996 00 00 00 74 11 22 1996 01 00 00 75 11 22 1996 15 00 00 76 11 22 1996 15 00 00 TT 11 29 1996 00 00 00 78 11 29 1996 00 00 00 79 12 03 1996 00 00 00 80 12 04 1996 00 00 00 81 12 05 1996 00 00 00 82 12 06 1996 00 00 00 83 12 09 1996 00 00 00 84 12 10 1996 00 00 00 85 12 11 1996 00 00 00 86 12 12 1996 00 00 00 87 12 13 1996 00 00 00 88 12 16 1996 00 00 00 89 5 56 Oracle8 Time Series Cartridge User s Guide IsValidTS 12 17 1996 00 00 00 90 12 18 1996 00 00 00 91 12 19 1996 00 00 00 92 12 20 1996 00 00 00 93 12 29 1996 00 00 00 94 12 28 1996 00 00 00 95 12 26 1996 00 00 00 96 12 27 1996 00 00 00 97 12 30 1996 00 00 00 98 01 04 1997 00 00 00 99 Value returned by IsValid 0 Value returned by ValidateTS 0 DisplayValTS Testing DisplayValTS TS WRN the input time series has errors See the message for details message output by validateTS TS ERR the input time series is unsorted TS ERR the tim ries has null timestamps TS ERR the tim ries has timestamps lt calendar minDate refer LoDateTab TS ERR the tim ries has timestamps gt calendar maxDate refer
52. a time series to be consistent the following must be true a All timestamps are sorted in ascending sequence a There are no duplicate timestamps a All timestamps match the precision of the calendar a No timestamps are beyond the bounds of the calendar minDate and maxDate a All timestamps conform to the pattern specification except those listed in the off exceptions list or the on exceptions list a The time series data is contiguous That is between the smallest earliest and largest latest timestamps in the time series the time series data contains timestamps for all valid calendar timestamps If some mechanism is not used to enforce these consistency rules accidental or malicious actions could destroy the integrity of the time series data For example a user might delete rows from the middle of the time series rather than being restricted to deleting rows at the beginning and the end of the date range for the time series 2 6 2 Enforcing Time Series Consistency with Security Views Enforcing time series consistency can be accomplished with a security view A secu rity view is a relational view of time series data that uses INSTEAD OF triggers to maintain time series consistency For an explanation of INSTEAD OF triggers see the Oracle8 Server Concepts manual The security view is intended to be used for limited or moderate insert update and delete operations it is not intended for bulk changes to time series data
53. are not needed in this case The PATTERN ONLY calendar should have no exceptions If this calendar has any exceptions the resulting time series will have non null exception lists which will cause the DeriveExceptions function to report an error After you create the reference time series call the DeriveExceptions function with the reference time series as the first parameter series1 DeriveExceptions compares the dates in series1 with the dates in series2 and it returns the calendar of series1 with the exceptions created as follows a All timestamps that are in series1 but not in series2 become off exceptions For example if series2 contains dates on which stock XYZ traded and 04 Jul 1997 Friday is not in that time series then 04 Jul 1997 is added to the calendar as an off exception a All timestamps that are in series2 but not in series1 become on exceptions Time Series Usage 3 15 Using Product Developer Functions The following example uses the reference time series created in the preceding state ment to update the exception lists of every other calendar in the stockdemo_calendars table with the exceptions for each calendar derived from the timestamps in the associated time series This example assumes that each calendar maps to a time series with the same name UPDATE stockdemo_calendars cal SET cal SELECT ORDSYS TimeSeries DeriveExceptions tsl open ts2 open FROM stocks_ts tsl stocks_ts ts2 WHERE tsl tic
54. are thr cases of deletion to consider Case 1 The table does not have any existing time series entries for the given ticker In this case the E trigger raises an exception Case 2 The tstamp is equal to the current startdate This routine verifies this and then deletes H the row Case 3 The tstamp is equal to the current enddat This routine verifies this and then deletes the row Tf the time series is not empty and if the row being deleted is not the startdate or enddate an exception is raised IF startdate IS null THEN raise_application_error 20000 Timeseries is empty ELSE Time Series Usage 3 5 Using the Cartridge IF NOT purifieddate startdate or purifieddate raise_application_error 20000 Timestamp date not s enddate END IF END IF Delete the row in the time series DELETE FROM stockdemo WHERE ticker o ticker AND tstamp purifieddate END Next create two other triggers one update specific for example stockdemo_sv_update and the other insert specific for example stockdemo_sv_insert S the Time Series cartridge usage demo for an example After creating all appropriate triggers grant SELECT DELE UPDATE and INSERT privileges on the security view to the appropriate users For example GRANT SELECT DELETE UPDATE INSERT on stockdemo_sv TO ordtus
55. date the effective units value is nega tive startDate Starting date to be used in calculating the lead or lag value also the starting date in the input time series for which the output time series is to be created If startDate is specified endDate must also be specified endDate Ending date in the input time series for which the output time series is to be cre ated If endDate is specified startDate must also be specified The function creates a time series whose elements reflect an input time series adjusted by a number of timestamps For example using the United States stock trading calendar for 1997 if the first timestamp in the input time series is 06 Jan 1997 Monday and the units value is 2 the first timestamp in the output time series is 02 Jan 1997 Thursday and its associated value such as closing price is the same as that for 06 Jan 1997 in the input time series Subsequent elements of the output time series reflect the timestamp adjustment For example assuming the United States stock trading calendar for 1997 Table 5 1 shows some time series data with a two day lag period Table 5 1 Lagging a Time Series by Two Days Input Time Series Output Time Series Timestamp Closing Price Timestamp Closing Price 06 Jan 1997 49 50 02 Jan 1997 49 50 07 Jan 1997 49 25 03 Jan 1997 49 25 08 Jan 1997 50 00 06 Jan 1997 50 00 5 60 Oracle8 Time Series Cartridge User s Guide Lag Example For convenie
56. define additional kinds of data specifying both the structure of the data and the ways of operating on it and use these types within the relational model This approach adds value to the data stored in a data base Oracle8 with the objects option stores structured business data in its natural form and allows applications to retrieve it that way For that reason it works efficiently with applications developed using object oriented programming techniques 1 3 Storing and Accessing Data The Time Series cartridge can store time series data in the database under transac tional control Once stored in the database this data can be queried and retrieved by finding a row in a table that contains the primary key which includes the timestamp using the various alphanumeric columns attributes of the table Typical queries might include the following a Select the closing price from a stock market data table where the ticker stock symbol is XYZ and the date is 30 May 1997 a Select the 30 day moving average of stock XYZ for the month of May 1997 Applications access and manipulate time series data using SQL or PL SQLM See the Oracle8 SQL Reference manual for information on SQL syntax 1 2 Oracle8 Time Series Cartridge User s Guide Installing the Kit 1 4 Installing the Kit The exact procedure for installing the Time Series cartridge is platform dependent For more detailed information see the README txt file for your platf
57. endDate DATE RETURN ORDSYS ORDTNumSeries Description Given a time series a positive or negative number units or a date lead_date and optionally a starting and ending timestamp within the time series returns a time series that leads or for negative numeric values lags the input time series by the appropriate number of timestamps Parameters ts The input time series units Integer specifying the number of timestamps by which the output time series is to be adjusted If units is positive each element in the output time series is the same as the element in the input time series for that relative position plus the units If units 5 66 Oracle8 Time Series Cartridge User s Guide Lead Usage is negative each element in the output time series is the same as the element in the input time series for that relative position minus the units lead_date The date relative to the starting date reflecting the number of timestamps by which the output time series is to be adjusted The function calculates the number of timestamps between lead_date and startDate and then uses that number as if it were a units parameter value If lead_date is later than startDate the effective units value is positive if lead_date is before startDate the effective units value is negative startDate Starting date to be used in calculating the lead or lag value also the starting date in the input time series for which the output time series i
58. equivalent to Lag with 10 for units Moreover because of the way the lead_date parameter is interpreted Lead and Lag with a lead_date operate identically Return a time series starting with 03 Mar 1997 using closing prices from the time series from 01 Nov 1996 through 30 Nov 1996 for stock ACME The returned time series has the same number of timestamps as are in the specified date range start Date through endDate SELECT FROM the SELECT CAST ORDSYS TimeSeries ExtractTable ORDSYS TimeSeries Lead ts close to_date 03 MAR 97 DD MON YY to_date 01 NOV 96 DD MON YY to_date 30 NOV 96 DD MON YY AS ORDSYS ORDTNumTab FROM ORDTDEV stockdemo_ts ts WHERE ts ticker ACME This example might produce the following output 03 MAR 97 59 04 MAR 97 60 05 MAR 97 61 06 MAR 97 62 07 MAR 97 63 10 MAR 97 64 27 MAR 97 77 28 MAR 97 78 20 rows selected 5 68 Oracle8 Time Series Cartridge User s Guide Mavg Mavg Format Description Parameters ORDSYS TimeSeries Mavg ts ORDSYS ORDTNumSerieslOTRef startDate DATE endDate DATE k INTEGER RETURN ORDSYS ORDTNumSeries Given an input ORDTNumsSeries returns a moving average for the time series or for the date range if one is specified Each value in the returned time series is the average of the value for the current timestamp plus the value for each of the previ
59. follows name is the name of the time series cal is a REF to the calendar table_name is the fully qualified name of the flat IOT tstamp_colname is the name of tstamp column in the flat IOT value_colname is the name of the value column in the flat IOT for example close for the closing price qualifier_colname is the name of the column that identifies a time series instance for example ticker qualifier_value is the value of the column that identifies a time series instance for example ACME which is the ticker for Acme Corporation In the Time Series cartridge usage demo the view stockdemo_ts uses the reference based interface to time series functions The stockdemo_ts view determines which calendar should be coupled with the time series by accessing the calendar stockdemo_calendars and metadata stockdemo_metadata tables The pricing data is accessed through the underlying table containing historical time series pricing data stockdemo For an illustration of the relationship between the reference based view and the underlying tables in the Time Series cartridge usage demo see Figure 1 1 in Chapter 1 The stockdemo_ts view is defined as follows CREATE OR REPLACE SELECT meta ti VIEW stockdemo_ts ticker open high low close volume AS ckername ORDSYS ORDTNumSeriesIOTRef substr meta tickername 1 230 open NumSeries Ref cal ordtdev stockdemo tstamp op
60. lead_date and returns a time series where the starting timestamp is the lead_date Note that to simplify the presentation some error checking has been omitted 3 16 Oracle8 Time Series Cartridge User s Guide Using Product Developer Functions create function Lead ts ORDSYS ORDINumSeries lead_date date i integer ts ORDSYS ORDTNumSeries Temporary Storage for Result out return ORDSYS ORDTNumSeries is new_tstamp date Changeable version of lead date las t_lead_date date Last timestamp of the output time series first _tstamp date First timestamp of las las uni the input time series t_index integer Last index of the input time series t_tstamp date Last timestamp of the input time series ts integer Number of timestamps between input and output time series ERR_LEAD_TSTAMP_BOUNDS constant integer 20540 ERR_LEAD TSTAMP_BOUNDS_MSG constant varchar2 100 Projected lead timestamp beyond calendar bounds begin first_tstamp ts series 1 tstamp last_index ts series last last_tstamp ts series last_index tstamp if ORDSYS Calendar IsValidDate ts cal lead_date 0 then Raise Application Error ERR_LEAD_TSTAMP_BOUNDS ERR_LEAD_TSTAMP_BOUNDS_MSG end if units is the number of timestamps between the first timestamp of the input time series and lead date units
61. not equal the function returns NULL Contrast this function with IntersectCals which intersects two calendars Example Perform a union of two calendars CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE FORMAT MM DD YYYY HH24 MI SS DECLARE tstCall ORDSYS ORDTCalendar tstCal2 ORDSYS ORDTCalendar resultCal ORDSYS ORDTCalendar equalFlag INTEGER dummyVal INTEGER BEGIN Select the calendars GENERIC CAL1 into tstCall and GENERIC CAL2 into tstCal2 from stockdemo calendars SELECT value cal INTO tstCall FROM ORDTIDEV stockdemo_calendars cal WHERE cal name GENERIC CAL1 SELECT value cal INTO tstCal2 FROM ORDTDEV stockdemo_calendars cal WHERE cal name GENERIC CAL2 Display the calendars tstCall and tstCal2 SELECT ORDSYS TimeSeries Display tstCall INTO dummyVal FROM dual SELECT ORDSYS TimeSeries Display tstCal2 INTO dummyVal FROM dual Union tstCall and tstCal2 resultCal ORDSYS Calendar Unioncals tstCall tstCal2 SELECT ORDSYS TimeSeries Display resultCal result of UnionCals INTO dummyVal FROM dual END 4 66 Oracle8 Time Series Cartridge User s Guide UnionCals This example might produce the following output Calendar Name GEN Frequency 4 MinDate MaxDate patBits 01 patAnchor
62. or invalid checkDate The timestamp to be checked for validity according to the calendar If checkDate is valid the function returns 1 if checkDate is invalid the function returns 0 A timestamp is invalid if any of the following conditions is true a Itis outside the date range of the calendar a Itis an off exception in the calendar a Itis not sufficiently precise for example a timestamp of 01 Jul 1997 if the calen dar has a frequency of year a Itisnull Check if 02 Jan 1996 is a valid timestamp for a calendar GENERIC CAL1 CONNECT ORDTUSER ORDTUSER 4 40 Oracle8 Time Series Cartridge User s Guide IsValidDate SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE FORMAT MM DD YYYY HH24 MI SS DECLARE tstCal ORDSYS ORDTCalendar tstDatel DATE result INTEGER dummyVal BEGIN INTEGER Select a calendar say GENERIC CAL1 into tstCal from stockdemo_calendars SELECT value cal INTO tstCal FROM ORDTIDEV stockdemo_calendars cal WHERE cal name GENERIC CAL1 Disp lay the calendar SELECT ORDSYS TimeSeries Display tstCal INTO dummyVal FROM dual DBMS_OU PUT NEW_LINE Verify if 02 JAN 1996 a Monday is a valid date and display the result tstDatel TO_DATE 01 02 1996 result ORDSYS Calendar IsValidDate
63. ordtnumcell Bin pI 12 02 1996 1 12 03 1996 2 12 04 1996 3 12 05 1996 4 12 06 1996 5 12 09 1996 6 12 10 1996 7 12 11 1996 8 112 12 1996 9 12 13 1996 10 TO_DATE ORDSYS ordtnumcell TO_DATE ORDSYS ordtnumcell TO_DATE ORDSYS ordtnumcell TO_DATE ORDSYS ordtnumcell TO_DATE dummyval INTEGER BEGIN Generate a timeseries by from XCORP s high repeat forward SELECT ORDSYS TimeSeries Display ORDSYS TimeSeries Fill ts 1 Fill Forward INTO dummyval FROM dual Generate a timeseries by from XCORP s high repeat backward SELECT ORDSYS TimeSeries Display ORDSYS TimeSeries Fill ts 2 Fill Backward INTO dunmyval FROM dual Generate a timeseries by from XCORP s high null fill SELECT ORDSYS TimeSeries Display ORDSYS TimeSeries Fill ts 0 Null Fill INTO dummyval 5 36 Oracle8 Time Series Cartridge User s Guide Fill FROM dual END This example might produce the following output Fill Forward Calendar Data Calendar Name FOO CALENDAR Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 01 01 1997 00 00 00 patBits 1111111 patAnchor 01 07 1996 00 00 00 onExcept ions offExceptions Series Data N o e ie ie Oo Ooo a ao O GOG O Oo MOD OD Oo oOo Oo amp Om OOo co O Co Oa Oo G N p N Ss ie
64. series A null is returned if the time series fs is empty An exception is returned if the time series ts is null Return the last timestamp and opening price for stock ACME in the stockdemo_ts time series SET SERVEROUTPUT ON ALTER SESSION SET NLS DATE FORMAT MM DD YYYY HH24 MI SS DECLARE dummyval INTEGER BEGIN SELECT ORDSYS TimeSeries Display ORDSYS TimeSeries Last ts open Last Results INTO dummyval FROM ORDTDEV stockdemo_ts ts WHERE ts ticker ACME END 5 62 Oracle8 Time Series Cartridge User s Guide Last This example might produce the following output Last Results Timestamp 12 31 1996 00 00 00 Value 99 Time Series and Time Scaling Functions Reference 5 63 LastN LastN Format Description Parameters Usage Example ORDSYS TimeSeries LastN ts ORDSYS ORDTNumSerieslOTRef NumValues NUMBER RETURN ORDSYS ORDTNumSeries Given a time series and a number of elements NumValues to return returns the last NumValues elements in the time series ts The input time series NumValues Number of elements from the end of the time series to be returned The function returns a time series populated with the last Num Values cells from the input time series ts The calendar of the output time series is the same as that of the input time series An exception is returned if the time series
65. series2 ORDTNumSerieslOTRef or DeriveExceptions seriesi ORDTVarchar2SerieslOTRef series2 ORDTVarchar2SerieslOTRef 3 14 Oracle8 Time Series Cartridge User s Guide Deriving Calendar Exceptions This overloading of the DeriveExceptions function allows the input parameters to be time series REFs either two ORDTNumSeriesIOTRef parameters or two ORDTVarchar2SeriesIOTRef parameters Before calling DeriveExceptions you must construct a time series based on a refer ence calendar This time series will contain all the timestamps within the date range minDate through maxDate of the calendar The following example builds a reference time series based on a calendar named PATTERN ONLY An INSERT statement populates the time series named PAT TERN ONLY with the valid timestamps between the starting and ending dates of the calendar INSERT INTO stocks ticker tstamp SELECT PATTERN ONLY tl cl FRO SELECT column_value cl FROM the SELECT CAST ORDSYS Calendar TimeStampsBet ween VALUE cal cal mindate cal maxdate AS ORDSYS ORDTDateTab FROM stock_calendars cal WHERE cal name PATTERN ONLY t1 The insertion is made directly into the underlying table not into the security view Using the underlying table is safe here because the time series is presumed to be correct so the mechanisms for ensuring consistency between the time series and the calendar provided by the security view
66. state ment but it does support DBMS_OUTPUT for anonymous PL SQL blocks Example Display the output for a query that returns the 10 highest closing prices for stock AONE for the month of January 1996 SET SERVEROUTPUT ON DECLARE tmp INTEGER BEGIN SELECT ORDSYS TimeSeries Display ORDSYS TimeSeries TSMaxN close 10 to_date 01011996 MMDDYYYY to_date 01311996 MMDDYYYY INTO tmp FROM ORDTDEV stocks_ts WHERE ticker AONE END This example might produce the following output 5 16 Oracle8 Time Series Cartridge User s Guide Display Date Value 01 24 1996 00 00 00 43 9138 01 25 1996 00 00 00 42 9925 01 31 1996 00 00 00 42 9925 01 26 1996 00 00 00 42 7413 01 30 1996 00 00 00 42 7413 01 29 1996 00 00 00 42 5738 01 23 1996 00 00 00 41 9875 01 22 1996 00 00 00 41 82 01 19 1996 00 00 00 41 485 01 18 1996 00 00 00 40 815 The preceding example works from both SQL Plus and the Server Manager svrmgrl prompt The following version of the example works from the Server Manager prompt but not from SQL Plus SET SERVEROUTPUT ON SELECT ORDSYS TimeSeries Display ORDSYS TimeSeries TSMaxN close 10 FROM ORDTDI to_date 01011996 M to_date 01311996 EV stocks_ts WHERE ticker AONE DYYYY DYYYY See the TSMaxN function for a
67. tables and calendars constructing security views constructing views to synthesize the interface to time series functions and running some example queries 1 6 1 Running the Usage Demo After the cartridge has been installed you can run the usage demo by going to the appropriate directory see Table 1 1 and invoking the demo sql procedure as fol lows o svrmgrl SVRMGR gt demo 1 6 2 Usage Demo Files The usage demo files include examples of bulk and incremental loading defining tables calendars and views for the time series cartridge and running example que ries These files are listed in Table 1 2 Table 1 2 Time Series Cartridge Usage Demo Files File Description demo sql stockdat ctl stockdat dat tables sql popcal sql securevw sql refvw sql queries sql queplsq l sql calqueries sql Main procedure file SQL Loader control file SOL Loader data file for time series data DDL for tables Defines calendars and populates calendar table Example security view Example reference based view Example time series queries SQL Example time series queries PL SQL Example calendar queries PL SQL Introduction 1 5 Time Series Cartridge Demos Demonstrations Table 1 2 Time Series Cartridge Usage Demo Files Cont File Description incload sql Incremental load script stockinc ctl SOL Loader control file for incremental load stockinc dat SOL Loader data file for incremental time series da
68. the function the results of this query have no practical value for financial analysis SELECT FROM the SELECT CAST ORDSYS TimeSeries ExtractTable ORDSYS TimeSeries Cprod ts volume to_date 01 NOV 96 DD MON YY to_date 06 NOV 96 DD MON YY AS ORDSYS ORDTNumTab FROM ORDTDEV stockdemo_ ts ts WHERE ts ticker ACME This example might produce the following output TSTAMP VALUE 01 NOV 96 1000 04 NOV 96 1000000 05 NOV 96 1000000000 06 NOV 96 1 0000E 12 4 rows selected 5 10 Oracle8 Time Series Cartridge User s Guide Csum Csum Format Description Parameters Usage ORDSYS TimeSeries Csum ts ORDSYS ORDTNumsSerieslOTRef stariDate DATE endDate DATE RETURN ORDSYS ORDTNumSeries Given a time series returns an ORDTNumeSeries with each element containing the cumulative sum up to and including the corresponding element in the input ORDT NumSeries ts The input time series startDate Starting date within the time series for which the cumulative sum is to be com puted If startDate is specified endDate must also be specified endDate Ending date within the time series for which the cumulative sum is to be com puted If endDate is specified startDate must also be specified Only non null values are considered in computing the cumulative sum An exception is returned if any of the following conditions is
69. ts The input time series startDate Starting date within the time series for which the median is to be calculated If start Date is specified endDate must also be specified endDate Ending date within the time series for which the median is to be calculated If end Date is specified startDate must also be specified An exception is returned if any of the following conditions is true a The time series ts is null a The time series ts does not have an associated calendar a endDate is earlier than startDate Return the median closing price for stock AONE for the month of January 1990 SELECT ORDSYS TimeSeries TSMedian close Time Series and Time Scaling Functions Reference 5 109 TSMedian FROM ORDTD WHERE ticker AON EV Stoc ks_TS Tl Do to date 01 01 1990 00 00 00 MM DD YYYY HH24 MI SS to date 01 31 1990 23 59 59 MM DD YYYY HH24 MI SS TSMedian This example might produce the following output 15 4649 1 row selected 5 110 Oracle8 Time Series Cartridge User s Guide TSMin TSMin Format Description Parameters Usage Example ORDSYS TimeSeries TSMin ts ORDSYS ORDTNumsSerieslOTRef startDate DATE endDate DATE RETURN NUMBER Given an input ORDTNumsSeries and optionally starting and ending dates returns a number corresponding to the lowest minimum of all non null time series entries ts The input time series
70. validating 4 34 4 69 calendar functions 2 20 4 1 Cavg function 5 3 Index Cmax function 5 5 Cmin function 5 7 collection based interface 2 13 CombineCals function 4 2 consistency of time series data approaches 2 20 3 10 conventional path SQL Loader 3 13 conversion functions 2 30 count TSCount function 5 99 Cprod function 5 9 cumulative sequence functions 2 29 D data cartridge definition 1 1 datatypes calendar 2 7 time series 2 23 defining calendar 2 8 DeleteExceptions function 4 7 demos of Time Series cartridge advanced developer 1 4 Developer 2000 1 4 OCI 1 4 PRO C C 1 4 usage 1 4 DeriveExceptions function 2 9 5 13 Developer 2000 demo 1 4 direct path SQL Loader 3 13 Display function 5 15 DisplayValCal procedure 4 10 Index 1 DisplayValTS procedure 5 18 division TSDivide function 5 101 E EqualCals function 4 17 error messages A 1 exceptions 2 5 deriving 2 9 ExtractCal function 5 26 ExtractDate function 5 28 extraction functions 2 26 ExtractTable function 5 30 ExtractValue function 5 32 F Fill function 5 34 First function 5 40 FirstN function 5 42 frequency 2 6 functions calendar 2 20 4 1 Cavg 5 3 Cmax 5 5 Cmin 5 7 CombineCals 4 2 Cprod 5 9 DeleteExceptions 4 7 DeriveExceptions 2 9 5 13 Display 5 15 DisplayValCal procedure 4 10 DisplayValTS procedure 5 18 EqualCals 4 17 ExtractCal 5 26 ExtractDate 5 2
71. 0 00 00 78 29 1996 00 00 00 79 12 03 1996 00 00 00 80 12 04 1996 00 00 00 81 12 05 1996 00 00 00 82 12 06 1996 00 00 00 83 12 09 1996 00 00 00 84 2 10 1996 00 00 00 85 2 11 1996 00 00 00 86 2 12 1996 00 00 00 87 2 13 1996 00 00 00 88 2 16 1996 00 00 00 89 2 17 1996 00 00 00 90 2 18 1996 00 00 00 91 2 19 1996 00 00 00 92 2 20 1996 00 00 00 93 2 29 1996 00 00 00 94 2 28 1996 00 00 00 95 2 26 1996 00 00 00 96 2 27 1996 00 00 00 97 2 30 1996 00 00 00 98 01 04 1997 00 00 00 99 Value returned by IsValid 0 Value returned by ValidateTS 0 DisplayValTS Testing DisplayValTS 5 138 Oracle8 Time Series Cartridge User s Guide ValidateTS TS WRN the input time series has errors See the message for details message output by validateTS TS ERR the input time series is unsorted TS ERR the tim ries has null timestamps TS ERR the tim ries has timestamps lt calendar minDate refer LoDateTab TS ERR the tim ries has timestamps gt calendar maxDate refer HiDateTab TS ERR the tim ries has imprecise timestamps refer impreciseDateTab TS ERR the tim ries has duplicate timestamps refer DuplicateDateTab An NAN NH list of dates lt calendar minDate lowDateTab 10 26 1996 00 00 00 10 27 1996 00 00 00 list of dates gt calendar maxDate hiDateTab 1 06 1997 00 00 00 01 07 1997 00 00 00 o list of imprecise dates impreciseDateTab bh 1 22 1996 01 00 00 11 22 1996
72. 0 Conversion FUNCHONS caia dd 2 30 2 9 Time Scaling FunctiONS cicicicnnocininnonnnnoninnononancnnnnnononancnnnnnonon anno nnnno nan onnnnnononon EiT iak eaii Ta 2 31 2 9 1 Time Scaling on Collections cuina a tt 2 32 2 9 2 Time Scaling in the GROUP BY Clause cocicicicinononicnonnnononcnnonincncacnononinancncnonanonananonos 2 33 3 Time Series Usage 3 1 Using the Cartridsaii a id 3 1 3 1 1 Step 1 Create the Underlying Storage Table ooninicininininoninnnnnimnicrrnincicicnos 3 1 3 1 2 Step 2 Define a Calendar iii rn dt dada 3 2 3 1 3 Step 37 Load Time Series Dita iii 3 4 3 1 4 Step 4 Create a Security View and INSTEAD OF Triggers ccococicincnnnoninnnnnnaninnaninonos 3 4 3 1 5 Step 5 Create a Reference Based View occicicionnicinnnnncnoninnonononnnnoncororononconnororancincnca ranas 3 6 3 1 6 Step 6 Validate Time Series Consistency ococociocoononononinnnninnonnnnnnoninoncnnnonananoncncnonanananons 3 7 3 1 7 Step 7 Formulate Time Series Queries ooconococicininonononincnnnnanananononincncnnnonononononononanananons 3 7 3 2 Loading Time Series Dita ia 3 9 3 2 1 Bulk Loading miii iba 3 10 3 2 2 Incremental Lodi Binner 3 12 3 3 Deriving Calendar Exceptionsssts ccscsscatescassessths caciones 3 13 3 3 1 Deriving Exceptions Using a Calendar and Table of Dates Approach 1 3 13 3 3 2 Deriving Exceptions Using Two Time Series Parameters Approach 2 3 14 3 4 Using Product Developer Functions coocococinnonnnno
73. 00 00 00 00 00 GEN 00 00 00 00 00 00 00 00 ERIC CAL1 7 1996 00 00 00 02 03 1996 00 00 00 03 24 1996 00 00 00 05 19 1996 00 00 00 06 23 1996 00 00 00 08 04 1996 00 00 00 09 15 1996 00 00 00 02 02 1996 00 00 00 03 05 1996 00 00 00 05 08 1996 00 00 00 06 25 1996 00 00 00 05 08 1996 00 00 00 08 04 1996 00 00 00 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1996 00 00 00 patBits 0111110 01 0 patAnchor onException 02 03 1 05 19 1 09 15 1 offExceptions 01 08 1 04 04 1 s 996 996 996 996 996 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 7 1996 00 00 00 03 24 1996 00 00 00 04 27 1996 00 00 00 06 23 1996 00 00 00 07 07 1996 00 00 00 02 02 1996 00 00 00 03 05 1996 00 00 00 06 25 1996 00 00 00 Calendar Functions Reference 4 9 DisplayValCal Procedure DisplayValCal Procedure Format ORDSYS Calendar DisplayValCal validFlag IN INTEGER outMessage IN VARCHAR2 invOnExc IN ORDSYS ORDTDateTab invOffExc IN ORDSYS ORDTDateTab impOnExc IN ORDSYS ORDTDateTab impOffExc IN ORDSYS ORDTDateTab inputCal IN ORDSYS ORDT Calendar mesg IN VARCHAR2 Description Displays the results returned by the ValidateCal function Note DisplayValCal is a procedure not a function Procedures do not return values Parameters 4 10 validFlag The return value from the ValidateCal function call Value Meaning O The calendar
74. 00 0 00 00 02 03 1996 00 05 19 1996 00 08 04 1996 00 02 02 1996 00 05 08 1996 00 NumTimeSt ampsBetween 02 03 1996 00 00 00 4 54 Oracle8 Time Series Cartridge User s Guide 00 00 00 00 00 00 00 00 00 00 03 24 1996 00 00 00 06 23 1996 00 00 00 09 15 1996 00 00 00 03 05 1996 00 00 00 06 25 1996 00 00 00 05 16 1996 00 00 00 74 OffsetDate OffsetDate Format Description Parameters Usage ORDSYS Calendar OffsetDate inputCal INORDSYS ORDTCalendar origin IN DATE relOffset IN INTEGER RETURN DATE Given a reference date origin and an offset with respect to the origin relOffset returns the timestamp corresponding to the offset input inputCal Calendar from which the date is to be returned origin The date to which the offset value relOffset is to be applied in computing the returned date relOffset The relative offset of the returned date with respect to the origin The function returns the date of the timestamp at the relOffset number of timestamps from the origin date If relOffset is positive the returned date is later than origin if relOffset is negative the returned date is earlier than origin If relOffset is zero 0 the returned date is origin if origin is a valid date however if relOffset is zero 0 and origin is not a valid date the function returns NULL For example assume a Monday through Friday business day calendar for 1997 with 04 Jul 1997 Friday d
75. 00 00 04 20 1996 00 00 00 04 21 1996 00 00 00 04 28 1996 00 00 00 05 04 1996 00 00 00 05 05 1996 00 00 00 05 08 1996 00 00 00 05 11 1996 00 00 00 05 12 1996 00 00 00 05 18 1996 00 00 00 05 25 1996 00 00 00 05 26 1996 00 00 00 06 01 1996 00 00 00 06 02 1996 00 00 00 Calendar Functions Reference 4 33 IsValidCal IsValidCal Format Description Parameters Usage Example ORDSYS Calendar IsValidCal inputCal IN ORDSYS ORDT Calendar RETURN BINARY_INTEGER Returns 1 if the calendar is valid and 0 if the calendar is not valid inputCal The calendar to be checked for validity A calendar is invalid not valid if it contains any errors This function does not cor rect any errors or perform any repair operations on the calendar Contrast this function with the ValidateCal function which checks the validity of the calendar and repairs any correctable errors For detailed information on calen dar errors see the information on ValidateCal in this chapter If the IsValidCal function returns 0 you should do the following before you attempt to use the calendar 1 Use the ValidateCal function to repair any correctable errors 2 If there are any errors that ValidateCal cannot correct correct these errors your self 3 Repeat steps 1 and 2 as often as necessary until the resulting calendar is valid Use the IsValidCal and ValidateCal functions and the DisplayValCal procedure with
76. 00 00 05 08 1996 07 09 1996 00 00 00 08 05 1996 10 23 1996 00 00 00 11 19 1996 4 30 Oracle8 Time Series Cartridge User s Guide 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09 15 1996 12 14 1996 03 08 1997 06 08 1997 09 10 1996 12 12 1996 03 04 1997 06 09 1997 09 15 1996 03 05 1996 06 25 1996 09 10 1996 12 12 1996 09 15 1996 03 05 1996 06 25 1996 09 10 1996 12 12 1996 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 InvalidTimeStampsBetween InvalidTimeStampsBetween Format Description Parameters Usage ORDSYS Calendar InvalidTimeStampsBetween inputCal IN ORDSYS ORDT Calendar startDate IN DATE endDate IN DATE RETURN ORDSYS ORDTDateTab Given starting and ending input timestamps returns a table ORDTDateTab con taining the invalid timestamps within that range according to the specified calen dar inputCal The calendar to be used to determine whether a timestamp is valid or invalid startDate Starting date in the range to be checked for inv
77. 000 NOTE Here an instance of the tim series is materialized so that it could be modified to generate an invalid time series SELECT ORDSYS TIMES FROM ordtdev stockdemo_ts ts WHERE ts ticker ACME lt Example of validating a valid time series SELECT ordsys timeseries display numTS A VALID TII FROM dual ERIES GetSeries ts open INTO numTS retIsValid ORDSYS TIMESERIES IsValidTS numTS retValTS ORDSYS TIMESERIES ValidateTS numTS out DBMS_OUTPUT PUT_LIN DBMS_OUTPUT PUT_LIN E SERIES INTO tempVal lesg loDateTab hiDateTab impDateTab dupDateTab extraDateTab missingDateTab E Value returned by IsValid E Value returned by ValidateTS ret IsValid retValTS ORDSYS TIMESERIES DisplayValTS retValTS outMesg loDateTab hiDateTab impDateTab dupDateTab extraDateTab missingDateTab DBMS_OUTPUT NEW_LINE Testing DisplayValTS For illustration let us first create an invalid timeseries Here we are adjusting the calendar s minDate and maxDate to avoid getting a huge list of missing dates numTS cal minDate numTS cal maxDate 110 28 1996 101 05 1997 TO_DATI TO_DATI E E 5 20 Oracle8 Time Series Cartridge User s Guide Dis
78. 01 Jan 1997 17 Feb 1997 and 26 May 1997 as off exceptions UPDATE stockdemo calendars cal SET cal SELECT ORDSYS Calendar InsertExceptions VALUE cal ORDSYS ORDTDateTab to_date 01 JAN 97 DD MON YY to_date 17 FEB 97 DD MON YY Time Series Usage 3 11 Loading Time Series Data to_date 26 MAY 97 DD MON YY FROM dual WHERE cal name BUSINESS 96 After you have defined the calendar and populated the exception lists you can use the IsValidTimeSeries function to check that the time series is consistent with the calendar 3 2 2 Incremental Loading 3 12 After you have performed the bulk load of time series data and have started using the Time Series cartridge you will probably want to add data periodically For example every trading day after the stock exchange closes that day s data for each ticker becomes available As with bulk loading incremental loading is typically done in a controlled environ ment You know which timestamps will become off exceptions and you can explic itly update the exception lists of the appropriate calendars The following example demonstrates such an update UPDATE stockdemo_calendars cal SET cal SELECT ORDSYS Calendar InsertExceptions VALUE cal to date 01 JAN 97 DD MON YY FROM dual WHERE cal name XCORP The SQL Loader utility is recommended f
79. 1 if the time series is valid and 0 if the time series is invalid ts The input time series A time series is invalid if one or more of the following conditions are true a The time series ts is null a The time series ts does not have an associated calendar a The calendar associated with the time series is invalid a The timestamps are not sorted a One or more timestamps are null imprecise or outside the date range of the calendar One or more timestamps are included in the time series but should be excluded based on the calendar definition for example a Saturday timestamp that is in a Monday Friday calendar and that is not an on exception Time Series and Time Scaling Functions Reference 5 51 IsValidTS One or more timestamps are excluded from the time series but should be included based on the calendar definition for example a Wednesday date that is not a holiday in a Monday Friday calendar and for which there is no data Such dates can be considered as holes in the time series Contrast this function with ValidateTS which checks whether a time series is valid and if the time series is not valid outputs a diagnostic message and tables with timestamps that are causing the time series to be invalid Example Use the IsValidTS and ValidateTS functions and the DisplayValTS procedure with an invalid time series SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE_ FORMAT MM DD YYYY HH24 MI SS
80. 11 22 1996 15 00 00 list of duplicate dates duplicateDateTab 11 22 1996 15 00 00 11 29 1996 00 00 00 ExtraDateTab 12 28 1996 00 00 00 12 29 1996 00 00 00 01 04 1997 00 00 00 MissingDateTab 10 28 1996 00 00 00 10 29 1996 00 00 00 10 30 1996 00 00 00 10 31 1996 00 00 00 11 14 1996 00 00 00 11 15 1996 00 00 00 11 18 1996 00 00 00 11 19 1996 00 00 00 11 20 1996 00 00 00 11 21 1996 00 00 00 11 25 1996 00 00 00 11 26 1996 00 00 00 11 27 1996 00 00 00 12 02 1996 00 00 00 12 23 1996 00 00 00 12 24 1996 00 00 00 12 31 1996 00 00 00 01 01 1997 00 00 00 01 02 1997 00 00 00 01 03 1997 00 00 00 Time Series and Time Scaling Functions Reference 5 25 ExtractCal ExtractCal Format Description Parameters Usage Example ORDSYS TimeSeries ExtractCal ts ORDSYS ORDTNumSeries OTRef RETURN ORDSYS ORDT Calendar or ORDSYS TimeSeries ExtractCal ts ORDSYS ORDTVarchar2SerieslOTRef RETURN ORDSYS ORDT Calendar Given a time series returns a calendar that is the same as the calendar on which the time series is based ts The input time series The function returns a calendar that has the same starting and ending timestamps pattern frequency and exceptions on and off as the calendar on which the speci fied time series is based An exception is returned if the time series ts is null Return a calendar that matches the one on which the time series for the ACME ticker is based SET SERVEROUTPUT ON ALT
81. 18 NOV 96 64 5 19 NOV 96 65 20 NOV 96 65 5 21 NOV 96 66 22 NOV 96 66 5 25 NOV 96 67 26 NOV 96 67 5 27 NOV 96 68 29 NOV 96 68 5 20 rows selected 5 4 Oracle8 Time Series Cartridge User s Guide Cmax Cmax Format Description Parameters Usage ORDSYS TimeSeries Cmax ts ORDSYS ORDTNumSeries OTRef stariDate DATE endDate DATE RETURN ORDSYS ORDTNumSeries Given a time series returns an ORDTNumeSeries with each element containing the cumulative maximum up to and including the corresponding element in the input ORDTNumSeries ts The input time series startDate Starting date within the time series for which the cumulative maximum is to be returned If startDate is specified endDate must also be specified endDate Ending date within the time series for which the cumulative maximum is to be returned If endDate is specified startDate must also be specified Only non null values are considered in determining the cumulative maximum An exception is returned if any of the following conditions is true a The time series ts is null a The time series ts does not have an associated calendar a endDate is earlier than startDate Time Series and Time Scaling Functions Reference 5 5 Cmax If startDate and endDate are specified the time series is trimmed to the date range before the cumulative maximum is computed Example Return the cumulative maximum of the closing price of stock ACME for
82. 1996 06 25 1996 09 15 1 12 14 1 03 08 1 06 08 1 996 996 997 997 09 10 1 12 12 1 03 04 1 06 09 1 996 996 997 997 09 15 1996 03 05 1996 06 25 1996 09 10 1996 12 12 1996 00 00 00 00 00 00 00 00 00 00 Oo O OO O O O O 00 00 00 00 00 OS OS So lt lt E So 2 O gt a lt lt 00 00 00 00 00 00 00 00 00 00 QS O E O OO oO Co See O ES Oouooo 00 00 00 00 00 Calendar Functions Reference 4 5 CombineCals result of IntersectCals Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1996 00 00 00 patBits 1111100 patAnchor 01 08 1996 00 00 00 onExcept ions 07 07 1996 00 00 00 offExceptions 01 08 1996 00 00 00 04 04 1996 00 00 00 07 09 1996 00 00 00 10 23 1996 00 00 00 4 6 Oracle8 Time Series Cartridge User s Guide 08 04 1996 00 00 00 02 02 1996 00 00 00 05 08 1996 00 00 00 08 05 1996 00 00 00 11 19 1996 00 00 00 09 15 1996 00 00 00 03 05 1996 00 00 00 06 25 1996 00 00 00 09 10 1996 00 00 00 12 12 1996 00 00 00 DeleteExceptions DeleteExceptions Format Description Parameters Usage ORDSYS Calendar DeleteExceptions inputCal INORDSYS ORDTCalendar delExcDate IN DATE RETURN ORDSYS ORDT Calendar or ORDSYS Calendar DeleteExceptions inputCal INORDSYS ORDTCalendar delExcTab INORDSYS ORDTDateTab RETURN ORDSYS ORDT Calendar Deletes f
83. 1996 00 00 00 onExcept ions 01 21 1996 00 00 00 02 03 1996 04 27 1996 00 00 00 05 19 1996 07 07 1996 00 00 00 08 04 1996 offExceptions 01 08 1996 00 00 00 02 02 1996 04 04 1996 00 00 00 05 08 1996 07 09 1996 00 00 00 Calendar Name GENERIC CAL2 Frequency 4 MinDate MaxDate patBits 1111100 patAnchor 01 0 onExcept ions 07 07 1996 10 13 1996 01 04 1997 04 05 1997 offExceptions 07 09 1996 10 23 1996 01 01 1997 04 07 1997 CO OO OOO oO O D gt SiO OO 01 01 1996 00 00 00 12 31 1997 00 00 00 8 1996 00 00 00 00 00 00 00 00 00 00 00 result of CombineCals Frequency 4 MinDate 01 01 MaxDate 12 31 patBits 0111110 patAnchor 01 0 onExceptions 07 07 1996 0 offExceptions 01 08 1996 0 04 04 1 07 09 1 10 23 1996 0 equalFlag 0 1996 1996 00 08 04 1996 00 11 10 1996 00 02 09 1997 00 05 11 1997 00 08 05 1996 00 11 19 1996 00 02 12 1997 00 05 05 1997 00 00 00 00 00 00 7 1996 00 00 00 0 00 0 00 0 00 0 00 0 00 00 08 04 1996 00 02 02 1996 00 05 08 1996 00 08 05 1996 00 11 19 1996 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 oooo ko 1 oooo CI ED 2 G3 00 00 00 00 00 03 24 1996 06 23 1996 09 15 1996 03 05
84. 1996 00 00 00 67 5 54 Oracle8 Time Series Cartridge User s Guide IsValidTS 11 14 1996 00 00 00 68 15 1996 00 00 00 69 18 1996 00 00 00 70 19 1996 00 00 00 71 20 1996 00 00 00 72 21 1996 00 00 00 73 22 1996 00 00 00 74 25 1996 00 00 00 75 26 1996 00 00 00 76 27 1996 00 00 00 77 29 1996 00 00 00 78 12 02 1996 00 00 00 79 12 03 1996 00 00 00 80 12 04 1996 00 00 00 81 12 05 1996 00 00 00 82 12 06 1996 00 00 00 83 12 09 1996 00 00 00 84 2 10 1996 00 00 00 85 2 11 1996 00 00 00 86 2 12 1996 00 00 00 87 2 13 1996 00 00 00 88 2 16 1996 00 00 00 89 2 17 1996 00 00 00 90 2 18 1996 00 00 00 91 2 19 1996 00 00 00 92 2 20 1996 00 00 00 93 2 23 1996 00 00 00 94 2 24 1996 00 00 00 95 2 26 1996 00 00 00 96 2 27 1996 00 00 00 97 2 30 1996 00 00 00 98 2 31 1996 00 00 00 99 Value returned by IsValid 1 Value returned by ValidateTS 1 DisplayValTS Testing DisplayValTS TS SUC the input time series is a valid time series AN INVALID TIME SERIES Name ACME open NumSeries Time Series and Time Scaling Functions Reference 5 55 IsValidTS Calendar Data Calendar Name BUSINESS 96 Frequency 4 MinDate 10 28 1996 00 00 00 MaxDate 01 05 1997 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions offExceptions 11 28 1996 00 00 00 12 25 1996 00 00 00 Series Data Date
85. 2 2 6 regular 2 1 validating 3 11 5 51 5 131 time series functions 2 23 5 1 TimeStampsBetween function 4 61 top values TSMax function 5 107 trim functions 2 26 TrimSeries function 5 90 TSAdd function 5 93 TSAvg function 5 97 TSCount function 5 99 TSDivide function 5 101 TSMax function 5 105 TSMaxN function 5 107 TSMedian function 5 109 TSMin function 5 111 TSMinN function 5 113 TSMultiply function 5 115 TSProd function 5 119 TSStdDev function 5 121 TSSubtract function 5 123 TSSum function 5 127 TSVariance function 5 129 U UnionCals function 4 65 usage demo 1 4 files 1 5 tables and views 1 6 2 16 V ValidateCal function 4 69 ValidateTS function 5 131 validating calendar 4 34 4 69 time series 3 11 5 51 5 131 variance TSVariance function 5 129 Index 5 Index 6
86. 2 2 a Calendar functions described in this chapter time series and time scaling functions described in Chapter 5 Two separate reference chapters are provided for the functions because the func tions described in each are typically done at different times in the application devel opment cycle and by people performing different job roles a Calendar functions are mainly used by product developers such as ISVs to develop new time series functions and to administer and modify calendars a Time Series and time scaling functions are used mainly by application develop ers and some end users after the associated calendar or calendars have been defined Syntax notes a The ORDSYS schema name and the package name must be used with the func tion name although public synonyms can be created to eliminate the need for specifying the schema name see Section 1 4 Each function is included in a PL SOL package such as Calendar or TimeSeries The ORDSYS schema name and the package name are included in the Format and in any examples a Function calls are not case sensitive except for any quoted literal values For example the following code line excerpts are valid and semantically identical select CAST TimeSeries ExtractTable close AS ORDTNumTab select cast TIMESERIES extracttable close as ordtnumtab select cast TiMeSeRiEs eXtRaCtTaBlE ClosE As ordtNUMtab Calendar Functions Reference 4 1
87. 29 1996 00 00 00 79 12 03 1996 00 00 00 80 12 04 1996 00 00 00 81 12 05 1996 00 00 00 82 12 06 1996 00 00 00 83 12 09 1996 00 00 00 84 12 10 1996 00 00 00 85 12 11 1996 00 00 00 86 12 12 1996 00 00 00 87 12 13 1996 00 00 00 88 12 16 1996 00 00 00 89 12 17 1996 00 00 00 90 12 18 1996 00 00 00 91 12 19 1996 00 00 00 92 12 20 1996 00 00 00 93 12 29 1996 00 00 00 94 12 28 1996 00 00 00 95 12 26 1996 00 00 00 96 12 27 1996 00 00 00 97 12 30 1996 00 00 00 98 01 04 1997 00 00 00 99 Value returned by IsValid 0 Value returned by ValidateTS 0 DisplayValTS Testing DisplayValTS TS WRN the input time series has errors See the message for details message output by validateTS 5 24 Oracle8 Time Series Cartridge User s Guide DisplayValTS Procedure TS ERR the input time series is unsorted TS ERR the tim ries has null timestamps TS ERR the tim ries has timestamps lt calendar minDate refer LoDateTab TS ERR the tim ries has timestamps gt calendar maxDate refer HiDateTab TS ERR the tim ries has imprecise timestamps refer impreciseDateTab TS ERR the tim ries has duplicate timestamps refer DuplicateDateTab Ann nH DN list of dates lt calendar minDate lowDateTab 10 26 1996 00 00 00 10 27 1996 00 00 00 list of dates gt calendar maxDate hiDateTab 1 06 1997 00 00 00 01 07 1997 00 00 00 o list of imprecise dates impreciseDateTab m 1 22 1996 01 00 00
88. 31 1995 Maps to 0 in pattern Sunday O_DATE 01 13 1996 Maps to 0 in pattern Saturday O_DATE 02 24 1996 Maps to 0 in pattern Saturday O_DATE 03 30 1996 Maps to 0 in pattern Saturday O_DATE 02 02 1996 01 01 01 Imprecise O_DATE 03 04 1996 01 01 01 Imprecise O_DATE 04 05 1996 02 02 02 Imprecise O_DATE 03 25 1996 Valid off exception O_DATE 01 22 1996 Valid but out of sequence O_DATE 02 12 1996 O_DATE 04 30 1996 NULL Null date O_DATE 02 12 1996 Duplicate date within OFFs NULL Null date O_DATE 04 30 1996 Duplicate off exception NULL Null date O_DATE 03 25 1996 Duplicate off exception O_DATE 01 22 1996 Duplicate off exception O_DATE 01 17 1996 Added to on and off exceptions O_DATE 05 28 1996 Added to on and off exceptions O_DATE 06 18 1996 Added to on and off exceptions O_DATE 04 23 1996 Added to on and off exceptions O_DATE 02 02 1996 4 72 Oracle8 Time Series Cartridge User s Guide ValidateCal O DA E 03 04 1996 O DA E 05 06 1997 ORDSYS ORDTExceptions O DA E 02 08 1969 O DA 02 15 1969 O DA r 02 13 1999 O DA O DA 01 03 1996
89. 4 1996 O DA O DA r03 23 1996 O DA E 05 28 1996 O DA E 06 18 1996 O DA E 04 23 1996 O DA E 01 06 1996 O DA E 02 03 1996 O DA BEGIN SELECT ORDSYS FROM dual validFlag ORDSYS CA IF validFlag THE validFlag t E E 01 17 1996 E 05 04 1997 Added to on and off exceptions Date Date Date Date laps laps laps laps DOL 01 2010 lt minDate lt minDate gt maxDate gt maxDate to 1 in pattern to 1 in pattern to 1 in pattern to 1 in pattern Imprecise Imprecise Imprecise Wednesday Monday Monday Monday Valid on exception Valid on exception Null ull date date Valid on exception Valid on exception Duplicate on exception Duplicate on exception Duplicate on exception Duplicate on exception Added to on and off exceptions Added to on and off exceptions Added to on and off exceptions Added to on and off exceptions Valid but out of sequence TIMESERIES Display tstCall tstCall INTO dummyval 0 ENDAR IsValidCal tstCal1 ORDSYS CALENDAR ValidateCal stCall outMessage r ORDSYS TIM 4 36 Oracle8 Time Series Cartridge U ser s Guide invOnExc invOffExc impOnE
90. 557 maxdate of the target calendar exceeds the maxdate of the ref calendar Cause DeriveExceptions encountered a reference time series calendar having a maxdate less than that of the target time series calendar Action Ensure that DeriveExceptions is called only with appropriate time series TS 00558 the target calendar should have empty on off exception lists Cause DeriveExceptions encountered a target time series calendar having non empty exception lists Action Ensure that DeriveExceptions is called only with target time series having empty exception lists TS 00559 the caltype field in the calendar has an illegal value Cause The Time Series Cartridge encountered a calendar with an invalid cal endar type Action Ensure that all calendars have valid calendar type value Valid calen dar types are Exception driven calendars 0 Error Messages A 7 Error Messages A 8 Oracle8 Time Series Cartridge User s Guide A addition TSAdd function 5 93 TSSum function 5 127 advanced developer demo 1 4 aggregate functions 2 28 architecture Time Series cartridge 2 10 arithmetic functions 2 28 average TSAvg function 5 97 average moving Mavg function 2 29 5 69 bottom values TSMinN function 5 113 bulk loading of time series data 3 10 consistency 2 20 3 10 C calendar 2 5 datatypes 2 7 defining 2 8 exceptions 2 5 frequency 2 6 pattern 2 5 precision 2 7
91. 6 00 00 00 Calendar Functions Reference 4 37 IsValidCal 03 04 1996 00 00 00 05 06 1997 00 00 00 DisplayValCal Your Message TS WRN the input calendar has rectifiable errors S message output by validateCal TS WRN fixed imprecis TS WRN fixed precision of the pattern anchor date TS WRN fixed imprecis TS WRN removed superfluous dates in the on exception list dates in the on exception list TS WRN removed null dates in the on exception list TS WRN sorted the on exceptions list TS WRN removed duplicate dates in the on exceptions list TS WRN removed superfluous dates in off exceptions list dates in the off exception list TS WRN removed null dates in the off exception list TS WRN sorted the off exceptions list TS WRN removed duplicate dates in the off exceptions list list of invalid 01 03 1996 05 27 1996 06 18 1996 list of invalid 12 31 1995 03 30 1996 on exceptions 00 00 00 02 19 1996 00 00 00 01 17 1996 00 00 00 04 23 1996 off exceptions 00 00 00 01 13 1996 00 00 00 list of imprecise on exceptions 03 23 1996 01 01 01 02 18 1996 list of imprecise off exceptions 02 02 1996 01 01 01 03 04 1996 the validated calendar Calendar Name Frequency 4 CALENDAR FOO MinDate 01 01 1975 00 00 00 4 38 Oracle8 Time Series Cartridge User s Guide 00 00 00 00 01 01 00 00 00
92. 8 ExtractTable 5 30 ExtractValue 5 32 Fill 5 34 First 5 40 FirstN 5 42 GetDatedElement 5 44 GetNthElement 5 46 GetOffset 4 20 Index 2 GetSeries 5 48 InsertExceptions 4 23 IntersectCals 4 27 InvalidTimeStampsBetween 4 31 IsValidCal 4 34 IsValidDate 4 40 IsValidTS 5 51 Lag 5 59 Last 5 62 LastN 5 64 Lead 5 66 Mavg 5 69 Msum 5 72 NumInvalidTimeStampsBetween 4 43 NumOffExceptions 4 46 NumOnExceptions 4 49 NumTimeStampsBetween 4 52 OffsetDate 4 55 Scaleup 5 74 ScaleupAvg 5 76 ScaleupCount 5 78 ScaleupFirst 5 80 ScaleupLast 5 82 ScaleupMax 5 84 ScaleupMin 5 86 ScaleupSum 5 88 SetPrecision 4 58 time scaling 2 31 5 1 time series 2 23 5 1 TimeStampsBetween 4 61 TrimSeries 5 90 TSAdd 5 93 TSAvg 5 97 TSCount 5 99 TSDivide 5 101 TSMax 5 105 TSMaxN 5 107 TSMedian 5 109 TSMin 5 111 TSMinN 5 113 TSMultiply 5 115 TSProd 5 119 TSStdDev 5 121 TSSubtract 5 123 TSSum 5 127 TSVariance 5 129 UnionCals 4 65 VallidateCal 4 69 VallidateTS 5 131 G GetDatedElement function 5 44 GetNthElement function 5 46 GetOffset function 4 20 GetSeries function 5 48 H highest values TSMaxN 5 107 incremental loading of time series data 3 12 InsertExceptions function 4 23 installation of the cartridge 1 3 instance based interface 2 13 INSTEAD OF triggers 3 4 IntersectCals function 4 27 InvalidTimeStampsBetween function 4 31 irregular time
93. 8 1996 1 14 1996 2 24 1996 1 14 1996 1 17 1996 4 23 1996 05 04 1997 offExceptions 02 03 1969 2 17 1999 2 24 1996 3 04 1996 O O AS O Se SS O oy O OS 0 0 00 ECF ses DE SOS DE gt AS Re a E 3 04 1996 0 DisplayValCal Your Message TS WRN the input calendar has rectifiable errors S 0 0 0 0 00 00 00 01 00 00 00 00 00 00 00 00 00 01 00 996 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 02 15 1969 01 03 1996 05 27 1996 05 26 1996 03 23 1996 02 24 1996 05 28 1996 01 06 1996 02 14 1969 12 31 1995 03 30 1996 04 05 1996 02 12 1996 03 25 1996 00 00 00 00 00 00 01 00 00 00 00 00 00 00 02 00 00 00 00 01 00 00 00 00 00 00 00 02 00 00 00 00 01 00 00 00 00 00 00 00 02 00 01 17 1996 00 00 00 04 23 1996 00 00 00 05 06 1997 00 00 00 message output by validateCal TS WRN fixed precision of the pattern anchor date 4 14 Oracle8 Time Series Cartridge User s Guide 02 13 1999 00 00 00 02 19 1996 00 00 00 03 23 1996 01 01 01 01 13 1996 00 00 00 01 13 1996 00 00 00 03 23 1996 00 00 00 06 18 1996 00 00 00 02 03 1996 00 00 00 02 03 1999 00 00 00 01 13 1996 00 00 00 02 02 1996 01 01 01 03 25 1996 00 00 00 04 30 1996 00 00 00 05 28 1996 00 00 00 02 02 1996 00 00 00 the message f
94. 9 29 NOV 96 59 20 rows selected 5 8 Oracle8 Time Series Cartridge User s Guide Cprod Cprod Format Description Parameters Usage ORDSYS TimeSeries Cprod ts ORDSYS ORDTNumSeries OTRef stariDate DATE endDate DATE RETURN ORDSYS ORDTNumSeries Given a time series returns an ORDTNumeSeries with each element containing the cumulative product of multiplication up to and including the corresponding ele ment in the input ORDTNumSeries ts The input time series startDate Starting date within the time series for which the cumulative product is to be com puted If startDate is specified endDate must also be specified endDate Ending date within the time series for which the cumulative product is to be com puted If endDate is specified startDate must also be specified Only non null values are considered in computing the cumulative product An exception is returned if any of the following conditions is true a The time series ts is null a The time series ts does not have an associated calendar a endDate is earlier than startDate Time Series and Time Scaling Functions Reference 5 9 Cprod If startDate and endDate are specified the time series is trimmed to the date range before the cumulative product is computed Example Return the cumulative product of the daily volume of stock ACME for the first four trading days of November 1996 This example is presented merely to illustrate
95. 996 00 00 00 05 08 1996 00 00 00 06 25 1996 00 00 00 07 09 1996 00 00 00 OffsetDate 03 03 1996 00 00 00 20 03 29 1996 00 00 00 OffsetDate 03 03 1996 00 00 00 20 Calendar Functions Reference 4 57 02 05 1996 00 00 00 SetPrecision SetPrecision Format Description Parameters Usage ORDSYS Calendar SetPrecision timestamp IN DATE frequency IN INTEGER RETURN DATE Given a timestamp and a frequency returns a timestamp that reflects the level of precision implied by the frequency timestamp Timestamp whose precision is to be set frequency Frequency to be applied in setting the precision The returned timestamp reflects the precision implied by the frequency as explained in Section 2 2 1 For example if the input timestamp is 29 Dec 1997 12 45 00 and frequency is 6 month the returned timestamp is 01 Dec 1997 00 00 00 Table 4 1 shows the frequencies their precision conventions and the resulting pre cision if an input timestamp of 19 Sep 1997 09 09 09 is supplied Table 4 1 SetPrecision and Timestamp of 19 Sep 1997 09 09 09 Frequency Every Precision Convention Result second MM DD YYYY HH24 MI SS 09 19 1997 09 09 09 minute MM DD YYYY HH24 MI 00 09 19 1997 09 09 00 4 58 Oracle8 Time Series Cartridge User s Guide SetPrecision Example Table 4 1 SetPrecision and Timestamp of 19 Sep 1997 09 09 09 Cont Frequency Every Precision Convention Result hour MM D
96. AR Supplement are commercial computer software and use duplication and disclosure of the Programs shall be subject to the licensing restrictions set forth in the applicable Oracle license agreement Otherwise Programs delivered subject to the Federal Acquisition Regulations are restricted computer software and use duplication and disclo sure of the Programs shall be subject to the restrictions in FAR 52 227 14 Rights in Data General including Alternate III June 1987 Oracle Corporation 500 Oracle Parkway Redwood City CA 94065 Oracle SQL Loader and SQL Plus are registered trademarks and Developer 2000 Net8 Network Computing Architecture Oracle Forms Oracle8 and PL SQL are trademarks of Oracle Corporation Redwood City California All other company or product names are used for identification purposes only and may be trademarks of their respec tive owners Contents Send US Your Comments ooo cccccccccccccccccesscssscscececsesccscscscsesusscscsesesucecsceseseusacanssecarsnsesesecsescanseees xi Bo e Ant AA AA REC TER UE AA AE EYP Se RT EE xiii 1 Introduction 1 1 Data Cartrid S68 iia ida 1 1 1 2 Object Relational Technology iiiaae anias 1 2 1 3 Storing arid Accessing Data v cicccscssieessctecsdcastes an neay ein rei reaa ol ia aSa 1 2 1 4 Installing th Kia AA A EER eth A RO AA 1 3 1 5 Creating Public Synonyms for Time Series Packages ocicicionononnnnmmmmmmss 1 4 1 6 Time Series Cartridge Demo
97. Action Use a positive number to specify the number of rows requested A 4 Oracle8 Time Series Cartridge User s Guide Error Messages TS 00535 the time series ref has a null table_name parameter Cause The Time Series Cartridge has encountered a time series ref having a null table_name Action Ensure that all time series refs include a valid table name TS 00536 the time series ref has a null tstamp_colname parameter Cause The Time Series Cartridge has encountered a time series ref having a null tstamp_colname Action Ensure that all time series refs include a valid timestamp column name TS 00537 the time series ref has a null value_colname parameter Cause The Time Series Cartridge has encountered a time series ref having a null value_colname Action Ensure that all time series refs include a valid value column name TS 00538 the time series ref has a null qualifier_colname parameter Cause The Time Series Cartridge has encountered a time series ref having a null qualifier_colname Action Ensure that all time series refs include a valid qualifier column name TS 00539 the time series ref has a null qualifier_value parameter Cause The Time Series Cartridge has encountered a time series ref having a null qualifier_value Action Ensure that all time series refs include a valid qualifier value TS 00540 the projected lead timestamp is beyond the calendar mindate max date Cause The given parameters r
98. Cal2 DBMS_OUTPUT PUT_LINE EqualCals GENERIC CAL1 GENERIC CAL2 equalFlag END This example might display the following output In this example the returned value of 0 indicates that the calendars are not equal Calendar Name GENERIC CAL1 4 18 Oracle8 Time Series Cartridge User s Guide EqualCals Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1996 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions 01 21 1996 00 00 00 02 03 1996 00 00 00 03 24 1996 00 00 00 04 27 1996 00 00 00 05 19 1996 00 00 00 06 23 1996 00 00 00 07 07 1996 00 00 00 08 04 1996 00 00 00 09 15 1996 00 00 00 offExceptions 01 08 1996 00 00 00 02 02 1996 00 00 00 03 05 1996 00 00 00 04 04 1996 00 00 00 05 08 1996 00 00 00 06 25 1996 00 00 00 07 09 1996 00 00 00 Calendar Name GENERIC CAL2 Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1997 00 00 00 patBits 1111100 patAnchor 01 08 1996 00 00 00 onExceptions 07 07 1996 00 00 00 08 04 1996 00 00 00 09 15 1996 00 00 00 10 13 1996 00 00 00 11 10 1996 00 00 00 12 14 1996 00 00 00 01 04 1997 00 00 00 02 09 1997 00 00 00 03 08 1997 00 00 00 04 05 1997 00 00 00 05 11 1997 00 00 00 06 08 1997 00 00 00 offExceptions 07 09 1996 00 00 00 08 05 1996 00 00 00 09 10 1996 00 00 00 10 23 1996 00 00 00 11 19 1996 00 00 00 12 12 1996 00 00 00 01 01 1997 00 00 00
99. D YYYY HH24 00 00 09 19 1997 09 00 00 day MM DD YYYY 00 00 00 09 19 1997 00 00 00 midnight month MM 01 YYYY 00 00 00 09 01 1997 00 00 00 midnight of first day of month year 01 01 YYYY 00 00 00 midnight 01 01 1997 00 00 00 of first day of year If the frequency value is not valid an exception is raised Set the precision of an imprecise timestamp here a timestamp containing hour minute and second values where the calendar has a day frequency CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON ALTER SESSION SET NLS _DATE FORMAT MM DD YYYY HH24 MI SS DECLARE tstCal ORDSYS ORDTCalendar tstDatel DATE resultDate date dummyVal INTEGER relOffset INTEGER BEGIN Select a calendar say GENERIC CAL1 into tstCal from stockdemo_calendars SELECT value cal INTO tstCal FROM ORDTIDEV stockdemo_calendars cal WHERE cal name GENERIC CAL1 Display the calendar SELECT ORDSYS TimeSeries Display tstCal INTO dummyVal FROM dual DBMS_OUTPUT NEW_LINE Set the precision of an imprecise date Calendar Functions Reference 4 59 SetPrecision tstDatel TO_DATE 03 03 1996 01 01 01 resultDate ORDSYS Calendar SetPrecision tstDatel tstCal frequency DBMS_OUTPUT PUT_LINE SetPrecision TO_CHAR tstDatel tstCal frequency 7 I TO_CHAR resultDate
100. DEC 96 57 10 DEC 96 60 875 11 DEC 96 59 625 12 DEC 96 99 15 13 DEC 96 54 875 16 DEC 96 55 625 17 DEC 96 5825 18 DEC 96 54 375 19 DEC 96 53 875 20 DEC 96 53 375 23 DEC 96 54 375 24 DEC 96 53 5 26 DEC 96 54 375 30 DEC 96 54 125 31 DEC 96 52 875 5 92 Oracle8 Time Series Cartridge User s Guide 01 APR 94 04 JUL 94 26 DEC 94 14 APR 95 04 SEP 95 01 JAN 96 2717 MAY 96 17 OCT 96 27 DEC 96 TSAdd TSAdd Format Description Parameters ORDSYS TimeSeries TSAdd ts1 ORDSYS ORDTNumSerieslOTRef ts2 ORDSYS ORDTNumsSerieslOTRef startDate DATE endDate DATE RETURN ORDSYS ORDTNumSeries or ORDSYS TimeSeries TSAdd ts1 ORDSYS ORDTNumSerieslOTRef k NUMBER startDate DATE endDate DATE RETURN ORDSYS ORDTNumSeries Given two input time series or a time series and a constant and optionally starting and ending dates returns a time series that reflects the addition of the first two parameters ts1 The time series or first time series whose elements are to be added either to corre sponding elements in the second time series or to a constant ts2 The time series whose elements are to be added to corresponding elements in the first time series k A constant to be added to corresponding elements in the first time series Time Series and Time Scaling Functions Reference 5 93 TSAdd startDate Starting date within the time series for which the addition is to be performed If startDate i
101. DateTab impDateTab ES dupDateTab extraDateTab missingDateTab retIsValid retValTS ORDSYS TIMESERIES DisplayValTS retValTS outMesg loDateTab hiDateTab impDateTab dupDateTab extraDateTab missingDateTab DBMS_OUTPUT PUT_LINE Value returned by IsValid DBMS_OUTPUT PU INE Value returned by ValidateTS Testing DisplayValTS END Time Series and Time Scaling Functions Reference 5 135 ValidateTS This example might produce the following output A VALID TIME SE RIE S3 Name ACME Calendar Da Calendar Name open NumSeries ta Frequency 4 01 01 1990 00 00 00 01 01 2001 00 00 00 MinDate MaxDate patBits R 0111110 01 07 1996 00 00 00 patAnchor onExcept ions offExceptions 11 28 1996 00 00 00 Series Data USINI ESS 96 12 25 1996 00 00 00 1996 1996 1996 1996 1996 1996 1996 1996 1996 1996 1996 1996 1996 1996 1996 1996 1996 1996 1996 1996 1996 1996 1996 1996 1996 1996 O O 00 0 0 0 0 0 0 0000 0000000 000 03 OO 00 000 00 00 0 00 00 O S Ov OOO 0 0 o G o o a A Ma A a O e a E gt a E de s O o E o Es es Be O a E e DE gt UE es a JE o OR sr E o JA gt E e E gt E e E e E e DE o A a E 0 00 0 0 0 0 0 O Oo0oo0o0ooooO QA 6 00 OS 0 0 OOOO Oo Oo 0 09 0 00 O O OO OO OO
102. ECT ORDSYS TimeSeries Display tstCal DBMS_OUTPUT NEW_LINE into tstCal INTO dummyVal FROM dual Get the number of off exceptions between 02 FEB 1996 and 07 JUL 1996 tstDatel TO_DATE 02 02 1996 tstDate2 TO_DATE 07 07 1996 result ORDSYS Calendar NumOff END Exceptions tstCal tstDatel tstDate2 DBMS_OUTPUT PUT_LINE NumOf fExceptions tstDatel tstDate2 A result This example might produce the following output As the last line of the output indicates there are five off exceptions in the specified date range 02 Feb 1996 through 07 Jul 1996 Calendar Name GENERIC CAL1 Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1996 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions 01 21 1996 00 00 00 04 27 1996 00 00 00 07 07 1996 00 00 00 offExceptions 02 03 1996 00 00 00 05 19 1996 00 00 00 08 04 1996 00 00 00 03 24 1996 00 00 00 06 23 1996 00 00 00 09 15 1996 00 00 00 Calendar Functions Reference 4 47 NumOffExceptions 01 08 1996 00 00 00 02 02 1996 00 00 00 03 05 1996 00 00 00 04 04 1996 00 00 00 05 08 1996 00 00 00 06 25 1996 00 00 00 07 09 1996 00 00 00 NumOffExcept ions 02 02 1996 00 00 00 07 07 1996 00 00 00 5 4 48 Oracle8 Time Series Cartridge User s Guide NumOnExceptions NumOnExceptions Format Descripti
103. ER SESSION SET NLS_DATE_ FORMAT MM DD YYYY HH24 MI SS DECLARE 5 26 Oracle8 Time Series Cartridge User s Guide ExtractCal dummyval INTEGER BEGIN SELECT ORDSYS TimeSeries Display ORDSYS TimeSeries ExtractCal ts open FROM ORDTIDEV stockdemo_ts ts WHERE ts ticker ACME END ExtractCal Results INTO dummyval This example might produce the following output ExtractCal Results Calendar Name Frequency 4 MinDate MaxDate patBits 0111110 patAnchor onExcept ions offExceptions 11 28 1996 00 00 00 BUSINESS 96 01 01 1990 00 00 00 01 01 2001 00 00 00 01 07 1996 00 00 00 12 25 1996 00 00 00 Time Series and Time Scaling Functions Reference 5 27 ExtractDate ExtractDate Format ORDSYS TimeSeries ExtractDate cell ORDSYS ORDTNumCell RETURN DATE or ORDSYS TimeSeries ExtractDate cell ORDSYS ORDTVarchar2Cell RETURN DATE Description Given an element in a time series returns the date Parameters cell The time series element for which you want the date Usage The time series element must first be identified such as by using the GetNthEle ment function An exception is returned if the time series element cell is null Example Return the date associated with the tenth element in a specified time series SELECT to_char ORDSYS TimeSeries ExtractDate ORDSYS TimeSeries GetNth
104. Element open 10 MM DD YYYY HH24 MI SS FROM ORDTDEV stocks_ts WHERE ticker AONE This example might produce the following output 5 28 Oracle8 Time Series Cartridge User s Guide ExtractDate TO_CHAR ORDSYS TIME 01 15 1990 00 00 00 1 row selected Time Series and Time Scaling Functions Reference 5 29 ExtractTable ExtractTable Format Description Parameters Usage Example ORDSYS TimeSeries ExtractTable ts ORDSYS ORDTNumSeries OT Ref RETURN ORDSYS ORDTNumTab or ORDSYS TimeSeries ExtractTable ts ORDSYS ORDTVarchar2SerieslOTRef RETURN ORDSYS ORDTVarchar2Tab Given a time series returns the time series table ORDTNumTab or ORDTVarchar2Tab associated with the time series ts The input time series The function returns the time series table ORDTNumTab or ORDTVarchar2Tab associated with the time series An exception is returned if the time series ts is null Return the closing prices for stock ACME SELECT FROM the SELECT CAST ORDSYS TimeSeries ExtractTable ts close as ORDSYS ORDTNumTab FROM ORDTDEV stockdemo_ ts ts WHERE ts ticker ACME This example might produce the following output 5 30 Oracle8 Time Series Cartridge User s Guide ExtractTable 01 NOV 96 59 04 NOV 96 60 05 NOV 96 61 31 DEC 96 99 41 rows selected Time Series and Time Scaling Functions Reference 5 31 ExtractVa
105. HERE ts ticker SAMCO and sc name QUARTERLY This example might produce the following output TSTAMP VALUE 01 JUL 96 64 01 OCT 96 64 2 rows selected Time Series and Time Scaling Functions Reference 5 79 ScaleupFirst ScaleupFirst Format Description Parameters Usage ORDSYS TimeSeries ScaleupFirst ts ORDSYS ORDTNumSerieslOTRef calendar ORDSYS ORDTCalendar stariDate 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 reflecting the first non null value of each scaled group of values ts The input time series calendar The calendar to be used for the scaling startDate The starting date to be used If startDate is specified endDate must also be specified endDate The ending date to be used If endDate is specified startDate must also be specified An exception is returned for any of the following conditions a The input time series the calendar on which the input time series in based or the specified calendar is null 5 80 Oracle8 Time Series Cartridge User s Guide ScaleupFirst Example The frequency of the calendar on which the time series is based is greater than the frequency of the specified calendar for example the time series calendar s frequency is month and the specified calendar s frequenc
106. HH24 MI SS DECLARE 5 124 Oracle8 Time Series Cartridge User s Guide TSSubtract tstCal ORDSYS ORDTCalendar startDate date endDate date dummyval INTEGER BEGIN startDate TO_DATE 11 14 1996 endDate TO_DATE 12 14 1996 SELECT ORDSYS TimeSeries Display ORDSYS TimeSeries TSSubtract ts1 high ts2 low startDate endDate TSSubtract Results INTO dummyval FROM ORDTDEV stockdemo_ts tsl ORDIDEV stockdemo_ts ts2 WHERE tsl ticker ACME and ts2 ticker FUNCO END This example might produce the following output TSSubtract Results Calendar Data Frequency 4 MinDate 01 01 1990 00 00 00 MaxDate 01 01 2001 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions offExceptions 11 28 1996 00 00 00 12 25 1996 00 00 00 Series Data Date Value 11 14 1996 00 00 00 45 13 11 15 1996 00 00 00 46 16 11 18 1996 00 00 00 47 13 11 19 1996 00 00 00 48 15 11 20 1996 00 00 00 49 18 11 21 1996 00 00 00 50 16 11 22 1996 00 00 00 51 15 11 25 1996 00 00 00 52 19 11 26 1996 00 00 00 53 22 11 27 1996 00 00 00 54 29 Time Series and Time Scaling Functions Reference 5 125 TSSubtract 1 29 1996 00 00 00 55 25 2 02 1996 00 00 00 56 12 2 03 1996 00 00 00 56 97 2 04 1996 00 00 00 57 98 2 05 1996 00 00 00 58 87 2 06 1996 00 00 00 60 25 2 09 1996 00 00 00 61 23
107. Imprecise 03 04 1996 01 01 01 Imprecise 04 05 1996 02 02 02 Imprecise 03 25 1996 Valid off exception 01 22 1996 Valid but out of sequence 102 12 1996 104 30 1996 Null date 102 12 1996 Duplicate date within OFFs Null date 04 30 1996 Duplicate off exception Null date 03 25 1996 Duplicate off exception 01 22 1996 Duplicate off exception 01 17 1996 Added to on and off exceptions 05 28 1996 Added to on and off exceptions 06 18 1996 Added to on and off exceptions Calendar Functions Reference 4 35 IsValidCal O DA 04 23 1996 O DA O DA 03 04 1996 O DA E E 02 02 1996 E E 05 06 1997 ORDSYS ORDTExceptions O DA E 02 08 1969 O DA 02 15 1969 O DA 02 13 1999 O DA O DA 01 03 1996 O DA 02 19 1996 O DA 02 20 1999 F F F F F F F O DA 05 27 1996 O DA 03 23 1996 01 F O DA O DA Fl E 02 18 1996 01 05 26 1996 01 E E E E E E 03 18 1996 E E O_DATE E 01 13 1996 F F NULL NULL O DA 01 14 1996 O DA OSDA O DA O DA 01 14 1996 O DA 02 2
108. L extraDateTab ORDSYS ORDTDateTab NULL missingDateTab ORDSYS ORDTDateTab NULL outMesg varchar2 2000 BEGIN Set the buffer siz DBMS_OUTPUT ENABLE 100000 NOTE Here an instance of the time series is materialized so that it could be modified to generate an invalid time series SELECT ORDSYS TIMESERIES GetSeries ts open INTO numTS FROM ordtdev stockdemo_ts ts WHERE ts ticker ACME lt Example of validating a valid time series SELECT ordsys timeseries display numIS A VALID TIME SERIES INTO tempVal FROM dual retIsValid ORDSYS TIMESERIES IsValidTS numTS retValTS ORDSYS TIMESERIES ValidateTS numTS outMesg loDateTab hiDateTab impDateTab dupDateTab extraDateTab missingDateTab DBMS_OUTPUT PUT_LINE Value returned by IsValid retIsValid DBMS_OUTPUT PUT_LINE Value returned by ValidateTS retValTS ORDSYS TIMESERIES DisplayValTS retValTS outMesg loDateTab hiDateTab impDateTab dupDateTab extraDateTab missingDateTab Testing DisplayValTS DBMS_OUTPUT NEW_LINE For illustration let us first create an invalid timeseries Here we are adjusting the calendar s minDate and maxDate to avoid getting a huge list of missing dates 5 134 Oracle8 Time Series Cartridge U
109. November 1996 SELECT FROM the SELECT CAST ORDSYS TimeSeries ExtractTable ORDSYS TimeSeries Cmax ts close to_date 01 NOV 96 DD MON YY to_date 30 NOV 96 DD MON YY AS ORDSYS ORDTNumTab FROM ORDTDEV stockdemo_ ts ts WHERE ts ticker ACME This example might produce the following output Note that this output reflects the simplified artificial data in the usage demo database where the closing price rises one point each day 01 NOV 96 59 04 NOV 96 60 05 NOV 96 61 06 NOV 96 62 07 NOV 96 63 08 NOV 96 64 11 NOV 96 65 12 NOV 96 66 13 NOV 96 67 14 NOV 96 68 15 NOV 96 69 18 NOV 96 70 19 NOV 96 71 20 NOV 96 T2 21 NOV 96 73 22 NOV 96 74 25 NOV 96 75 26 NOV 96 76 27 NOV 96 77 29 NOV 96 78 20 rows selected 5 6 Oracle8 Time Series Cartridge User s Guide Cmin Cmin Format Description Parameters Usage ORDSYS TimeSeries Cmin ts ORDSYS ORDTNumsSerieslOTRef stariDate DATE endDate DATE RETURN ORDSYS ORDTNumSeries Given a time series returns an ORDTNumeSeries with each element containing the cumulative minimum up to and including the corresponding element in the input ORDTNumSeries ts The input time series startDate Starting date within the time series for which the cumulative minimum is to be returned If startDate is specified endDate must also be specified endDate Ending date within th
110. O DA 02 19 1996 O DA 02 20 1999 03 18 1996 O DA O DA O DA O DA E E E E E E E 05 27 1996 E E E O_DATE E 01 13 1996 NULL NULL O DA 01 14 1996 O DA O DA O DA O DA O DA O DA O DA O DA O DA O DA E O DA E O DA E O DA BEGIN E SELECT ORDSYS FROM dual validFlag IF validFlag THE validFlag E ORDSYS CA TIMESERIES Display tstCall 0 03 23 1996 01 02 18 1996 01 05 26 1996 01 Date Date Date Date laps laps laps laps 201 SOLN 701 Valid Valid Valid Valid Added Added Added Valid but out of sequence Duplicate Duplicate Duplicate Duplicate lt minDate lt minDate gt maxDate gt maxDate to 1 to to to in pattern in pattern in pattern Imprecise Imprecise Imprecise on exception on exception Null date Null date on exception on exception on except ion on except ion on except ion on except ion Wednesday 1N Monday 1 in pattern Monday al Monday to on and off exceptions to on and off exceptions Added to on and off exceptions to on and off exceptions tstCall ENDAR IsValidCal tstCall1 ORDSYS CALENDAR ValidateCal stCall r
111. OO Ome 5 136 Oracle8 Time Series Cartridge User s Guide ValidateTS 12 10 1996 00 00 00 85 2 11 1996 00 00 00 86 2 12 1996 00 00 00 87 2 13 1996 00 00 00 88 2 16 1996 00 00 00 89 2 17 1996 00 00 00 90 2 18 1996 00 00 00 91 2 19 1996 00 00 00 92 2 20 1996 00 00 00 93 2 23 1996 00 00 00 94 2 24 1996 00 00 00 95 2 26 1996 00 00 00 96 2 27 1996 00 00 00 97 2 30 1996 00 00 00 98 2 31 1996 00 00 00 99 Value returned by IsValid 1 Value returned by ValidateTS 1 DisplayValTS Testing DisplayValTS TS SUC the input time series is a valid time series AN INVALID TIME SERIES Name ACME open NumSeries Calendar Data Calendar Name BUSINESS 96 Frequency 4 MinDate 10 28 1996 00 00 00 MaxDate 01 05 1997 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExceptions offExceptions 11 28 1996 00 00 00 12 25 1996 00 00 00 Series Data Date Value 11 01 1996 00 00 00 59 11 04 1996 00 00 00 60 11 05 1996 00 00 00 61 Time Series and Time Scaling Functions Reference 5 137 ValidateTS 11 06 1996 00 00 00 62 11 07 1996 00 00 00 63 11 08 1996 00 00 00 64 11 11 1996 00 00 00 65 11 12 1996 00 00 00 66 11 13 1996 00 00 00 67 10 27 1996 00 00 00 68 10 26 1996 00 00 00 69 01 06 1997 00 00 00 70 01 07 1997 00 00 00 71 72 73 22 1996 00 00 00 74 22 1996 01 00 00 75 22 1996 15 00 00 76 22 1996 15 00 00 77 29 1996 0
112. OOO O O 000 GO DO ES AAN YE D eo UL o E O Om 00 00 00 00 00 00 00 00 00 00 OOOO O O O O Qo GO S O OO Calendar Functions Reference 4 67 UnionCals patAnchor 01 08 1996 00 00 00 onExcept ions 01 21 1996 00 00 00 04 27 1996 00 00 00 07 07 1996 00 00 00 10 13 1996 00 00 00 offExceptions 07 09 1996 00 00 00 4 68 Oracle8 Time Series Cartridge User s Guide 02 03 1996 00 00 00 05 19 1996 00 00 00 08 04 1996 00 00 00 11 10 1996 00 00 00 03 24 1996 00 00 00 06 23 1996 00 00 00 09 15 1996 00 00 00 12 14 1996 00 00 00 ValidateCal ValidateCal Format Description Parameters ORDSYS Calendar ValidateCal cal INOUT ORDSYS ORDT Calendar outMessage OUT VARCHAR2 invOnExc OUT ORDTDateTab invOffExc OUT ORDTDateTab impOnExc OUT ORDTDateTab impOffExc OUT ORDTDateTab RETURN BINARY_INTEGER Validates a calendar and if necessary repairs the calendar and outputs information related to the problems and repairs cal The calendar to be validated and if necessary repaired outMessage Message describing how the calendar was repaired if the return value 1 or why the calendar could not be repaired if the return value 1 invOnExc Table of the invalid on exceptions found in the calendar invOffExc Table of the invalid off exceptions found in the calendar impOnExc Table of the imprecise on exceptions found in the calendar Calen
113. OUTPUT routines ts The object to be displayed Because the function is overloaded this parameter can be any of the following datatypes a ORDTNumSeriesIOTRef or ORDTNumSeries a ORDTVarchar2SeriesIOTRef or ORDTVarcharSeries a ORDTNumTab a ORDTVarchar2Tab a ORDTNumCell a ORDTVarchar2Cell a ORDTDateTab a ORDTCalendar a ORDTExceptions a ORDTPattern mesg Optional message text to be included in the display heading Timeseries dump for lt mesg gt Time Series and Time Scaling Functions Reference 5 15 Display Usage Use the SET SERVEROUTPUT ON statement to view the output of the Display function However the default display buffer of 2000 bytes is often too small to dis play a large time series In such cases you must use the ENABLE procedure of the DBMS_OUTPUT package to specify a larger display buffer size For example DBMS_OUTPUT ENABLE 1000000 You should use Display only for development and debugging Specify a display buffer larger than 2000 only when necessary because the display buffer uses shared system resources and a large value might affect the performance of other users Because the Display function uses DBMS_OUTPUT routines it is subject to the limi tations of these routines These limitations include the following Output cannot exceed 1 megabyte a The Display function cannot be used with the OCI SQL Plus does not support DBMS_OUTPUT in the context of a SELECT
114. Oracle8 Time Series Cartridge User s Guide Release 8 0 4 November 1997 Part No A57501 01 ORACLE Enabling the Information Age Oracle8 Time Series Cartridge User s Guide Part No A57501 01 Release 8 0 4 Copyright 1997 Oracle Corporation All rights reserved The programs are not intended for use in any nuclear aviation mass transit medical or other inher ently dangerous applications It shall be licensee s responsibility to take all appropriate fail safe back up redundancy and other measures to ensure the safe use of such applications if the Programs are used for such purposes and Oracle disclaims liability for any damages caused by such use of the Pro grams This Program contains proprietary information of Oracle Corporation it is provided under a license agreement containing restrictions on use and disclosure and is also protected by copyright patent and other intellectual property law Reverse engineering of the software is prohibited The information contained in this document is subject to change without notice If you find any problems in the documentation please report them to us in writing Oracle Corporation does not warrant that this document is error free If this Program is delivered to a U S Government Agency of the Department of Defense then it is deliv ered with Restricted Rights and the following legend is applicable Restricted Rights Legend Programs delivered subject to the DOD F
115. Reference 5 103 TSDivide 1 27 1996 00 00 00 3 1 29 1996 00 00 00 3 2 02 1996 00 00 00 3 2 03 1996 00 00 00 3 2 04 1996 00 00 00 3 2 05 1996 00 00 00 3 2 06 1996 00 00 00 3 2 09 1996 00 00 00 3 2 10 1996 00 00 00 3 2 11 1996 00 00 00 3 2 12 1996 00 00 00 3 2 13 1996 00 00 00 3 2897511598481 6533108393083087304934627 3263157894 7368421052631578947368421053 35008375209380234505862646566164154104 37078651685393258426966292134831460674 41382181515403830141548709408825978351 43970161624533775383340240364691255698 53684210526315789473684210526315789474 57593605384938998737904922170803533866 61344537815126050420168067226890756303 70212765957446808510638297872340425532 115907731738573259290901324220418624519 8034188034188034188034188034188034188 5 104 Oracle8 Time Series Cartridge User s Guide TSMax TSMax Format Description Parameters Usage Example ORDSYS TimeSeries TSMax ts ORDSYS ORDTNumSeries OT Ref startDate DATE endDate DATE RETURN NUMBER Given an input ORDTNumSeries and optionally starting and ending dates returns a number corresponding to the highest maximum of all non null time series entries ts The input time series startDate Starting date within the time series for which the maximum is to be calculated If startDate is specified endDate must also be specified endDate Ending date within the time series for which the maximum is to be calculated
116. S ORDTExceptions TO_DATE 28 NOV 1996 DD MON YYYY TO_DATE 25 DEC 1996 DD MON YYYY ORDSYS ORDTExceptions Notes on Example 2 1 The stockdemo_calendars table has rows of type ORDTCalendar which is described in Section 2 2 2 0 indicates that this is an exception based calendar the only type of calendar currently supported 8 BusinessDays is the name of this calendar 2 8 Oracle8 Time Series Cartridge User s Guide Calendars 4 is the frequency code for day The calendar s pattern consists of an excluded occurrence followed by five included occurrences followed by an excluded occurrence 0 1 1 1 1 1 0 Because the frequency is daily and because the anchor date 01 Jan 1995 is a Sunday Sundays are excluded Mondays through Fridays are included and Saturdays are excluded O The calendar begins at the start of 01 Jan 1990 and ends at the start of 01 Jan 2001 28 Nov 1996 and 25 Dec 1996 are off exceptions that is excluded from the cal 18 endar Note All exceptions off and on must be specified in ascending sorted order ORDSYS ORDTExceptions indicates that there are no on exceptions that is no Saturday or Sunday dates to be included in the calendar 2 2 4 Deriving Calendar Exceptions from Time Series Data When you want to create calendars that conform to time series data you can use the DeriveExceptions function to sim
117. S TimeSeries Display tstCal INTO dummyVal FROM dual DBMS_OUTPUT NEW_LINE Get all the valid timestamps between 03 MAR 1996 and 03 JUN 1996 tstDatel TO_DATE 03 03 1996 tstDate2 TO_DATE 06 03 1996 resultDTab ORDSYS Calendar TimeStampsBetween tstCal tstDatel tstDate2 SELECT ORDSYS TimeSeries Display resultDTab Valid timestamps INTO dummyVal FROM dual END 4 62 Oracle8 Time Series Cartridge User s Guide TimeStampsBetween This example might produce the following output Calendar Name GENERIC CAL1 Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1996 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions 01 21 1996 00 00 00 02 03 1996 00 00 00 03 24 1996 00 00 00 04 27 1996 00 00 00 05 19 1996 00 00 00 06 23 1996 00 00 00 07 07 1996 00 00 00 08 04 1996 00 00 00 09 15 1996 00 00 00 offExceptions 01 08 1996 00 00 00 02 02 1996 00 00 00 03 05 1996 00 00 00 04 04 1996 00 00 00 05 08 1996 00 00 00 06 25 1996 00 00 00 07 09 1996 00 00 00 Valid timestamps 03 04 1996 00 00 00 03 06 1996 00 00 00 03 07 1996 00 00 00 03 08 1996 00 00 00 03 11 1996 00 00 00 03 12 1996 00 00 00 03 13 1996 00 00 00 03 14 1996 00 00 00 03 15 1996 00 00 00 03 18 1996 00 00 00 03 19 1996 00 00 00 03 20 1996 00 00 00 03 21 1996 00 00 00 03 22 1996 00 00 00 03 24 1996 00 00 00 03 25 1996 00 00 00 03 26 1996
118. SStdDev close FROM ORDTDEV stockdemo_ts WHERE ticker ACME This example might produce the following output ORDSYS ORD ORDSYS ORD ORDSYS ORD 79 143 5 11 9791486 1 row selected 5 122 Oracle8 Time Series Cartridge User s Guide TSSubtract TSSubtract Format Description Parameters ORDSYS TimeSeries TSSubtract ts1 ORDSYS ORDTNumSerieslOTRef ts2 ORDSYS ORDTNumsSerieslOTRef startDate DATE endDate DATE RETURN ORDSYS ORDTNumSeries or ORDSYS TimeSeries TSSubtract ts1 ORDSYS ORDTNumSerieslOTRef k NUMBER startDate DATE endDate DATE RETURN ORDSYS ORDTNumSeries Given two input time series or a time series and a constant and optionally starting and ending dates returns a time series that reflects the subtraction of the second parameter from the first parameter ts1 The time series or first time series whose elements are to be decreased either by corresponding elements in the second time series or by a constant ts2 The time series whose elements are to be subtracted from corresponding elements in the first time series k A constant to be subtracted from corresponding elements in the first time series Time Series and Time Scaling Functions Reference 5 123 TSSubtract Usage Example startDate Starting date within the time series for which the subtraction is to be performed If startDate is specified endDate must also be specified endDate Ending date wit
119. SYS Calendar NumOffExceptions inputCal IN ORDSYS ORDTCalendar startDate IN DATE endDate IN DATE RETURN INTEGER Description Given starting and ending input timestamps returns the number of off exceptions within that range according to the specified calendar Parameters inputCal The calendar to be used in computing the number of off exceptions startDate Starting date in the range to be checked for off exceptions endDate Ending date in the range to be checked for off exceptions Usage startDate and endDate are included in the check for off exceptions For an explana tion of off exceptions and on exceptions see Section 2 2 If startDate is greater later than endDate an exception is raised Example Return the number of off exceptions between 02 Feb 1996 and 07 Jul 1996 in the GENERIC CAL calendar CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON ALTER SESSION SET NLS DATE FORMAT MM DD YYYY HH24 MI SS 4 46 Oracle8 Time Series Cartridge User s Guide NumOffExceptions DECLARE tstCal ORDSYS ORDTCalendar tstDatel DATE tstDate2 DATE result INTEGER dummyVal INTEGER BEGIN Select a calendar say GENERIC CAL1 from stockdemo_calendars SELECT value cal INTO tstCal FROM ORDTIDEV stockdemo_calendars cal WHERE cal name GENERIC CAL1 Display the calendar SEL
120. abad 3 1 3 2 Create a Calendar of Business Days ooooncicicncnonononnnnnncnnnnoronnncononnoronnnnonno raro rnn nara ro ran cn nanara 3 3 3 3 Greate a Sectitity Vie Winidiasiioibda nada diia idas ibas 3 4 3 4 Create an INSTEAD OE Trier rinitis dnd dd tias 3 4 3 5 Create a Reference Based View ccccccssssssssessecesseesscesssessscesseceseecsseecssessseceaeceseecesseeaseceseeens 3 6 3 6 Formulate Time Series Queries cccccccessesssessesceeecesceesecseessecssesseceesessesecseseeseeeseeseseeeeeenees 3 7 viii Figures 1 1 Tables and Views in the Time Series Usage DeMO cococococicinonononcnnononinnnnnononanananononananananons 1 7 2 1 Data Generation in Equities Markets ooocicicicinonininnonnnencnnonononcnnncnanonanancnononon anar ononanarananons 2 3 2 2 Historical Data for Stocks iia air acotada iaa dois ada cotizados 2 4 2 3 Time Series Architecture ccccccccccsscessecescccssscsscessecessscesseceseeessessncecsscesseceseecsascnseeceeeeens 2 11 2 4 Example of ORDTNumTab Collection Type ccocoicicinononononnmmrncccacncrccanacincnoss 2 14 2 5 Relationship of Input and Output Time Series in Moving Average Sum 004 2 30 2 6 Time Scaling from Daily to Monthly Frequency ocococococoninnnnnnnencnnononionininnaninancnananoconanons 2 31 Tables 1 1 Time Series Cartridge DEMOS siccici icia cian cdta let 1 4 1 2 Time Series Cartridge Usage Demo FileS connnnonconinnnnocnnocnnionacan cnn nonnnrnn nora nor anno ncnnn no
121. acceptable for a null pat anchor The anchor can be null only when using all zero or all one pattern bits Action Supply a pattern anchor date or adjust the pattern bits TS 00504 illegal validflag parameter was passed to Display ValCal Display ValTS Cause DisplayValCal or DisplayValTS was called with invalid parameters Action Only call DisplayValCal and DisplayValTS with the output of Vali dateCal or ValidateTS respectively TS 00505 illegal outmessage parameter was passed to Display ValCal Display ValTS Cause DisplayValCal or DisplayValTS was called with invalid parameters Action Only call DisplayValCal and DisplayValTS with the output of Vali dateCal or ValidateTS respectively Error Messages A 1 Error Messages TS 00506 the calendar pattern is null Cause The Time Series Cartridge encountered a calendar having a null pat tern Action Ensure that all calendars have a non null pattern TS 00507 the calendar has an imprecise mindate or maxdate Cause The Time Series Cartridge encountered a calendar having an imprecise mindate or maxdate Action Ensure that all calendar mindates and maxdates are precise TS 00510 datetab has dates outside the bounds of the calendar Cause DeriveExceptions encountered dates outside of the input calendar s mindate maxdate Action Adjust mindate maxdate or remove extraneous dates from the input DateTab TS 00511 calendar pattern bits array is ei
122. ace The Time Series cartridge provides a reference based interface for time series and time scaling functions This interface provides efficient performance especially when only a portion of the time series is accessed The performance benefit of this interface results from the fact that at runtime the reference based interface materializes only those rows within the specified date range as opposed to materializing the entire collection of rows from the time series The reference based interface uses the ORDTNumSeriesIOTRef and ORDTVarchar2SeriesIOTRef types which include a REF to a calendar plus several literal values At runtime reference based time series functions use these literal val ues to form and execute a SQL statement using dynamic SQL that derives an instance of a time series that contains only the timestamps needed for this instance The time series function determines which timestamps are needed based on the minDate and maxDate parameters to the function The ORDTNumSeriesIOTRef type is defined as follows CREATE TYPE ORDSYS ORDTNumSeriesIOTRef AS OBJECT name VARCHAR2 256 cal REF ORDSYS ORDTCalendar table_name VARCHAR2 256 tstamp_colname VARCHARZ2 30 value_colname VARCHAR2 30 qualifier_colname VARCHARZ2 30 Time Series Concepts 2 15 Interfaces to Time Series and Time Scaling Functions qualifier_value VARCHAR2 4000 The attributes of the ORDTNumSeriesIOTRef type are as
123. al DBMS_OUTPUT NEW_LINE into tstCal INTO dummyVal FROM dual Get the number of ON Exceptions between 02 FEB 1996 and 07 JUL 1996 tstDatel TO_DATE 02 02 1996 tstDate2 TO_DATE 07 07 1996 result END ORDSYS Calendar NumOnExceptions tstCal tstDatel tstDate2 DBMS_OUTPUT PUT_LINE NumOnExceptions tstDatel tstDate2 7 result This example might produce the following output As the last line of the output indicates there are six on exceptions in the specified date range 02 Feb 1996 through 07 Jul 1996 Calendar Name GENERIC CAL1 Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1996 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExceptions 01 21 1996 00 00 00 04 27 1996 00 00 00 07 07 1996 00 00 00 4 50 Oracle8 Time Series Cartridge User s Guide 02 03 1996 00 00 00 05 19 1996 00 00 00 08 04 1996 00 00 00 03 24 1996 00 00 00 06 23 1996 00 00 00 09 15 1996 00 00 00 NumOnExceptions offExceptions 01 08 1996 00 00 00 02 02 1996 00 00 00 03 05 1996 00 00 00 04 04 1996 00 00 00 05 08 1996 00 00 00 06 25 1996 00 00 00 07 09 1996 00 00 00 NumOnExceptions 02 02 1996 00 00 00 07 07 1996 00 00 00 6 Calendar Functions Reference 4 51 NumTimeStampsBetween NumTimeStampsBetween Format Description Parameters Usa
124. alid timestamps endDate Ending date in the range to be checked for invalid timestamps A timestamp is invalid if any of the following conditions is true It is outside the date range of the calendar a Itis an off exception in the calendar a Itis imprecise for example a timestamp of 02 Jul 1997 if the calendar fre quency is month a Itisnull startDate and endDate are included in the check for invalid timestamps Calendar Functions Reference 4 31 InvalidTimeStampsBetween If there are no invalid timestamps in the date range the function returns an empty ORDTDateTab If startDate is greater later than endDate an exception is raised Contrast this function with TimeStampsBetween which returns a table containing the valid timestamps in a date range Example Return a table of invalid timestamps between 03 Mar 1996 and 03 Jun 1996 in the GENERIC CAL1 calendar CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE FORMAT MM DD YYYY HH24 MI SS DECLARE tstCal ORDSYS ORDICalendar tstDatel DATE tstDate2 DAT resultDTab ORDSYS ordtDateTab dummyVal INTEGER relOffset INTEGER CI GI se BEGIN Select a calendar say GENERIC CAL1 into tstCal from stockdemo_calendars SELECT value cal INTO tstCal FROM ORDTIDEV stockdemo_calendars cal WHERE cal name GENERIC CAL1
125. an invalid calendar CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON 4 34 Oracle8 Time Series Cartridge User s Guide IsValidCal ALTER SES SION SET NLS_DATE FORMAT MM DD YYYY HH24 MI SS DECLARE outMessag invOnExc invOffE impOnExc impOf f dummyval validFlag tstCall TO_DATI CA e varchar2 32750 ORDSYS ORDTDateTab ORDSYS ORDTDateTab ORDSYS ORDTDateTab ORDSYS ORDTDateTab integer integer ORDSYS ORDTCalendar ORDSYS ORDTCalendar 701 01 1 O_DATE O_DATE O_DATE O_DATE O_DA O_DA O_DA O_DATE O_DATE O_DATE O_DATE O_DATE O_DATE O_DATE NULL O_DATE NULL O_DATE NULL O_DATE O_DATE O_DATE O_DATE O_DATE O_DATE 0 CALENDAR FOO 4 ORDSYS ORDTPattern ORDSYS ORDTPatternBits 1 1 1 1 1 0 0 TO_DATE 01 08 1996 01 01 01 TO_DATE 01 01 1975 999 ORDSYS ORDTExceptions 02 03 1969 Date lt minDate 02 14 1969 Date lt minDate 102 03 1999 Date gt maxDate 02 17 1999 Date gt maxDate 112 31 1995 Maps to 0 in pattern Sunday 01 13 1996 Maps to 0 in pattern Saturday 02 24 1996 Maps to 0 in pattern Saturday 03 30 1996 Maps to 0 in pattern Saturday 02 02 1996 01 01 01
126. an startDate Example Return a table of 10 day moving average values of the closing price for stock ACME for the month of December 1996 SELECT FROM the SELECT CAST ORDSYS TimeSeries ExtractTable ORDSYS TimeSeries Mavg ts close to_date 02 DEC 96 DD MON YY to_date 31 DEC 96 DD MON YyY 10 AS ORDSYS ORDTNumTab FROM ORDTDEV stockdemo_ts ts WHERE ts ticker ACME This example might produce the following output TSTAMP VALUE 02 DEC 96 74 5 03 DEC 96 75 5 04 DEC 96 76 5 05 DEC 96 77 5 06 DEC 96 78 5 09 DEC 96 79 5 10 DEC 96 80 5 11 DEC 96 SLS 12 DEC 96 82 5 13 DEC 96 83 5 5 70 Oracle8 Time Series Cartridge User s Guide Mavg 16 DEC 96 17 DEC 96 18 DEC 96 19 DEC 96 20 DEC 96 23 DEC 96 24 DEC 96 26 DEC 96 27 DEC 96 30 DEC 96 31 DEC 96 84 85 86 87 88 89 90 91 92 93 94 21 rows selected SVRMGR gt 090 aa aa a U Time Series and Time Scaling Functions Reference 5 71 Msum Msum Format Description Parameters ORDSYS TimeSeries Msum ts ORDSYS ORDTNumSerieslOTRef startDate DATE endDate DATE k INTEGER RETURN ORDSYS ORDTNumSeries Given an input ORDTNumSeries returns a moving sum for the time series or for the date range if one is specified Each value in the returned time series is the sum of the value for the current timestamp plus the value for each of the previous spe
127. and off exceptions are populated based on the calen dar pattern and the table of dates as follows a All timestamps that are in the calendar pattern but not in the table of dates become off exceptions For example 04 Jul 1997 Friday is in the pattern of a stock trading calendar but it is not a date on which U S stocks were traded a All timestamps that are in the table of dates but are not in the calendar pattern become on exceptions The following example derives the exceptions for all time series in the stockdemo table and updates the corresponding calendars in the stockdemo_calendars table UPDATE stockdemo_calendars cal SET cal SELECT ORDSYS Calendar DeriveExceptions VALUE cal CAST multiset SELECT s tstamp FROM stockdemo s WHERE cal name s ticker AS ORDSYS ORDTDateTab FROM dual This approach Approach 1 to deriving calendar exceptions has the following requirements a The input table of dates must be sorted in ascending timestamp order before the call to the DeriveExceptions function a The precision of the timestamps of the dates in the table must conform to the frequency of the input calendar 3 3 2 Deriving Exceptions Using Two Time Series Parameters Approach 2 The second approach to deriving exceptions takes two time series references as input parameters using the following form of the function DeriveExceptions series1 ORDTNumsSerieslOTRef
128. ange of the current time series but they are not currently in the time series 2 30 Oracle8 Time Series Cartridge User s Guide Time Scaling Functions Table 2 13 Conversion Functions Function Description Fill Fills a time series based on the calendar and fill type 2 9 Time Scaling Functions The Time Series cartridge provides functions to scale up time series data Scaleup functions produce summary information from finer granularity information for example monthly data based on daily data Scaleup is also known as rollup The relationship between the input and output time series in a scaleup operation is illustrated in Figure 2 6 which shows a mapping when scaling from a daily fre quency to a monthly frequency Figure 2 6 Time Scaling from Daily to Monthly Frequency 1 FEB 97 1 MAR 97 123 28 NU 3693A RA Figure 2 6 shows all days in February being mapped to the month of February This mapping also suggests the importance of the precision of timestamps of differ ent frequencies In the example shown in this figure The month timestamp for February 1997 is represented as 1 FEB 97 00 00 00 a The day timestamps for February 1997 are represented as 1 FEB 97 00 00 00 2 FEB 97 00 00 00 28 FEB 97 00 00 00 Time Series Concepts 2 31 Time Scaling Functions Note Scaledown functions are not included in the initial release but they are planned for a future release Scaledown functions gen er
129. ar SELECT ORDSYS TimeSeries Display tstCal INTO dummyVal FROM dual DBMS_OUTPUT NEW_LINE Offset 03 MAR 1996 by 20 tstDatel TO_DATE 03 03 1996 relOffset 20 resultDate ORDSYS Calendar OffsetDate tstCal tstDatel relOffset DBMS_OUTPUT PUT_LINE OffsetDate tstDatel relOffset 7 resultDate 4 56 Oracle8 Time Series Cartridge User s Guide OffsetDate DBMS_OUTPUT NEW_LINE Offset 03 MAR 1996 by 20 tstDatel TO_DATE 03 03 1996 relOffset 20 resultDate ORDSYS Calendar OffsetDate tstCal tstDatel relOffset DBMS_OUTPUT PUT_LINE OffsetDate tstDatel ORE relOffset II resultDate DBMS_OUTPUT NEW_LINE END This example might produce the following output In this example 29 Mar 1996 is 20 timestamps later than 03 Mar 1996 and 05 Feb 1996 is 20 timestamps earlier than 03 Mar 1996 Calendar Name GENERIC CAL1 Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1996 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions 01 21 1996 00 00 00 02 03 1996 00 00 00 03 24 1996 00 00 00 04 27 1996 00 00 00 05 19 1996 00 00 00 06 23 1996 00 00 00 07 07 1996 00 00 00 08 04 1996 00 00 00 09 15 1996 00 00 00 offExceptions 01 08 1996 00 00 00 02 02 1996 00 00 00 03 05 1996 00 00 00 04 04 1
130. arameters Usage ORDSYS TimeSeries TSProd ts ORDSYS ORDTNumSeries OT Ref startDate DATE endDate DATE RETURN NUMBER Given an input ORDTNumsSeries and optionally starting and ending dates returns a number corresponding to the product result of multiplication of all non null time series entries ts The input time series startDate Starting date within the time series for which the product is to be calculated If start Date is specified endDate must also be specified endDate Ending date within the time series for which the product is to be calculated If end Date is specified startDate must also be specified An exception is returned if any of the following conditions is true a The time series ts is null a The time series ts does not have an associated calendar a endDate is earlier than startDate Time Series and Time Scaling Functions Reference 5 119 TSProd Example Return the product resulting from multiplying the daily closing prices for stock AONE for the month of January 1990 This example is not very plausible but is presented merely to illustrate the syntax SELECT ORDSYS TimeSeries TSProd close to date 01 01 1990 00 00 00 MM DD YYYY HH24 MI SS to_date 01 31 1990 23 59 59 MM DD YYYY HH24 MI SS TSProd FROM ORDTDEV Stocks_TS WHERE ticker AONE This example might produce the following output TSPROD 1 7126E 26 1 row selected 5 120
131. ariance close ORDSYS TimeSeries TSStdDev close FROM ORDTDEV stockdemo_ts WHERE ticker ACME This example might produce the following output ORDSYS ORD ORDSYS ORD ORDSYS ORD 79 143 5 11 9791486 1 row selected 5 130 Oracle8 Time Series Cartridge User s Guide ValidateTS ValidateTS Format ORDSYS TimeSeries ValidateTS or ts INORDSYS ORDTNumSerieslOTRef outMesg OUT VARCHAR2 loDateTab OUT ORDSYS ORDTDateTab hiDateTab OUT ORDSYS ORDTDateTab impreciseDateTab OUT ORDSYS ORDTDateTab duplicateDateTab OUT ORDSYS ORDTDateTab extraDateTab OUT ORDSYS ORDTDateTab missingDateTab OUT ORDSYS ORDTDateTab RETURN INTEGER ORDSYS TimeSeries ValidateTS ts INORDSYS ORDTVarchar2SerieslOTRef outMesg OUT VARCHARZ loDateTab OUT ORDSYS ORDTDateTab hiDateTab OUT ORDSYS ORDTDateTab impreciseDateTab OUT ORDSYS ORDTDateTab duplicateDateTab OUT ORDSYS ORDTDateTab extraDateTab OUT ORDSYS ORDTDateTab missingDateTab OUT ORDSYS ORDTDateTab RETURN INTEGER Time Series and Time Scaling Functions Reference 5 131 ValidateTS Description Parameters Checks whether a time series is valid and if the time series is not valid outputs a diagnostic message and tables with timestamps that are causing the time series to be invalid ts The time series to be checked for validity outMesg If the time series is invalid if the return value 0 contains a diagnostic message describing an
132. ate finer granularity information from coarser granularity infor mation For example quarterly data can be converted to a daily time series Two interfaces to time scaling are supported the collection based interface opera tions on collections and the GROUP BY interface SQL GROUP BY clause Section 2 9 1 discusses the collection based interface for time scaling and Section 2 9 2 discusses the GROUP BY interface Note You should use the collection based interface for most time scaling queries Although the GROUP BY interface is useful for cer tain advanced queries see Section 2 9 2 the collection based inter face offers much better performance in most cases 2 9 1 Time Scaling on Collections The scaleup functions accept as input a numeric time series and a destination calen dar A numeric time series is returned which is scaled based on the destination cal endar For example the following statement returns the last closing prices for stock SAMCO for the months of October November and December of 1996 select from the select cast ORDSYS TimeSeries ExtractTable ORDSYS TimeSeries Scaleuplast ts close sc calendar to date 01 OCT 1996 DD MON YYYY to date 01 JAN 1997 DD MON YYYY as ORDSYS ORDTNumTab from ordtdev stocks_ts ts ordtdev scale sc where ts ticker SAMCO and sc name MONTHLY This example might produce the following output
133. ax minDate1 minDate2 Time Series Concepts 2 25 Time Series Functions For example assume the following two calendars a Calendar 1 01 Jan 1997 through 01 Dec 1997 daily pattern 0 1 1 1 1 1 0 Mon day through Friday off exception 01 May on exceptions 29 Mar and 29 Jun a Calendar 2 01 Feb 1997 through 01 Jan 1998 daily pattern 0 1 1 1 1 1 0 Mon day through Friday off exceptions 01 May and 14 Jul on exceptions 29 Jun and 28 Sep The new derived calendar is 01 Feb 1997 through 01 Dec 1997 daily pattern 0 1 1 1 1 1 0 Monday through Friday off exceptions 01 May and 14 Jul on excep tion 29 Jun 2 8 3 Extraction Retrieval and Trim Functions Time series extraction retrieval and trim functions operate on any time series type Extraction functions return one or more time series rows while retrieval and trim functions return a time series Table 2 5 lists the extraction functions Table 2 5 Extraction Functions Function Description DeriveExceptions ExtractCal ExtractDate ExtractTable ExtractValue First GetDatedElement GetNthElement Last Returns a calendar populated with exceptions derived from either a calendar and a table of dates or two time series Returns a calendar that is the same as the calendar on which the time series is based Gets the date from an element in a time series Returns the time series table ORDTNumTab or ORDTVarchar2Tab associat
134. ayS coonconnconoccnnonnnconnnonnncn cacao ccnnc canon cn nono rannnnr cnc nana 5 67 Send Us Your Comments Oracle8 Time Series Cartridge User s Guide Release 8 0 4 Part No A57501 01 Oracle Corporation welcomes your comments and suggestions on the quality and usefulness of this publication Your input is an important part of the information used for revision Did you find any errors Is the information clearly presented Do you need more information If so where Are the examples correct Do you need more examples What features did you like most about this manual If you find any errors or have any other suggestions for improvement please indicate the chapter section and page number if available You can send comments to us in the following ways e mail nedc_doc us oracle com fax 603 897 3269 Attn Data Cartridge Documentation postal service Oracle Corporation Data Cartridge Documentation One Oracle Drive Nashua NH 03062 USA If you would like a reply please include your name and contact information xi xii Preface This manual describes how to use the Oracle8 Time Series Cartridge Intended Audience Structure Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Appendix A This manual is intended for anyone who is interested in storing retrieving and manipulating time series data in an Oracle database including developers of spe cialized cartridges This manual contai
135. calendar that is the union of two input calendars cal1 The first calendar on which the union operation is to be performed cal2 The second calendar on which the union operation is to be performed The function performs a union of the two input calendars as follows The starting date of the resulting calendar is the later of the starting dates of the two calendars that is resulting minDate max minDatel minDate2 The ending date of the resulting calendar is the earlier of the ending dates of the two calendars that is resulting maxDate min maxDatel maxDate2 The union of the aligned patterns is computed For example if both calendars have a day frequency with Sunday as the first day and if cal1 has a pattern of 0 1 1 1 1 1 0 and cal2 has a pattern of 0 0 1 1 1 1 1 the resulting pattern is 0 1 1 1 1 1 1 that is the calendar includes Mondays through Saturdays The union of the on exception lists is computed For example if cal1 has 30 Mar and 29 Jun as on exceptions and cal2 has 29 Jun and 28 Sep as on exceptions the resulting calendar has 30 Mar 29 Jun and 28 Sep on exceptions Calendar Functions Reference 4 65 UnionCals a The intersection of the off exception lists is computed For example if call has 01 Jan and 04 Jul as off exceptions and cal2 has 01 Jan and 14 Jul as off excep tions the resulting calendar has only 01 Jan as an off exception If the frequencies of the two calendars are
136. checks if the frequencies off exceptions on exceptions and aligned patterns are the same for the two calendars If they are all the same the function returns 1 if they are not all the same the function returns 0 Calendar Functions Reference 4 17 EqualCals The function does not require the calendars to have the same starting and ending dates Example Check if two calendars GENERIC CAL1 and GENERIC CAL2 are equal CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE FORMAT MM DD YYYY HH24 MI SS DECLARE tstCall ORDSYS ORDTCalendar tstCal2 ORDSYS ORDTCalendar resultCal ORDSYS ORDTCalendar equalFlag INTEGER dummyVal INTEGER BEGIN Select the calendars GENERIC CAL1 into tstCall and GENERIC CAL2 into tstCal2 from stockdemo_calendars SELECT value cal INTO tstCall FROM ORDTIDEV stockdemo_calendars cal WHERE cal name GENERIC CAL1 SELECT value cal INTO tstCal2 FROM ORDTIDEV stockdemo_calendars cal WHERE cal name GENERIC CAL2 Display the calendars tstCall and tstCal2 SELECT ORDSYS TimeSeries Display tstCall INTO dummyVal FROM dual SELECT ORDSYS TimeSeries Display tstCal2 INTO dummyVal FROM dual Compare tstCall and tstCal2 for equality DBMS_OUTPUT NEW_LINE equalFlag ORDSYS Calendar EqualCals tstCall tst
137. ci fied number of timestamps minus one For example a 30 day moving sum for a stock s daily trading volume on any given date is the sum of that day s volume and the 29 preceding daily volumes ts The input time series startDate Starting date within the time series for which to return moving sums If startDate is specified endDate must also be specified endDate Ending date within the time series for which to return moving sums If endDate is specified startDate must also be specified k Positive integer specifying the look back window number of timestamps includ ing the current one over which to compute the moving sum 5 72 Oracle8 Time Series Cartridge User s Guide Msum Usage Example The returned time series has nulls for any entry where there are not k 1 timestamps preceding it in the calendar For example if a stock trading calendar for 1997 starts on 02 Jan 1997 the series of 5 day moving sums of the trading volume for a stock for the year has nulls for the volume for the first four timestamps 02 Jan 03 Jan 06 Jan and 07 Jan because there are insufficient timestamps for computing the sum Any nulls in the entries for the k timestamps are ignored as explained in Section 2 8 2 1 An exception is returned if any of the following conditions is true a The time series ts is null a The time series ts does not have an associated calendar a endDate is earlier than startDate Return a table
138. cter other than 1 or 0 in the pat All pattern characters other than 0 or 1 are set to tern 1 Imprecise date The precision is adjusted Superfluous date for example a regu The date is removed from the exceptions list lar valid date in the on exceptions list Null date The date is removed from the calendar 4 70 Oracle8 Time Series Cartridge User s Guide ValidateCal Example Table 4 2 Errors Repaired by ValidateCal Cont Error Repair Action Unsorted dates The dates are sorted Duplicate dates in the on exceptions or Duplicates are removed the date appears only off exceptions list once in the list Date appearing in both the on excep The date is removed from the inappropriate list tions and off exceptions lists depending on the pattern and the anchor date Date outside the date range of the calen The date is removed from the exceptions list dar The following errors are not correctable The function returns 1 if one or more of these errors are found a The frequency is not valid a The starting date is later than the ending date a The pattern is null or empty a All pattern bits are empty a One or more pattern bits are null a The anchor date is null and the pattern is not all ones or all zeroes for exam ple a pattern of 0 1 1 1 1 1 0 but no anchor date specified If the function returns 1 you should not use the calendar until you have fixed the errors that ValidateCal could no
139. d the pattern of a calendar but not the specific on or off exceptions You can extract these exceptions from the data by using the DeriveExceptions function 3 2 1 2 Validating That the Time Series Conforms to the Calendar Often you will want to ensure that the time series data extracted from the incoming data conforms to a predefined calendar To do this insert the exceptions either when you create the calendar or afterward with the InsertExceptions functions or do both creating the calendar with some exceptions and then adding others then use the IsValidTimeSeries function to check that the time series is consistent with the calendar You can insert exceptions when you define the calendar For example the follow ing statement specifies 28 Nov 1996 and 25 Dec 1996 as off exceptions in the calen dar named BUSINESS 96 INSERT INTO stockdemo_calendars VALUES ORDSYS ORDTCalendar 0 BUSINESS 96 4 ORDSYS ORDTPattern ORDSYS ORDTPatternBits 0 1 1 1 1 1 0 TO_DATE 01 JAN 1995 DD MON YYYY O_DATE 01 JAN 1990 DD MON YYYY O_DATE 01 JAN 2001 DD MON YYYY ORDSYS ORDTExceptions TO_DATE 28 NOV 1996 DD MON YYYY TO_DATE 25 DEC 1996 DD MON YYYY ORDSYS ORDTExceptions Y You can also add exceptions after the calendar is defined by using the InsertExcep tions function For example the following statement adds
140. dar Functions Reference 4 69 ValidateCal Usage impOffExc Table of the imprecise off exceptions found in the calendar This function returns one of the following values Value Meaning O The calendar is valid No errors were found 1 Correctable errors were found and corrected The resulting calendar is valid 1 Uncorrectable errors were found The calendar is not valid Errors in the input calendar make it invalid Depending on the error it may be cor rectable or uncorrectable Correctable errors are repaired by the ValidateCal func tion If all errors are correctable the resulting calendar is valid For a calendar to be valid all timestamps in the off exception and on exception lists must be consistent with the defined pattern for the calendar If one or more excep tion timestamps are not consistent with the pattern the calendar is invalid For example if 04 Jan 1997 Saturday is in the off exception list of a calendar whose pattern includes only Mondays through Fridays as normal business days 04 Jan 1997 is an invalid off exception because as a Saturday is would normally be an off day Imprecise exception timestamps are repaired For an explanation of precision see Section 2 2 1 Table 4 2 lists correctable errors and the repair actions taken by the ValidateCal function Table 4 2 Errors Repaired by ValidateCal Error Repair Action Imprecise anchor date The precision is adjusted Chara
141. dummyVal INTEGER BEGIN Select the calendars GENERIC CAL1 into tstCall and GENERIC CAL2 into tstCal2 from stockdemo_calendars SELECT value cal INTO tstCall FROM ORDIDEV stockdemo_calendars cal WHERE cal name GENERIC CAL1 SELECT value cal INTO tstCal2 FROM ORDTDEV stockdemo_ calendars cal WHERE cal name GENERIC CAL2 4 28 Oracle8 Time Series Cartridge User s Guide IntersectCals Display the calendars tstCall and tstCal2 SELECT ORDSYS TimeSeries Display tstCal1 INTO dummyVal FROM dual SELECT ORDSYS TimeSeries Display tstCal2 INTO dummyVal FROM dual Combine tstCall and tstCal2 resultCal ORDSYS Calendar CombineCals tstCall tstCal2 equalFlag SELECT ORDSYS TimeSeries Display resultCal result of CombineCals INTO dummyVal FROM dual DBMS_OUTPUT PUT_LINE equalFlag equalFlag Intersect tstCall and tstCal2 resultCal ORDSYS Calendar IntersectCals tstCall tstCal2 SELECT ORDSYS TimeSeries Display resultCal result of IntersectCals INTO dummyVal FROM dual END This example might produce the following output Calendar Name GENERIC CAL1 Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1996 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExceptions 01 21 1996 00 00 00 02 03 1996 00 00 00
142. e Series Usage 3 1 Using the Cartridge close NUMBER volume INTEGER CONSTRAINT pk_stockdemo PRIMARY KEY ticker tstamp 2 ORGANIZATION INDEX 3 Notes on Example 3 1 The table is named stockdemo and has the columns for the ticker stock symbol the timestamp date on which stocks are traded that day s opening high low and closing prices and the trading volume The constraint named pk_stockdemo defines the primary key as the ticker plus the timestamp ORGANIZATION INDEX indicates that this is an index organized table The CREATE TABLE statement can also include other keywords such as TABLESPACE and STORAGE 3 1 2 Step 2 Define a Calendar If the calendar does not already exist create it by inserting its definition in a table of calendars If the table of calendars does not already exist create it first Your calendar will be based on the system defined datatype ORDTCalendar which is supplied with the cartridge ORDTCalendar has the following definition System Defined Calendar Datatype CREATE TYPE ORDSYS ORDTCalendar AS OBJECT caltype INTEGER name VARCHAR2 256 frequency INTEGER pattern ORDSYS ORDTPattern minDate DATE maxDate DATE offExceptions ORDSYS ORDTExceptions onExceptions ORDSYS ORDTExceptions The following example creates a table named stockdemo_calendars and defines a cal endar named BusinessDays The B
143. e calendar of the output time series is the same as that of the input time series An exception is returned if the time series ts is null or if NumValues is zero 0 or negative Return the first 10 timestamps and opening prices in the time series for stock ACME SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE FORMAT MM DD YYYY HH24 MI SS DECLARE dummyval INTEGER 5 42 Oracle8 Time Series Cartridge User s Guide FirstN BEGIN SELECT ORDSYS TimeSeries Display ORDSYS TimeSeries FirstN ts open 10 FirstN Results INTO dunmyval FROM ORDTIDEV stockdemo_ts ts WHERE ts ticker ACME END This example might produce the following output FirstN Results Calendar Data Calendar Name BUSINESS 96 Frequency 4 MinDate 01 01 1990 00 00 00 MaxDate 01 01 2001 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions offExceptions 11 28 1996 00 00 00 12 25 1996 00 00 00 Series Data Date Value 01 1996 00 00 00 59 04 1996 00 00 00 60 05 1996 00 00 00 61 06 1996 00 00 00 62 07 1996 00 00 00 63 08 1996 00 00 00 64 11 1996 00 00 00 65 12 1996 00 00 00 66 13 1996 00 00 00 67 14 1996 00 00 00 68 Time Series and Time Scaling Functions Reference 5 43 GetDatedElement GetDatedElement Format Description Parameters Usage Example ORDSYS TimeSeries GetDatedElement t
144. e must also be specified An exception is returned for any of the following conditions a The input time series the calendar on which the input time series in based or the specified calendar is null 5 82 Oracle8 Time Series Cartridge User s Guide ScaleupLast Example a The frequency of the calendar on which the time series is based is greater than the frequency of the specified calendar for example the time series calendar s frequency is month and the specified calendar s frequency is day For an explanation of concepts related to time scaling see Section 2 9 Return the last closing prices for stock SAMCO for the months of October Novem ber and December of 1996 SELECT FROM THE SELECT CAST ORDSYS TimeSeries ExtractTable ORDSYS TimeSeries ScaleupLast ts close sc calendar to_date 01 OCT 1996 DD MON YYYY to date 01 JAN 1997 DD MON YYYY AS ORDSYS ORDTNumTab FROM ORDTDEV stocks_ts ts ordtdev scale sc WHERE ts ticker SAMCO and sc name MONTHLY This example might produce the following output TSTAMP VALUE 01 OCT 96 42 375 01 NOV 96 38 25 01 DEC 96 3919 3 rows selected Note that each timestamp reflects the first date of the month in the calendar follow ing the rules explained in Section 2 2 1 and each value in this case reflects the clos ing price on the last date for that month in the calendar
145. e time series for which the cumulative minimum is to be returned If endDate is specified startDate must also be specified Only non null values are considered in determining the cumulative minimum An exception is returned if any of the following conditions is true a The time series ts is null a The time series ts does not have an associated calendar a endDate is earlier than startDate Time Series and Time Scaling Functions Reference 5 7 Cmin If startDate and endDate are specified the time series is trimmed to the date range before the cumulative minimum is computed Example Return the cumulative minimum of the closing price of stock ACME for November 1996 SELECT FROM the SELECT CAST ORDSYS TimeSeries ExtractTable ORDSYS TimeSeries Cmin ts close to_date 01 NOV 96 DD MON YY to_date 30 NOV 96 DD MON YY AS ORDSYS ORDTNumTab FROM ORDTDEV stockdemo_ ts ts WHERE ts ticker ACME This example might produce the following output Note that this output reflects the simplified artificial data in the usage demo database where the closing price rises one point each day 01 NOV 96 59 04 NOV 96 59 05 NOV 96 59 06 NOV 96 59 07 NOV 96 59 08 NOV 96 59 11 NOV 96 59 12 NOV 96 59 13 NOV 96 59 14 NOV 96 59 15 NOV 96 59 18 NOV 96 59 19 NOV 96 59 20 NOV 96 59 21 NOV 96 59 22 NOV 96 59 25 NOV 96 59 26 NOV 96 59 27 NOV 96 5
146. ecurity view should be defined to ensure data integrity see Section 2 6 2 2 5 Interfaces to Time Series and Time Scaling Functions The interfaces to the time series and time scaling functions rely on the following aspects of the Time Series cartridge architecture a Time series data is stored as relational data in a flat IOT one timestamp per row a Calendars are stored in object tables a Time series and time scaling functions expect time series data and calendars to be formatted as objects A time series object is typically the first parameter to a function Two basic interfaces to time series and time scaling functions are defined a aninstance based object interface In the instance based interface the first input parameter to a time series func tion is an instance of a time series for example ORDTNumSeries a areference based object interface In the reference based interface the first input parameter to a time series func tion is a reference to a time series for example ORDTNumSeriesIOTRef The reference based interface requires that you provide enough descriptive infor 2 12 1A time series could be stored in a standard table however for performance reasons it is highly recommended that you use an IOT rather than a standard table Oracle8 Time Series Cartridge User s Guide Interfaces to Time Series and Time Scaling Functions mation to enable the functions to execute dynamic SQL to obtain an ins
147. ed with a time series Gets the value stored in an element in a time series Gets the first element in a time series Gets the element of a time series at a supplied date Gets the Nth element of a time series Gets the last element in a time series 2 26 Oracle8 Time Series Cartridge User s Guide Time Series Functions Table 2 6 lists the retrieval and trim functions Table 2 6 Retrieval and Trim Functions Function Description FirstN Gets the first n elements in a time series GetSeries Returns the entire time series LastN Gets the last n elements in a time series TrimSeries Returns the time series data between the supplied dates 2 8 4 Shift Functions Shift functions lead or lag a time series by a specified number of units where units reflects the frequency of the calendar for the time series Table 2 7 Shift Functions Function Description Lead Leads a time series by the specified number of units Lag Lags a time series by the specified number of units 2 8 5 SQL Formatting Functions When called from a SOL SELECT expression a time series function returns an instance of a time series datatype which is not displayable The SOL formatting functions facilitate format conversions that allow time series to be displayed Table 2 8 SQL Formatting Functions Function Description ExtractCal Given a time series returns a calendar that is the same as the calendar on which the time series
148. efined as an off exception and assume that origin is 02 Jul 1997 Wednesday If relOffset 2 the returned date is 07 Jul 1997 Monday Calendar Functions Reference 4 55 OffsetDate If relOffset 2 the returned date is 30 Jun 1997 Monday If relOffset 0 the returned date is 02 Jul 1997 Wednesday If the origin date is not in the calendar inputCal the next later date is used if relOff set is positive or zero and the next earlier date is used if relOffset is negative Using the calendar in the preceding example if origin is specified as 04 Jul 1997 and if relOffset 2 then 07 Jul 1997 Monday the next business day is used as origin and the returned date is 09 Jul 1997 Wednesday If the calendar pattern is empty or null an exception is raised Example Get the dates 20 timestamps later and 20 timestamps earlier than 03 Mar 1996 in the GENERIC CAL1 calendar CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON ALTER SESSION SET NLS DATE FORMAT MM DD YYYY HH24 MI SS DECLARE tstCal ORDSYS ORDTCalendar tstDatel DATE resultDate date dummyVal INTEGER relOffset INTEGER BEGIN Select a calendar say GENERIC CAL1 into tstCal from stockdemo_calendars SELECT value cal INTO tstCal FROM ORDIDEV stockdemo_calendars cal WHERE cal name GENERIC CAL1 Display the calend
149. efinition for example a Saturday timestamp that is in a Monday Friday calendar and that is not an on exception missingDateTab A table of dates that are excluded from the time series but that should be included based on the calendar definition for example a Wednesday date that is not a holi day in a Monday Friday calendar and for which there is no data Such dates can be considered as holes in the time series mesg Optional message This procedure is intended to be used with the ValidateTS function See the infor mation on ValidateTS in this chapter The DisplayValTS procedure uses the DBMS_OUTPUT package See the Usage information for the Display function for limitations relating to the use of DBMS_OUTPUT Use the IsValidTS and ValidateTS functions and the DisplayValTS procedure with an invalid time series SET SERVEROUTPUT ON ALTER SESSION SET NLS DATE FORMAT MM DD YYYY HH24 MI SS DECLARE numTS ORDSYS ORDTNumSeries tempVal integer Time Series and Time Scaling Functions Reference 5 19 DisplayValTS Procedure retIsValid integer retValTS integer loDateTab ORDSYS ORDTDateTab hiDateTab ORDSYS ORDTDateTab impDateTab ORDSYS ORDTDateTab dupDateTab ORDSYS ORDTDateTab extraDateTab ORDSYS ORDTDateTab EE missingDateTab ORDSYS ORDTDateTab NULL outMesg varchar2 2000 BEGIN Set the buffer size DBMS_OUTPUT ENABLE 100
150. ement of the returned time series For example a If two time series contain daily trade volumes for two stocks each element of the returned time series contains the result of multiplying the volume in the first time series by the volume in the second time series for that day a Ifa time series ts1 contains closing prices for a stock and if a constant k of 2 is specified each element of the returned time series contains the closing price of ts1 multiplied by 2 If ts1 and ts2 are specified the function returns a time series whose calendar is the result of using the CombineCals function on the calendars associated with these two time series An exception is returned if any of the following conditions is true a An input time series is null a An input time series does not have an associated calendar a The calendars associated with ts1 and ts2 do not have the same frequency and aligned pattern a endDate is earlier than startDate Example Multiply the high price for stock ACME by the low price for stock FUNCO for each trading day from 14 Nov 1996 through 14 Dec 1996 CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE FORMAT MM DD YYYY HH24 MI SS 5 116 Oracle8 Time Series Cartridge User s Guide TSMultiply DECLARE tstCal ORDSYS ORDTCalendar startDate date endDate date dummyval INTEGER BEGIN startDate TO_DATE 11 14 1996
151. en ticker meta tickername ORDSYS ORDTNumSeriesIOTRef substr meta tickername 1 230 high NumSeries Ref cal ordtdev stockdemo tstamp high ticker meta tickername ORDSYS ORDTNumSeriesIOTRef substr meta tickername 1 230 low NumSeries Ref cal ordtdev stockdemo ORDSYS ORDTNumSeriesIOTRef 2 16 Oracle8 Time Series Cartridge User s Guide tstamp low ticker meta tickername Interfaces to Time Series and Time Scaling Functions substr meta tickername 1 230 close NumSeries Ref cal ordtdev stockdemo tstamp close ticker meta tickername ORDSYS ORDTNumSeriesIOTRef substr meta tickername 1 230 volume NumSeries Ref cal ordtdev stockdemo tstamp volume ticker meta tickername FROM stockdemo metadata meta stockdemo calendars cal WHERE meta calendarname Cal name Depending on which column is selected a different literal value is applied as an attribute of the ORDTNumSeriesIOTRef type For example for the following query SELECT ORDSYS TimeSeries Mavg close to date 02 DEC 96 DD MON YY to date 31 DEC 96 DD MON YY 10 FROM ORDIDEV stockdemo_ts WHERE ticker ACME The literal value close is used as the value_colname column name The other attributes of the ORDTNumSeriesIOTRef type include the timestamp c
152. endDate TO_DATE 12 14 1996 SELECT ORDSYS TimeSeries Display ORDSYS TimeSeries TSMultiply ts1 high ts2 low startDate endDate TSMultiply Results INTO dummyval FROM ORDTDEV stockdemo_ts tsl ORDIDEV stockdemo_ts ts2 WHERE tsl ticker ACME and ts2 ticker FUNCO END This example might produce the following output TSMultiply Results Calendar Data Frequency 4 MinDate 01 01 1990 00 00 00 MaxDate 01 01 2001 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions offExceptions 11 28 1996 00 00 00 12 25 1996 00 00 00 Series Data Date Value 11 14 1996 00 00 00 1647 03 11 15 1996 00 00 00 1668 8 11 18 1996 00 00 00 1694 77 11 19 1996 00 00 00 LITLE Z 11 20 1996 00 00 00 1738 86 11 21 1996 00 00 00 1764 16 11 22 1996 00 00 00 1788 75 11 25 1996 00 00 00 1809 56 11 26 1996 00 00 00 1831 06 Time Series and Time Scaling Functions Reference 5 117 TSMultiply 1 27 1996 00 00 00 1849 1 29 1996 00 00 00 1876 2 02 1996 00 00 00 1910 2 03 1996 00 00 00 1946 2 04 1996 00 00 00 1969 2 05 1996 00 00 00 2002 2 06 1996 00 00 00 1995 2 09 1996 00 00 00 2020 2 10 1996 00 00 00 2046 2 11 1996 00 00 00 2044 2 12 1996 00 00 00 2060 2 13 1996 00 00 00 2082 5 118 Oracle8 Time Series Cartridge User s Guide 38 29 43 64 lt 19 TSProd TSProd Format Description P
153. endar representation Examples of frequencies are second minute hour day month and year Pattern The pattern specifies the repeating pattern of frequencies and an anchor date that identifies the date of an occurrence of the frequency For example if the fre quency is set to day the pattern can define which days of the week are included in the calendar For example a pattern of 0 1 1 1 1 1 0 over a day frequency defines a calendar over all weekdays If an anchor date of 01 Jun 1997 or any Sunday is specified then the 7 day pattern begins each Sunday and Sunday and Saturday 0 are excluded from the calendar while Monday through Fri day 1 are included in the calendar Exceptions Exceptions are timestamps that do not conform to the calendar pattern but that are significant for the calendar definition There are two kinds of exceptions off exceptions and on exceptions Anoff exception is an exception to the 1 bits in the pattern and thus is a timestamp to be excluded from the calendar For example to ensure that Wednesday 25 Dec 1996 is excluded from the calendar when Wednesdays normally are included define that date as an off exception Anon exception is an exception to the 0 bits in the pattern and thus is a timestamp to be included in the calendar For example to ensure that Satur day 28 Jun 1997 is included in the calendar when Saturdays are excluded define that date as an on exception Time Series Conc
154. epts 2 5 Calendars On exceptions can also be used without a pattern that is when a zero pat tern is specified for the time series An irregular time series can be con structed by defining a frequency a zero 0 pattern and an on exceptions list In this case the on exceptions list defines the timestamps that consti tute the irregular time series An example of such an irregular time series is a calendar of dates for quarterly dividend payments or earnings announce ments 2 2 1 Frequency and Precision Each frequency has an associated integer code that is used in function calls Table 2 1 lists the supported frequencies and their integer codes Table 2 1 Frequencies Frequency Every Integer Code second 1 minute 2 hour 3 day 4 month 6 8 year Each frequency has an associated precision Time Series cartridge functions require that input timestamps be of the precision of the frequency associated with the calen dar The SetPrecision function is the exception this function takes a frequency and a timestamp and returns a timestamp that conforms to the associated calendar A timestamp that is not consistent with the frequency is said to be imprecise For example a timestamp of 09 Sep 1997 is imprecise if it is input to a function that is dealing with a calendar whose frequency is 6 month or 8 year When you create a calendar all timestamps used in the calendar definition the anchor date for the pat ter
155. er 3 1 5 Step 5 Create a Reference Based View Create a reference based view for convenient and efficient access to time series data as explained in Section 2 5 2 Example 3 5 creates a reference based view for stock price data Example 3 5 Create a Reference Based View CR EATE VIEW stockdemo_ts ticker open high low close volume AS SELECT meta tickername ORDSYS ORDTNumSeriesIOTRef substr meta tickername 1 230 open NumSeries Ref cal ORDTDEV stockdemo tstamp open ticker meta tickername ORDSYS ORDTNumSeriesIOTRef substr meta tickername 1 230 high NumSeries Ref cal ORDTDEV stockdemo tstamp high ticker meta tickername ORDSYS ORDTNumSeriesIOTRef substr meta tickername 1 230 low NumSeries Ref cal ORDTDEV stockdemo 3 6 Oracle8 Time Series Cartridge User s Guide nddate THEN tartdate or E Ed x Using the Cartridge tstamp low ticker meta tickername ORDSYS ORDTNumSeriesIOTRef substr meta tickername 1 230 close NumSeries Ref cal ORDTDEV stockdemo tstamp close ticker meta tickername ORDSYS ORDTNumSeriesIOTRef substr meta tickername 1 230 volume NumSeries Ref cal ORDTDEV stockdemo tstamp volume ticker meta tickername FROM stockdemo metadata m
156. er functions let you modify and expand the Time Series cartridge capabilities For example you could use product developer calendar functions in creating a new function that modified the information returned for the moving average or that returned a net present value for a portfolio of stocks at a specified date Time Series Concepts 2 21 Calendar Functions Note It is recommended that you not modify the functions pro vided with the Time Series cartridge If you want a function with a behavior different from an existing function create a new function with a different name or put the function in a different package or do both For example if you work for XYZ Corporation and create a modified moving average function you could name the function MavgXYZ and put it in a package named XYZPackage Table 2 4 lists the product developer calendar functions Table 2 4 Product Developer Calendar Functions Function Description Calendar Related Functions CombineCals Combines two calendars Similar to IntersectCals except patterns must be identical Exception Related Functions NumOffExceptions Returns the number of off exceptions between two dates NumOnExceptions Returns the number of on exceptions between two dates Date and Index Related Functions IsValidDate Determines if a supplied date is valid OffsetDate Returns a date which is k dates in the future or k in the past if k is negative of the supplied date
157. eries data during loading you must choose one of the approaches described in Section 2 6 3 Adjust calendars to be consistent with the time series if you are sure that all timestamps are correct This strategy is normally appropriate when there is a unique calendar per time series a Validate that each time series is consistent with the calendar if you expect time series data to adhere to a predefined calendar This approach is particularly useful if the same calendar is used for all time series data being loaded This section describes how to perform bulk loading using these two approaches and it also describes how to perform incremental loading The loading of time series data is usually performed under controlled circum stances so it is safe to perform these loads directly to an underlying table instead of to a security view Time Series Usage 3 9 Loading Time Series Data 3 2 1 Bulk Loading After you create an index organized table IOT to hold time series data such as for the stockdemo demo database you must populate the table with data For a data base of stock information you may need to load millions of rows of daily summary information into the IOT SQL Loader is recommended for loading large amounts of time series data The fol lowing example shows a SQL Loader script with an excerpt from the sample data stockdat dat and the SOL Loader control file stockdat ctl For complete informa tion about SOL
158. erieslOTRef units INTEGER stariDate DATE endDate DATE RETURN ORDSYS ORDTNumSeries or ORDSYS TimeSeries Lag ts ORDSYS ORDTNumSerieslOTRef lead_date DATE stariDate DATE endDate DATE RETURN ORDSYS ORDTNumSeries Description Given a time series a positive or negative number units or a date lead_date and optionally a starting and ending timestamp within the time series returns a time series that lags or for negative numeric values leads the input time series by the appropriate number of timestamps Parameters ts The input time series units Integer specifying the number of timestamps by which the output time series is to be adjusted If units is positive each element in the output time series is the same as the element in the input time series for that relative position minus the units If Time Series and Time Scaling Functions Reference 5 59 Lag Usage units is negative each element in the output time series is the same as the element in the input time series for that relative position plus the units lead_date The date relative to the starting date reflecting the number of timestamps by which the output time series is to be adjusted The function calculates the number of timestamps between lead_date and startDate and then uses that number as if it were a units parameter value If lead_date is later than startDate the effective units value is positive if lead_date is before the starting
159. es functions 2 8 2 Conventions and Semantics For time series functions that accept two time series both time series must be defined on calendars that have the same frequency and the same pattern The calen dars may have different exceptions lists and different starting and ending dates 2 8 2 1 Semantics of Null Operands A number of time series functions perform arithmetic comparison and grouping operations When nulls are encountered in this context the default behavior is to mirror SQL a Group functions ignore nulls When all values encountered are null a null is returned For example the sum of 1 NULL NULL 3 returns 4 The sum of NULL NULL NULL NULL returns null 2 24 Oracle8 Time Series Cartridge User s Guide Time Series Functions a Functions that operate on time series ignore nulls but return a null if all values encountered are null Such functions include Mavg Moving Average and Msum Moving Sum For example if there are 5 nulls in the last 30 timestamps for and including a specific date the 30 day moving average on that date is computed using only 25 values that is adding only the non null values and dividing by 25 How ever if all 30 dates the date and the 29 previous dates have nulls the moving average for that date is null Any arithmetic expression containing a null returns a null For example 10 NULL returns null a A comparison operator that encounters a null returns a nul
160. eslOTRef RETURN ORDSYS ORDTNumCell Given a time series returns the first element in it ts The input time series A null is returned if the time series fs is empty An exception is returned if the time series ts is null Return the first timestamp and opening price for stock ACME in the stockdemo_ts time series SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE FORMAT MM DD YYYY HH24 MI SS DECLARE dummyval INTEGER BEGIN SELECT ORDSYS TimeSeries Display ORDSYS TimeSeries First ts open First Results INTO dummyval FROM ORDTIDEV stockdemo_ts ts WHERE ts ticker ACME END 5 40 Oracle8 Time Series Cartridge User s Guide First 7 This example might produce the following output First Results Timestamp 11 01 1996 00 00 00 Value 59 Time Series and Time Scaling Functions Reference 5 41 FirstN FirstN Format Description Parameters Usage Example ORDSYS TimeSeries FirstN ts ORDSYS ORDTNumSerieslOTRef NumValues NUMBER RETURN ORDSYS ORDTNumSeries Given a time series and a number of elements NumValues to return returns the first NumValues elements in the time series ts The input time series NumValues Number of elements from the beginning of the time series to be returned The function returns a time series populated with the first NumValues cells from the input time series ts Th
161. esult in timestamps outside of mindate max date Action Adjust the lead timestamp or lead units to remain within calendar min date maxdate or extend the mindate maxdate TS 00541 the projected lag timestamp is beyond the calendar mindate maxdate Cause The given parameters result in timestamps outside of mindate max date Action Adjust the lag timestamp or lag units to remain within calendar mind ate maxdate or extend the mindate maxdate Error Messages A 5 Error Messages TS 00542 the window size for mavg msum must be gt 1 Cause Window size parameter passed to moving average sum was not greater than 0 Action Use a window size parameter greater than or equal to 1 TS 00547 the input fill type is invalid Cause Fill has been called with a filltype less than 0 or greater than 2 Action Use a valid filltype 0 1 or 2 TS 00551 error parsing the SOL statement with the time series ref Cause The SQL statement constructed from the time series ref was invalid Action Verify the validity of the time series ref e Verify the validity of all components of the time series ref e No spaces or invalid punctuation may appear in table or column names The user must have select privileges on the table referenced e The table name must be qualified with its schema name TS 00552 error executing the SQL statement with the time series ref Cause The SQL statement constructed from the time serie
162. et_index INTEGER startDate DATE endDate DATE RETURN ORDSYS ORDTNumCell Description Given a time series a number target_index and optionally a date range returns the Nth element element whose position corresponds to target_index in the speci fied time series or within the date range if one is specified Parameters ts The input time series target_index Positive integer specifying the position of the element to be returned startDate Starting date within the time series to which target_index is to be applied If target_index 1 the function returns the element for startDate If startDate is speci fied endDate must also be specified endDate Ending date within the time series to which target_index is to be applied If endDate is specified startDate must also be specified Usage An exception is returned if any of the following conditions is true a The time series ts is null a The time series ts does not have an associated calendar 5 46 Oracle8 Time Series Cartridge User s Guide GetNthElement Example a target_index is not an integer or is zero 0 or a negative number a endDate is earlier than startDate Return the tenth opening price for stock AONE SELECT ORDSYS TimeSeries ExtractValue ORDSYS TimeSeries GetNthElement open 10 FROM ORDTDEV stocks_ts WHERE ticker AONE This example might produce the following output ORDSYS TIM 15 1875 1 row se
163. eta stockdemo calendars cal WHERE meta calendarname Cal name The refvw sql demo file creates a reference based view 3 1 6 Step 6 Validate Time Series Consistency Choose one of the following approaches to ensuring the consistency of time series data using the guidelines in Section 2 6 3 a Adjust calendars to be consistent with the time series Use the DeriveExceptions function in adjusting a calendar to be consistent with the time series See Section 2 2 4 for more information about this approach a Validate that each time series is consistent with the calendar Use the IsValidTS function to check that the time series is consistent with the calendar See the IsValidTS function reference information in Chapter 5 3 1 7 Step 7 Formulate Time Series Queries Formulating time series queries involves invoking time series or time scaling func tions or both Example 3 6 uses the Mavg time series function to obtain 30 day moving averages for stock ACME and it uses the ScaleupSum time scaling func tion to obtain monthly volumes for stock ACME The results shown in the exam ple reflect sample data for the cartridge usage demo The queries in this step use the reference based view stockdemo_ts that was cre ated in step 6 Example 3 6 Formulate Time Series Queries SELECT FROM THE SELECT CAST ORDSYS TimeSeries ExtractTable ORDSYS TimeSeries Mavg close to_date 11 01 96
164. ew synthesizes references to col lections Reference based views are explained in Section 2 5 2 Figure 1 1 shows the layering and interdependencies between underlying tables and the security and reference based views 1 6 Oracle8 Time Series Cartridge User s Guide Time Series Cartridge Demos Demonstrations Figure 1 1 Tables and Views in the Time Series Usage Demo Reference View Security View stockdemo_ts stockdemo_sv Index Organized Time Series Time Series Data Table Calendar Table Metadata Table stockdemo stockdemo_calendars stockdemo_metadata NU 3689A RA Introduction 1 7 Time Series Cartridge Demos Demonstrations 1 8 Oracle8 Time Series Cartridge User s Guide 2 Time Series Concepts This chapter explains concepts related to the Oracle8 Time Series Cartridge and it provides information on using the cartridge It covers the following topics overview of time series data calendars Time Series cartridge architecture storage of time series data the collection based interface to functions consistency of time series data the reference based interface overviews of each major function type calendar time series time scaling using the Time Series cartridge 2 1 Overview of Time Series Data A time series is a set of timestamped data entries A time series allows a natural association of data collected over intervals of time For example summaries of stock market trading or ban
165. f datatype 2 24 ORDTVarchar2Tab datatype 2 23 P package names public synonyms for 1 4 pattern 2 5 precision 2 7 purified timestamps 2 19 PRO C C demo 1 4 procedures DisplayValCal 4 10 DisplayValTS 5 18 product TSAvg function 5 119 public synonyms for package names 1 4 purified timestamps 2 19 R reference based interface 2 15 reference based view 1 6 2 16 regular time series 2 1 S Scaleup function 5 74 ScaleupAvg function 5 76 ScaleupCount function 5 78 ScaleupFirst function 5 80 ScaleupLast function 5 82 ScaleupMax function 5 84 ScaleupMin function 5 86 ScaleupSum function 5 88 security view 1 6 2 16 3 4 semantics null operands 2 24 off exception operands 2 25 Index 4 server output setting 5 16 SET SERVEROUTPUT ON statement 5 16 SetPrecision function 4 58 shift functions 2 27 SQL formatting functions 2 27 SQL Loader utility 3 9 bulk loading 3 10 conventional and direct paths 3 13 incremental loading 3 12 standard deviation TSStdDev function 5 121 stockdemo_metadata table 1 6 2 16 stockdemo_sv security view 1 6 2 16 stockdemo_ts reference based view 1 6 2 16 subtraction TSSubtract function 5 123 sum TSSum function 5 127 sum moving Msum function 2 29 5 72 synonyms public package names 1 4 T time scaling functions 2 31 5 1 time series cartridge architecture 2 10 data storage 2 11 datatypes 2 23 irregular 2
166. f historical data stored in a database Figure 2 2 Historical Data for Stocks Ticker Tstamp Open High Low Close Volume XYZ 01 02 1997 21 75 22 75 21 50 22 00 352 000 XYZ 01 03 1997 22125 22 50 21 00 21 75 530 000 XYZ 01 06 1997 21 625 22 00 21 625 21 875 490 000 YZA 01 02 1997 44 25 44 25 43 50 43 875 125 000 YZA 01 03 1997 43 75 44 25 43 75 44 125 97 000 YZA 01 06 1997 44 25 44 50 44 125 44 125 107 000 Stock market historical databases have the following general characteristics a Multiple stocks each identified by the ticker symbol can be stored in the data base a Each stock can have multiple attributes ticker tstamp open high low close vol ume a Each stock has one or more associated time series 2 4 Oracle8 Time Series Cartridge User s Guide Calendars Each time series has an associated calendar see Section 2 2 This kind of financial historical data is used in examples in this manual and in the usage demo see Section 1 6 provided with the Time Series cartridge 2 2 Calendars A calendar maps human meaningful time values to underlying machine represen tations of time Typically a calendar is associated with a time series For example a business day calendar can define the days of the week on which stocks are traded The holidays when trading does not occur are also in the calen dar The following are key components of a calendar Frequency A frequency specifies the granularity of the cal
167. fExceptions 01 08 1996 00 00 00 02 02 1996 00 00 00 03 05 1996 00 00 00 Calendar Functions Reference 4 25 InsertExceptions 04 04 1996 00 00 00 04 08 1996 00 00 00 05 08 1996 00 00 00 06 25 1996 00 00 00 07 09 1996 00 00 00 4 26 Oracle8 Time Series Cartridge User s Guide IntersectCals IntersectCals Format ORDSYS Calendar IntersectCals cali ORDSYS ORDTCalendar cal2 ORDSYS ORDTCalendar RETURN ORDSYS ORDTCalendar Description Returns the intersection of two calendars Parameters cal1 The first calendar to be intersected cal2 The second calendar to be intersected Usage The function performs an intersection of the two input calendars as follows a The starting date of the resulting calendar is the later of the starting dates of the two calendars that is resulting minDate max minDatel minDate2 a The ending date of the resulting calendar is the earlier of the ending dates of the two calendars that is resulting maxDate min maxDatel maxDate2 a The intersection of the aligned patterns is computed For example if both calen dars have a day frequency with Sunday as the first day and if cal1 has a pattern of 0 1 1 1 1 1 0 and cal2 has a pattern of 0 0 1 1 1 1 1 the resulting pattern is 0 0 1 1 1 1 0 that is the calendar includes only Tuesdays Wednesdays Thurs days and Fridays a The intersection of the on exception lists of the two calendars is computed For examp
168. fficiently than is possible using only traditional datatypes and user defined functions With the Time Series cartridge you can use or adapt existing tables for time series applications or you can create new tables You can also extend the capabilities of the cartridge to add or modify functions and to create customized calendars 1 1 Data Cartridges Within the Oracle Network Computing Architecture NCA data cartridges facil itate the storage and retrieval of complex datatypes required by nontraditional Introduction 1 1 Object Relational Technology database applications such as geographic information systems imaging work flow document management and digital libraries These applications are built using components or modules that support the capture input processing analysis storage retrieval and display of the complex datatypes A data cartridge is the mechanism by which clients application specific servers and database servers can be easily and reliably extended The Oracle8 Time Series Cartridge provides support for time series domain specific types functions and interfaces The Time Series cartridge focuses on a set of time series data representa tion and access mechanisms sufficient to support many applications and the devel opment of more specialized cartridges 1 2 Object Relational Technology The objects option makes Oracle8 an object relational database management sys tem which means that users can
169. fined in the text Italic type in text indicates emphasis or a user defined variable schema name or object datatype Angle brackets enclose user supplied names Brackets enclose optional clauses from which you can choose one or none xiv 1 Introduction The Oracle8 Time Series Cartridge is an extension to Oracle8 that provides storage and retrieval of timestamped data through object types The cartridge is a building block for applications rather than being an end user application in itself It consists of datatypes along with related functions for managing and processing time series data For example applications can use this cartridge to process historical data derived from financial market transactions such as trades of stocks bonds and mutual fund shares In such applications the functions included with the Time Series car tridge let you conveniently perform operations ranging from the simple to the com plex such as a finding the opening closing low and high prices for a stock on a specific date a calculating monthly volumes for a stock for a specific year a deriving the 30 day moving average for a stock over a year Time series applications have certain distinct requirements and some degree of commonality The time series datatypes accommodate the commonality and sup port extensions that address application specific requirements With this cartridge time series data can be managed more conveniently and e
170. ge ORDSYS Calendar NumTimeStampsBetween inputCal INORDSYS ORDTCalendar startDate IN DATE endDate IN DATE RETURN INTEGER Given starting and ending input timestamps returns the number of valid timestamps within that range according to the specified calendar inputCal The calendar to be used to determine whether a timestamp is valid or invalid startDate Starting date in the range to be checked for invalid timestamps endDate Ending date in the range to be checked for invalid timestamps A timestamp is invalid not valid if any of the following conditions is true a Itis outside the date range of the calendar a Itis an off exception in the calendar a Itis not sufficiently precise for example a timestamp of 01 Jul 1997 if the calen dar has a frequency of year a Itisnull startDate and endDate are included in the check for valid timestamps If there are no valid timestamps in the date range the function returns 0 zero 4 52 Oracle8 Time Series Cartridge User s Guide NumTimeStampsBetween Example If startDate is greater later than endDate an exception is raised Contrast this function with NumInvalidTimeStampsBetween which returns the number of invalid timestamps in a date range Return the number of valid timestamps between 03 Feb 1996 and 16 May 1996 in the GENERIC CAL1 calendar CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE_ FORMAT MM DD YYYY HH24 MI SS
171. ght produce the following output ORDSYS ORD ORDSYS ORD ORDSYS ORD 79 143 5 11 9791486 1 row selected 5 98 Oracle8 Time Series Cartridge User s Guide TSCount TSCount Format Description Parameters Usage ORDSYS TimeSeries TSCount ts ORDSYS ORDTNumSeries OTRef startDate DATE endDate DATE RETURN NUMBER Given an input ORDTNumsSeries and optionally starting and ending dates returns a number corresponding to the count of all non null time series entries ts The input time series startDate Starting date within the time series for which the count is to be calculated If start Date is specified endDate must also be specified endDate Ending date within the time series for which the count is to be calculated If end Date is specified startDate must also be specified Nulls are ignored in computing the count An exception is returned if any of the following conditions is true a The time series ts is null a The time series ts does not have an associated calendar a endDate is earlier than startDate Time Series and Time Scaling Functions Reference 5 99 TSCount Example Return the total number of daily closing prices for stock AONE for the month of January 1990 SELECT ORDSYS TimeSeries TSCount close to date 01 01 1990 00 00 00 MM DD YYYY HH24 MI SS to_date 01 31 1990 23 59 59 MM DD YYYY HH24 MI SS TSCount FROM ORDTDEV Stocks_TS WHERE ticker AONE
172. he frequency and pattern of the calendar Calendar Functions Reference 4 23 InsertExceptions If a date to be inserted is already an exception in the calendar the function ignores the request to insert the date If newExcDate or newExcTab is empty or null or if all dates to be inserted already exist in the calendar as exceptions the function returns the input calendar with no changes Example Insert some exceptions into a calendar CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE FORMAT MM DD YYYY HH24 MI SS DECLARE tstCal ORDSYS ORDTCalendar tstDTab ORDSYS ordtDateTab resultCal ORDSYS ORDTCalendar dummyVal INTEGER relOffset INTEGER BEGIN Select a calendar say GENERIC CAL1 into tstCal from stockdemo_calendars SELECT value cal INTO tstCal FROM ORDTDEV stockdemo_calendars cal WHERE cal name GENERIC CAL1 Display the calendar SELECT ORDSYS TimeSeries Display tstCal INTO dummyVal FROM dual DBMS_OUTPUT NEW_LINE Populate tstDTab with some on and off exceptions tstDTab ORDSYS ORDTDateTab 02 10 1996 ON Exception 07 09 1996 OFF Exception 03 17 1996 ON Exception 04 08 1996 OFF Exception SELECT ORDSYS TimeSeries Display tstDTab Input DateTab INTO dummyVal FROM dual
173. hin the time series for which the subtraction is to be performed If endDate is specified startDate must also be specified The function performs a pairwise subtraction operation on each element of ts1 decreasing it by either the corresponding element in ts2 or by k This operation determines the value of each element of the returned time series For example a If two time series contain daily trade volumes for two stocks each element of the returned time series contains the result of subtracting the ts2 volume from the ts1 volume for that day a Ifa time series ts1 contains closing prices for a stock and if a constant k of 1 is specified each element of the returned time series contains the closing price of ts1 decreased by 1 If ts1 and ts2 are specified the function returns a time series whose calendar is the result of using the CombineCals function on the calendars associated with these two time series An exception is returned if any of the following conditions is true a An input time series is null a An input time series does not have an associated calendar a The calendars associated with ts1 and ts2 do not have the same frequency and aligned pattern a endDate is earlier than startDate Subtract the low price for stock FUNCO from the high price for stock ACME for each trading day from 14 Nov 1996 through 14 Dec 1996 CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE_FORMAT MM DD YYYY
174. id on exception O_DATE 01 13 1996 Duplicate on exception O_DATE 01 14 1996 Duplicate on exception O_DATE 02 24 1996 Duplicate on exception O_DATE 03 23 1996 Duplicate on exception O_DATE 01 17 1996 Added to on and off exceptions O_DATE 05 28 1996 Added to on and off exceptions O_DATE 06 18 1996 Added to on and off exceptions O_DATE 04 23 1996 Added to on and off exceptions O_DATE 01 06 1996 Valid but out of sequence O_DATE 02 03 1996 O_DATE 05 04 1997 BEGIN SELECT ORDSYS TIMESERIES Display tstCall tstCall INTO dummyval FROM dual validFlag ORDSYS CALENDAR IsValidCal tstCall1 IF validFlag 0 THE validFlag ORDSYS CALENDAR ValidateCal tstCall outMessage invOnExc invOffExc impOnExc impOffExc y ORDSYS TIMESERIES DisplayValCal validFlag outMessage invOnExc invoff impOnExc impOffExc tstCall Your Message EXC Calendar Functions Reference 4 13 DisplayValCal Procedure END IF END This example might produce the following output tstCall Calendar Name CAL Frequency 4 ENDAR FOO MinDate 01 01 1975 00 00 00 MaxDate patBits 1111100 01 01 1999 00 00 00 patAnchor 01 08 1996 01 01 01 onExcept ions 02 08 1969 2 20 1999 3 18 1996 2 1
175. ies Cartridge User s Guide TSDivide DECLARE tstCal ORDSYS ORDTCalendar startDate date endDate date dummyval INTEGER BEGIN startDate TO_DATE 11 14 1996 endDate TO_DATE 12 14 1996 SELECT ORDSYS TimeSeries Display ORDSYS TimeSeries TSDivide ts1 high ts2 low startDate endDate TSDivide Results INTO dummyval FROM ORDTDEV stockdemo_ts tsl ORDIDEV stockdemo_ts ts2 WHERE tsl ticker ACME and ts2 ticker FUNCO END This example might produce the following output TSDivide Results Calendar Data Frequency 4 MinDate 01 01 1990 00 00 00 MaxDate 01 01 2001 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions offExceptions 11 28 1996 00 00 00 12 25 1996 00 00 00 Series Data Date Value 11 14 1996 00 00 00 2 8906577293674067867 616254713028 9065773 11 15 1996 00 00 00 2 93624161073825503355704697986577181208 11 18 1996 00 00 00 2 974444 9099287808 9652283200670297444491 11 19 1996 00 00 00 3 01886792452830188679245283018867924528 11 20 1996 00 00 00 3 0646515533165407220822837951301427372 11 21 1996 00 00 00 3 10402684563758389261744966442953020134 11 22 1996 00 00 00 3 1446540880503144654088050314465408805 11 25 1996 00 00 00 3 19193616127677446451070978580428391432 11 26 1996 00 00 00 3 23801513877207737594617325483599663583 Time Series and Time Scaling Functions
176. ies reflecting the sum of each scaled group of values ts The input time series calendar The calendar to be used for the scaling startDate The starting date to be used If startDate is specified endDate must also be specified endDate The ending date to be used If endDate is specified startDate must also be specified An exception is returned for any of the following conditions a The input time series the calendar on which the input time series in based or the specified calendar is null a The frequency of the calendar on which the time series is based is greater than the frequency of the specified calendar for example the time series calendar s frequency is month and the specified calendar s frequency is day 5 88 Oracle8 Time Series Cartridge User s Guide ScaleupSum Example For an explanation of concepts related to time scaling see Section 2 9 Return the sum of the daily trade volume for stock SAMCO for each month in the entire time series SELECT FROM THE SELECT CAST ORDSYS TimeSeries ExtractTable ORDSYS TimeSeries ScaleupSum ts volume sc calendar AS ORDSYS ORDTNumTab FROM ORDTDEV stocks_ts ts ordtdev scale sc WHERE ts ticker SAMCO and sc name MONTHLY This example might produce the following output TSTAMP VALUE 01 JAN 90 3117750 01 FEB 90 2036500 01 MAR 90 1424375 01 APR 90 981500 01 MAY 90 1348875 01 JUN
177. ime Series Cartridge has encountered a calendar with a null mind ate or maxdate Action Ensure that all calendars have a valid mindate and maxdate TS 00529 calendar mindate is greater than its maxdate Cause The Time Series Cartridge has encountered a calendar with mindate gt maxdate Action Ensure that all calendars have a valid mindate lt maxdate TS 00530 series indexes must be greater than 0 Cause GetNthElement encountered an index less than 1 Action Use indexes greater than 0 TS 00531 the input time series has a null calendar reference Cause The Time Series Cartridge has encountered a time series with a null cal endar reference Action Ensure that all calendar references are valid TS 00532 unable to DEREF calendar referenced by time series Cause The Time Series Cartridge was unable to dereference a calendar refer ence Action Verify that the user executing the query has select privileges for the calendar table storing the object and that the correct calendar has been refer enced by the time series ref TS 00533 the time series has data beyond its calendar mindate maxdate Cause The Time Series Cartridge has encountered a time series with data beyond mindate maxdate Action Ensure that all timestamps in a time series are within the calendar s mindate maxdate TS 00534 the number of rows requested must be a positive integer Cause The requested number of rows was less than 0
178. ime period such as a daily summary indicating the trade volume and the opening high low and closing prices for each stock traded that day This sum mary data is collected to produce historical data such as a table of all daily vol umes and opening high low and closing prices for all stocks traded for the year 1997 For example Figure 2 1 shows how data related to securities on a stock exchange is generated 2 2 Oracle8 Time Series Cartridge User s Guide Overview of Time Series Data Figure 2 1 Data Generation in Equities Markets Daily Snapshot or Summary Data Historical Data Stock Exchange CCC Be CO Terr ty Dee cos TTT Tr gt Tick Data Applications that use the data Daily Newspapers Charting Tools Quote Servers Technical Analysis Tools NU 3691A RA In Figure 2 1 each trade on the stock exchange includes several items of informa tion including a ticker and a price for example stock XYZ at 37 50 The daily sum mary data includes the opening high low and closing prices for each ticker for example for XYZ 37 75 38 25 37 00 37 625 The daily data for each ticker is appended to the historical data for the ticker The daily data is used for such pur poses as quote server applications and listing in the next day s newspapers the his torical data is used by such applications as price and volume charting and technical analysis The data collection model for historical data has the following cha
179. imestamps Usage A timestamp is invalid if any of the following conditions is true a Itis outside the date range of the calendar a Itis an off exception in the calendar a Itis not sufficiently precise for example a timestamp of 01 Jul 1997 if the calen dar has a frequency of year a Itisnull startDate and endDate are included in the check for valid timestamps Calendar Functions Reference 4 61 TimeStampsBetween If there are no valid timestamps in the date range the function returns an empty ORDTDateTab If startDate is greater later than endDate an exception is raised Contrast this function with InvalidTimeStampsBetween which returns a table con taining the invalid timestamps in a date range Example Return a table of valid timestamps between 03 Mar 1996 and 03 Jun 1996 in the GENERIC CAL1I calendar CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE FORMAT MM DD YYYY HH24 MI SS DECLARE tstCal ORDSYS ORDICalendar tstDatel DATE tstDate2 DAT resultDTab ORDSYS ordtDateTab dummyVal INTEGER relOffset INTEGER CI GI se BEGIN Select a calendar say GENERIC CAL1 into tstCal from stockdemo_calendars SELECT value cal INTO tstCal FROM ORDTIDEV stockdemo_calendars cal WHERE cal name GENERIC CAL1 Display the calendar SELECT ORDSY
180. ine multiple calendars that have the same frequency and pattern but different exception lists The first approach is less efficient than the second approach in this case because the internal implementation of the first approach generates a collection of dates based on the input calendar parameter If you need to derive exceptions for multiple calendars defined on the same frequency and pattern this date generation operation is per formed multiple times You can avoid these multiple date generation operations by using the second approach Section 3 3 contains more detailed information about using each approach to deriv ing calendar exceptions 2 3 Time Series Cartridge Architecture Figure 2 3 shows the Time Series cartridge architecture At the lowest level a stor age option is required and for the initial release this must be a flat index organized table IOT For future releases nested IOT and VARRAY storage options are planned The actual cartridge consists of PL SQL packages for calendar time series and time scaling functions In addition a collection based interface between time series storage and the packaged functions is provided 2 10 Oracle8 Time Series Cartridge User s Guide Storage of Time Series Data Figure 2 3 Time Series Architecture PL SQL Packages Time Series Storage NU 3690A RA The rest of this chapter describes this architecture working from bottom to top in Figure 2 3 storage of time serie
181. input time series in based or the specified calendar is null 5 76 Oracle8 Time Series Cartridge User s Guide ScaleupAvg Example a The frequency of the calendar on which the time series is based is greater than the frequency of the specified calendar for example the time series calendar s frequency is month and the specified calendar s frequency is day Nulls are ignored in computing the average for each group of values For an explanation of concepts related to time scaling see Section 2 9 Return the average closing prices for stock SAMCO for each month for the entire time series SELECT FROM THE SELECT CAST ORDSYS TimeSeries ExtractTable ORDSYS TimeSeries ScaleupAvg ts close sc calendar AS ORDSYS ORDTNumTab FROM ORDTDEV stocks_ts ts ordtdev scale sc WHERE ts ticker SAMCO and sc name MONTHLY This example might produce the following output TSTAMP VALUE 01 JAN 90 29 7074045 01 FEB 90 29 0477211 01 MAR 90 30 7003091 01 OCT 96 42 7717391 01 NOV 96 39 83125 01 DEC 96 38 2738095 84 rows selected Time Series and Time Scaling Functions Reference 5 77 ScaleupCount ScaleupCount Format Description Parameters Usage ORDSYS TimeSeries ScaleupCount ts ORDSYS ORDTNumSerieslOTRef calendar ORDSYS ORDTCalendar stariDate DATE endDate DATE RETURN ORDSYS ORDTNumSeries Given a time series a calendar to be used for scali
182. is based ExtractDate Given an element in a time series returns the date ExtractTable Given a time series returns the time series table ORDTNumTab or ORDTVarchar2Tab associated with the time series ExtractValue Given an element in a time series returns the value stored in it Time Series Concepts 2 27 Time Series Functions 2 8 6 Aggregate Functions Aggregate functions return scalar or ORDTNumTab values Each aggregate func tion can be used in either of the following ways a The function accepts a numeric time series ORDTNumSeries and operates on all elements of the collection a The function accepts a numeric time series ORDTNumSeries and a date range bounded by datel and date2 The function is computed on the time series defined by the date range Thus each aggregate function is of the form f ts ORTDNumSeries datel DATE date2 DATE Table 2 9 Aggregate Functions Function Returns TSAvg Average mean of a time series TSCount Number of elements in a time series TSMax Maximum value of a time series TSMaxN Specified number of top highest values in a time series TSMedian Middle element of a time series TSMin Minimum value of a times series TSMinN Specified number of bottom lowest values in a time series TSProd Product of the elements of a time series TSStddev Standard deviation square root of VAR TSSum Sum of the elements of a time series TSVariance Variance analogous
183. is valid No errors were found 1 Correctable errors were found and corrected The resulting calendar is valid 1 Uncorrectable errors were found The calendar is not valid Oracle8 Time Series Cartridge User s Guide DisplayValCal Procedure Usage Example outMessage Message output by ValidateCal describing how the calendar was repaired if the return value 1 or why the calendar could not be repaired if the return value 1 invOnExc Table of the invalid on exceptions found in the calendar invOffExc Table of the invalid off exceptions found in the calendar impOnExc Table of the imprecise on exceptions found in the calendar impOffExc Table of the imprecise off exceptions found in the calendar inputCal The calendar returned by ValidateCal repaired if necessary mesg Optional message This procedure is intended to be used with the ValidateCal function See the infor mation on ValidateCal in this chapter Use the IsValidCal and ValidateCal functions and the DisplayValCal procedure with an invalid calendar CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON ALTER SESSION SET NLS DATE FORMAT MM DD YYYY HH24 MI SS DECLARE outMessage varchar2 32750 invOnExc ORDSYS ORDTDateTab invOffExc ORDSYS ORDTDateTab impOnExc ORDSYS ORDTDateTab impOffExc ORDSYS ORDTDateTab dummyval integer Calendar Functions Reference 4 11 DisplayValCal Procedure
184. ker PATTERN ONLY and ts2 ticker cal name WHERE cal name lt gt PATTERN ONLY This approach Approach 2 to deriving calendar exceptions has the following requirements a The input parameters to the DeriveExceptions function must be either two ORDTNumSeriesIOTRef parameters or two ORDTVarchar2SeriesIOTRef parameters ORDTNumSeries and ORDTVarchar2Series variants are not sup ported for this function Calendars of the time series input parameters must have the same frequency and pattern a The first time series parameter PATTERN ONLY time series must have no exceptions a The starting date minDate of the calendar of the second time series must be greater later than or equal to the starting date of the calendar of the first time series The ending date maxDate of the calendar of the second time series must be less earlier than or equal to the ending date of the calendar of the first time series 3 4 Using Product Developer Functions Product developer functions described in Section 2 7 2 let you modify and expand the Time Series cartridge capabilities For example an ISV could develop addi tional time series analysis functions by calling product developer functions The following example shows the use of the IsValidDate NumTstampsBetween and OffsetDate product developer functions in a PL SQL implementation of the Lead function The Lead function inputs a time series and a
185. king transactions are typically collected daily and are naturally modeled with time series A time series can be regular or irregular depending on how predictably data points arrive or occur Ina regular time series the data arrives predictably at predefined intervals For example daily summaries of stock market data form a regular time series and one such time series might be the set of trade volumes and opening high low and closing prices for stock XYZ for the year 1997 Time Series Concepts 2 1 Overview of Time Series Data a nan irregular time series unpredictable bursts of data arrive at unspecified points in time or most timestamps cannot be characterized by a repeating pat tern For example account deposits and withdrawals from a bank automated teller machine ATM form an irregular time series An irregular time series may have long periods with no data or short periods with bursts of data 2 1 1 Data Generation for a Time Series Data generation for a time series begins with individual transactions such as trades on a stock exchange or purchases of products Each transaction has a timestamp and sufficient information to identify that transaction uniquely such as a stock ticker or a product ID as well as other pertinent information such as the price and information to identify the party initiating the purchase or sale Individual transaction data is typically rolled up to produce summary data for a meaningful t
186. l For example a GT comparison of 30 Jun 1997 and null returns null Note that because PL SQL does not implement UNKNOWN these semantics are slightly different than the SQL treatment of comparisons with nulls In SQL a comparison operator that encounters a null returns UNKNOWN which is like a null except that operations on UNKNOWN return UNKNOWN a Scaleup functions return a null if all timestamps for a scaling interval contain nulls For example if you are scaling up daily data from 01 Jan 1997 through 30 Jun 1997 to monthly data and if there are no values for the month of February a null is returned for February and scaled data is returned for the other months Note that this behavior differs from the standard GROUP BY scaling in SQL in which February would be missing in the scaled results Some functions allow alternate semantics in the form of an option The reference information for each function describes any alternate semantics options 2 8 2 2 Semantics of Off Exception Operands In comparisons of two time series it is possible that a timestamp valid for one time series is not valid for the other time series Operations on two time series having similar calendars return a time series that is defined over a new calendar This new calendar is derived from the two input calendars using all of the following a the union of the off exceptions a the intersection of the on exceptions a bounded by min maxDate1 maxDate2 m
187. le if cal1 has 30 Mar and 29 Jun as on exceptions and cal2 has 29 Jun and 28 Sep as on exceptions the resulting calendar has only 29 Jun as an on exception Calendar Functions Reference 4 27 IntersectCals a The union of the off exceptions of the two calendars is computed For example if call has 01 Jan and 04 Jul as off exceptions and cal2 has 01 Jan and 14 Jul as off exceptions the resulting calendar has 01 Jan 04 Jul and 14 Jul as off excep tions If the frequencies of the two calendars are not equal the function returns NULL Contrast this function with UnionCals which performs a union of two calendars IntersectCals and CombineCals differ as follows CombineCals requires the frequencies and the aligned patterns of the two cal endars to be equal whereas IntersectCals requires only that the frequencies be equal However IntersectCals does require that the patterns be of the same length CombineCals lets you specify starting and ending dates for the resulting calen dar whereas IntersectCals does not let you specify starting and ending dates Example Combine two calendars GENERIC CAL1 and GENERIC CAL2 then intersect the two calendars CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON ALTER SESSION SET NLS DATE FORMAT MM DD YYYY HH24 MI SS DECLARE tstCall ORDSYS ORDTCalendar tstCal2 ORDSYS ORDTCalendar resultCal ORDSYS ORDTCalendar equalFlag INTEGER
188. lected Time Series and Time Scaling Functions Reference 5 47 GetSeries GetSeries Format Description Parameters Usage Example ORDSYS TimeSeries GetSeries ts ORDSYS ORDTNumSeries OT Ref RETURN ORDSYS ORDTNumSeries or ORDSYS TimeSeries GetSeries ts ORDSYS ORDTVarchar2SerieslOTRef RETURN ORDSYS ORDTVarchar2Series Given a reference to a time series of references ORDTNumSeriesIOTRef or ORDTVarchar2SeriesIOTRef returns a time series instance ORDTNumSeries or ORDTVarchar2Series ts The input time series The function materializes the input time series An exception is returned if the time series ts is null Return an instance of a specified time series opening prices for stock ACME SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE_ FORMAT MM DD YYYY HH24 MI SS DECLARE dummyval INTEGER BEGIN 5 48 Oracle8 Time Series Cartridge User s Guide GetSeries SELECT ORDSYS TimeSeries Display ORDSYS TimeSeries GetSeries ts open GetSeries Results INTO dummyval FROM ORDTIDEV stockdemo_ts ts WHERE ts ticker ACME END This example might produce the following output GetSeries Results Name ACME open NumSeries Calendar Data Calendar Name BUSINESS 96 Frequency 4 MinDate 01 01 1990 00 00 00 MaxDate 01 01 2001 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept i
189. lendar say GENERIC CAL1 into tstCal from stockdemo_calendars SELECT value cal INTO tstCal FROM ORDTDEV stockdemo_calendars cal WHERE cal name GENERIC CAL1 Display the calendar SELECT ORDSYS TimeSeries Display tstCal INTO dummyVal FROM dual DBMS_OUTPUT NEW_LINE Delete some exceptions in tstCal tstDTab ORDSYS ORDTDateTab 01 21 1996 ON Exception 05 08 1996 OFF Exception 08 04 1996 ON Exception 07 09 1996 OFF Exception SELECT ORDSYS TimeSeries Display tstDTab Input DateTab INTO dummyVal FROM dual resultCal ORDSYS Calendar DeleteExceptions tstCal tstDTab 4 8 Oracle8 Time Series Cartridge User s Guide DeleteExceptions SELECT ORDSYS TimeSeries Display resultCal INTO dummyVal FROM dual END This example might produce the following output The second display of informa tion about GENERIC CAL1 does not include the deleted on exceptions and off exceptions Calendar Name Frequency 4 GEN ERIC CAL1 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1996 00 00 00 patBits 0111110 01 0 patAnchor onException 01 21 1 04 27 1 07 07 1 of fExceptio 01 08 1 04 04 1 07 09 1 s 996 996 996 ns 996 996 996 Input DateTab 01 21 1 07 09 1 996 996 Calendar Name Frequency 4 00 00 00 00 00
190. loads on underlying tables instead of on security views However after you load data into the tables you must ensure time series consistency by using one of the following approaches Adjust calendars to be consistent with the time series If you are sure that all timestamps are correct it is safe to adjust the calendar to be consistent with the time series This strategy is normally appropriate when there is a unique calendar per time series The DeriveExceptions function is useful for adjusting a calendar to be consis tent with the time series Validate that each time series is consistent with the calendar If you expect time series data to adhere to a predefined calendar validating each time series is the better approach This approach is particularly useful if the same calendar is used for all time series data being loaded The IsValidTimeSeries function can be used to check if the time series is consis tent with the calendar For better performance in the case of a shared calendar for all time series you may want to customize time series validation using PL SQL This involves writing custom utility functions that call Time Series cartridge product devel oper calendar functions see Section 2 7 2 to test and maintain time series con sistency Section 3 2 contains additional information and examples of bulk and incremental loading of time series data 2 7 Calendar Functions The Time Series cartridge provides calendar func
191. lue ExtractValue Format Description Parameters Usage Example ORDSYS TimeSeries ExtractValue cell ORDSYS ORDTNumCell RETURN or NUMBER ORDSYS TimeSeries ExtractValue cell ORDSYS ORDTVarchar2Celf RETURN VARCHAR2 Given an element in a time series returns the value stored in it cell The time series element for which you want the value The time series element must first be identified such as by using the GetNthEle ment function An exception is returned if the time series element cell is null Return the value of the tenth opening price in the stocks_ts table SELECT ORDSYS TimeSeries ORDSYS TimeSeries GetNthElement open 10 FROM ORDTD EV stocks_ts WHERE ticker AONE Ext ractValue This example might produce the following output ORDSYS TIM 5 32 Oracle8 Time Series Cartridge User s Guide ExtractValue 15 1875 1 row selected Time Series and Time Scaling Functions Reference 5 33 Fill Fill Format Description Parameters Usage ORDSYS TimeSeries Fill ts ORDSYS ORDTNumSeriesl OT Ref fill_type INTEGER RETURN ORDSYS ORDTNumSeries Given a time series and optionally a fill type returns a time series in which values for missing dates are inserted A missing date is a date that is defined by the calen dar and within the time series bounds but that is not in the current time series ts The inpu
192. n the minDate and maxDate and all off and on exceptions must be precise with respect to the frequency For example the calendar will not be valid if you specify a frequency of month and an anchor date patAnchor of 02 Jan The calendar datatypes and their attributes are presented in Section 2 2 2 2 6 Oracle8 Time Series Cartridge User s Guide Calendars Table 2 2 shows the frequencies their precision conventions and an example timestamp of each precision Table 2 2 Precisions Frequency Every Precision Convention Example Result M DD YYYY HH24 MI SS M DD YYYY HH24 MI 00 second M M hour MM DD YYYY HH24 00 00 M M minute day M DD YYYY 00 00 00 midnight month M 01 YYYY 00 00 00 midnight of first day of month year 01 01 YYYY 00 00 00 midnight of first day of year 09 09 1997 09 09 09 09 09 1997 09 09 00 09 09 1997 09 00 00 09 09 1997 00 00 00 09 01 1997 00 00 00 01 01 1997 00 00 00 2 2 2 Calendar Datatypes The Time Series cartridge provides the following calendar datatypes Time series datatypes are described in Section 2 8 1 a calendar ORDTCalendar Sections 2 2 3 and 3 1 2 contain calendar definitions with explanatory notes CREATE TYPE ORDSYS ORDTCalendar AS OBJECT caltype INTEGER name VARCHAR2 256 frequency INTEGER pattern ORDSYS ORDTPattern minDate DATE maxDate DATE offExceptions ORDSYS ORDTExceptions onExceptions ORDSYS ORDTExceptions
193. n example that returns the same information but that uses a subquery instead of the Display function Time Series and Time Scaling Functions Reference 5 17 DisplayValTS Procedure DisplayValTS Procedure Format ORDSYS TimeSeries Display ValTS validFlag IN INTEGER outMessage IN VARCHAR2 loDateTab INORDSYS ORDTDateTab hiDateTab INORDSYS ORDTDateTab impreciseDateTab INORDSYS ORDTDateTab duplicateDateTab INORDSYS ORDTDateTab extraDateTab INORDSYS ORDTDateTab missingDateTab INORDSYS ORDTDateT ab mesg IN VARCHAR2 Description Displays the results returned by the ValidateTS function Note DisplayValTS is a procedure not a function Procedures do not return values Parameters validFlag The return value from the ValidateTS function outMessage The diagnostic returned by the ValidateTS function loDateTab A table of dates before the starting date of the calendar associated with the time series 5 18 Oracle8 Time Series Cartridge User s Guide DisplayValTS Procedure Usage Example hiDateTab A table of dates after the starting date of the calendar associated with the time series impreciseDateTab A table of the imprecise dates found in the time series duplicateDateTab A table of the duplicate dates dates that appear more than once in the time series extraDateTab A table of dates that are included in the time series but that should be excluded based on the calendar d
194. nce both the Lead and Lag functions are provided The functions oper ate identically except that they interpret the sign of the units value in opposite ways For example Lead with 10 for units is equivalent to Lag with 10 for units Moreover because of the way the lead_date parameter is interpreted Lead and Lag with a lead_date operate identically Return a time series starting with 03 Mar 1997 using closing prices from the time series from 01 Nov 1996 through 30 Nov 1996 for stock ACME The returned time series has the same number of timestamps as are in the specified date range start Date through endDate SELECT FROM the SELECT CAST ORDSYS TimeSeries Extract Table ORDSYS TimeSeries Lag ts close to_date 03 MAR 97 DD MON YY to_date 01 NOV 96 DD MON YY to_date 30 NOV 96 DD MON YY AS ORDSYS ORDTNumTab FROM ORDTDEV stockdemo ts ts WHERE ts ticker ACME This example might produce the following output 03 MAR 97 59 04 MAR 97 60 05 MAR 97 61 06 MAR 97 62 07 MAR 97 63 10 MAR 97 64 27 MAR 97 77 28 MAR 97 78 20 rows selected Time Series and Time Scaling Functions Reference 5 61 Last Last Format Description Parameters Usage Example ORDSYS TimeSeries Last ts ORDSYS ORDTNumSerieslOTRef RETURN ORDSYS ORDTNumCell Given a time series returns the last element in it ts The input time
195. ndDate is not specified the ending date of the resulting calendar is the earlier of the ending dates of the two calendars that is resulting maxDate min maxDatel maxDate2 The function intersects the on exception lists of the two calendars For example if call has 30 Mar and 29 Jun as on exceptions and cal2 has 29 Jun and 28 Sep as on exceptions the resulting calendar has only 29 Jun as an on exception The function performs a union of the off exceptions of the two calendars For exam ple if cal1 has 01 Jan and 04 Jul as off exceptions and cal2 has 01 Jan and 14 Jul as off exceptions the resulting calendar has 01 Jan 04 Jul and 14 Jul as off exceptions CombineCals and IntersectCals differ as follows a CombineCals requires the frequencies and the aligned patterns of the two cal endars to be equal whereas IntersectCals requires only that the frequencies be equal However IntersectCals does require that the patterns be of the same length CombineCals lets you specify starting and ending dates for the resulting calen dar whereas IntersectCals does not let you specify starting and ending dates Combine two calendars GENERIC CAL1 and GENERIC CAL2 then intersect the two calendars CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON ALTER SESSION SET NLS DATE FORMAT MM DD YYYY HH24 MI SS DECLARE Calendar Functions Reference 4 3 CombineCals tstCall ORDSYS ORDTCalendar tstCal2
196. ndar or ORDSYS TimeSeries DeriveExceptions series ORDTVarchar2SerieslOTRef series2 ORDTVarchar2SerieslOTRef RETURN ORDSYS ORDT Calendar Description Derives calendar exceptions from a calendar and a table of dates Approach 1 or from two time series Approach 2 Parameters inputCal The calendar that contains no exceptions and for which exceptions are to be derived Time Series and Time Scaling Functions Reference 5 13 DeriveExceptions Usage Example DateTab The table of dates that includes all dates in the time series for example all dates on which stock XYZ traded series1 The reference time series that contains no exceptions and all valid timestamps from the calendar for example all Monday through Friday dates within the date range of the calendar series2 The time series that contains the timestamps to be used in deriving the exceptions for the resulting calendar for example all dates on which stock XYZ traded See Section 2 2 4 for a detailed explanation of the two approaches to using this func tion See Sections 3 3 1 and 3 3 2 for examples of the two approaches to using this func tion 5 14 Oracle8 Time Series Cartridge User s Guide Display Display Format Description Parameters ORDSYS TimeSeries Display ts ORDSYS see parameter description Lmesg VARCHAR2 RETURN INTEGER Displays various information see the description of the ts parameter using DBMS_
197. ng and optionally starting and ending dates returns a time series reflecting the count of non null timestamps in each scaled group ts The input time series calendar The calendar to be used for the scaling startDate The starting date to be used If startDate is specified endDate must also be specified endDate The ending date to be used If endDate is specified startDate must also be specified An exception is returned for any of the following conditions a The input time series the calendar on which the input time series in based or the specified calendar is null 5 78 Oracle8 Time Series Cartridge User s Guide ScaleupCount Example a The frequency of the calendar on which the time series is based is greater than the frequency of the specified calendar for example the time series calendar s frequency is month and the specified calendar s frequency is day Nulls are ignored in computing the count for each group of values For an explanation of concepts related to time scaling see Section 2 9 Return the quarterly count of daily closing prices for stock SAMCO for the period 01 June 1996 through 31 December 1996 SELECT FROM THE SELECT CAST ORDSYS TimeSeries ExtractTable ORDSYS TimeSeries ScaleupCount ts close sc calendar to_date 01 JUL 1996 DD MON YYYY to_date 31 DEC 1996 DD MON YYYY AS ORDSYS ORDTNumTab FROM ORDTDEV stocks_ts ts ordtdev scale sc W
198. nonencnnananannoninnonanoncnnnonononanonononananonanonos 2 18 2 6 1 Rules for Time Series Consistency cccccconononacinananononanoncnncnnononnnnonancannonononanononononanananonos 2 18 2 6 2 Enforcing Time Series Consistency with Security Views ocococincnnononncncononaranananonos 2 18 2 6 3 Bulk Loading and Consistency ococicionnnnononconononinnoninnonincnnaninnonanancannononanananononananananonos 2 20 2 7 Calendar Functions Volar tdi eatin 2 20 2 7 1 End Us r Functions ui Sie Shee nie 2 21 2 7 2 Product Developer FunctiONS ocncncncnconinononinananononononcnnoncnnnnnononononononanonanonononananananonos 2 21 2 8 Time Series FUunctiOns 22 A dd 2 23 2 8 1 Time Series Datatypes ersinnen teer napainen iane Eia Sa REE aSa ia aea St 2 23 2 8 2 Conventions and Semantics scssi i ii ias 2 24 2 8 3 Extraction Retrieval and Trim Functions c ccccccssscessecsseeesceessceeseceseecsseeesseeseees 2 26 2 8 4 Shift FunetiOns A ide iseaniteadnahsn ativan a s etaa aaas 2 27 2 8 5 SOL Formatting Functions sitiada aladdin it 2 27 2 8 6 Aggregate FUNCTIONS cccccsesceseseescsesesesensesceeseeescsesesessesesesesseecesssseseseesssensseessenaeeses 2 28 2 8 7 Arithriietic BunCtiOns is te 2 fa sie est asics a 2 28 2 8 8 Cumulative Sequence FunctiONS ociciconononinnononnononcnnoninannnninnononancnononanonananononananananonos 2 29 2 8 9 Moving Average and Sum FunctiONS ococionoionnnoncnnoninnnonnononononcnononanananonononaranananonos 2 29 2 8 1
199. noninnorinnonincnnononcnnnnnono non cn nacio non an co nennanananons 3 16 4 Calendar Functions Reference CombineCalS id it A a a As 4 2 Del teEXceptlonse iia da ada nati tdi cis 4 7 DisplayValCal Procedente die Iria 4 10 Equ Cad 0 A A AAA ea aie a 4 17 CAOS A tos 4 20 MES AAA penenie eesi kean Aeneis R AEEA ra En Ee AENEA ERNEA SERA eE PENE EESE 4 23 IntersectCals ci A A aa a 4 27 InvalidTimeStampsBetweeh innisis iaa 4 31 IV Md Call EEE A EE E OEI 4 34 TS Vall Date nnn A sa 4 40 NumlInvalidTimeStampsBetween sessssssssessssiesieriestessesisstestesseniesiestnsnententesennneneeeese 4 43 NuimOffExceptionss nnne e eaa e A e anda Aedes Saeed 4 46 INUMONEXCEp ONS soria dit a e e a eed A AAA 4 49 Num FimieStam psBetw Cen wissic sciss icesssensiidisatecuesveessy eiaa dit iii 4 52 OSA Dt A A ce SRE Sea eA Seas 4 55 SOtPLE CISION A A A Abt 4 58 TimeStampsBel Wee nimentasada talca io tdi iii illes 4 61 Unas as 4 65 ValidateGall vic s ceils hxc A A A Geeta ied 4 69 5 Time Series and Time Scaling Functions Reference vi Cant dale isa ral dos 5 3 EM AAA A A Ai 5 5 A RR 5 7 A A irate lhe sisted Me bit tate tta dial tastes ble abies i 5 9 CS UTI eases abs E RR 5 11 Derive Exceptions inerea eiea ana NASEN RENEA ARNESE AER NEEE AEE 5 13 Display osne m AE a Ea E E a A E A 5 15 DisplayValTS Procede incio cid EE E E A RA 5 18 eD n ae a e T EEA EAE A E EE EE 5 26 EXxtractDate ist dad NE 5 28 ExtractTaDle ii Aa 5 30 Extract Value ii A as 5
200. ns the following chapters and appendix Introduces data cartridges object types and the contents of the Time Series car tridge Explains time series concepts and operations Explains important procedures for using the cartridge Provides reference information on calendar functions Provides reference information on time series and time scaling functions Lists potential errors their causes and user actions to correct them Related Documents For information added after the production of this manual see the README file in the following directory a ORACLE HOME ord ts admin Solaris systems xiii a ORACLE HOME ord80 ts admin Windows NT systems The location of the README file is platform dependent For more information see the following manuals in the Oracle8 documentation set a PL SQL User s Guide and Reference a Oracle Call Interface Programmer s Guide a Oracle8 Application Developer s Guide Conventions In this manual the Oracle8 Time Series Cartridge is sometimes referred to as the Time Series cartridge The following conventions are also used in this manual Convention Meaning boldface text italicized text A vertical ellipsis in an example means that lines not directly related to the example have been omitted A horizontal ellipsis in an example means that part of the statement or command not directly related to the example has been omitted Boldface type in text indicates a term de
201. of 30 day moving sum values of trading volume for stock AONE for 1996 SELECT FROM THE SELECT CAST ORDTS Extract ORDTS MSUM volume to date 01 01 96 MM DD YyY to date 12 31 96 MM DD YY 30 AS ORDTNumTab FROM StockTabView WHERE ticker AONE Time Series and Time Scaling Functions Reference 5 73 Scaleup Scaleup Format Description Parameters Usage Example ORDSYS TimeSeries Scaleup inDate DATE calendar ORDSYS ORDTCalendar RETURN DATE Given an input ORDTCalendar and a date returns a scaled date inDate The date to be used for scaling calendar The calendar to be used for scaling the date For an explanation of concepts related to time scaling see Section 2 9 This function is used in a SOL GROUP BY clause for scaling of dates An exception is returned if inDate or calendar is null For all tickers accessible through the stockdemo_sv view ACME FUNCO SAMCO and XCORP scale daily data to monthly summary data for the summed volume and average closing price Scaleup Group By interface For all tickers in stockdemo scale daily data to monthly summary data reporting summed volumes and average closes SELECT ticker ORDSYS TimeSeries Scaleup sv tstamp value cal sum volume avg close 5 74 Oracle8 Time Series Cartridge User s Guide Scaleup FROM ORDTD WHERE cal name EV s
202. olumn name tstamp a qualifying column name ticker and the actual value of the qualifying column meta tickername The implementation of time series functions uses the information stored in the ORDTNumSeriesIOTRef type to generate the appropriate dynamic SQL statement at runtime Using the preceding example to instantiate a time series object that is to convert an ORDTNumSeriesIOTRef to an ORDTNumSeries the Mavg function generates a query that performs the following action with the logic shown not the exact syntax SELECT tstamp close FROM ordtdev stockdemo_ts WHERE ticker ACME and tstamp BETWEEN lt a date range adjusted to reflect the 10 day window and the calendar including any holidays gt The Mavg function computes the moving average and returns the result as a time series instance ORDTNumSeries For more information about the Mavg function see Section 2 8 9 Time Series Concepts 2 17 Consistency of Time Series Data 2 6 Consistency of Time Series Data Most time series and time scaling functions rely on calendars that are consistent with time series data By assuming a time series is consistent with its calendar time series and time scaling functions can use the calendar as a basis for navigation of time series data Time series consistency must be maintained otherwise functions might raise exceptions or return incorrect results 2 6 1 Rules for Time Series Consistency For
203. on Parameters Usage Example ORDSYS Calendar NumOnExceptions inputCal INORDSYS ORDTCalendar startDate IN DATE endDate IN DATE RETURN INTEGER Given starting and ending input timestamps returns the number of on exceptions within that range according to the specified calendar inputCal The calendar to be used in computing the number of on exceptions startDate Starting date in the range to be checked for on exceptions endDate Ending date in the range to be checked for on exceptions startDate and endDate are included in the check for on exceptions For an explana tion of off exceptions and on exceptions see Section 2 2 If startDate is greater later than endDate an exception is raised Return the number of on exceptions between 02 Feb 1996 and 07 Jul 1996 in the GENERIC CAL calendar CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON Calendar Functions Reference 4 49 NumOnExceptions ALTER SESSION SET NLS_DATE_ FORMAT MM DD YYYY HH24 MI SS DECLARE tstCal ORDSYS ORDTCalendar tstDatel DATE tstDate2 DATE result INTEGER dummyVal INTEGER BEGIN Select a calendar say GENERIC CAL1 from stockdemo_calendars SELECT value cal INTO tstCal FROM ORDTIDEV stockdemo_calendars cal WHERE cal name GENERIC CAL1 Display the calendar SELECT ORDSYS TimeSeries Display tstC
204. on in the Oracle8 Server Utilities manual a The APPEND keyword is specified so that the new data is appended to the existing tabular data 3 3 Deriving Calendar Exceptions This section explains in greater detail the two approaches to deriving calendar exceptions from time series data These two approaches were introduced in Section 2 2 4 see that section for information on concepts related to exceptions and the reasons for choosing a particular approach 3 3 1 Deriving Exceptions Using a Calendar and Table of Dates Approach 1 The first approach to deriving exceptions takes a calendar and an ORDTDateTab that is a table of dates as input parameters using the following form of the func tion DeriveExceptions cal ORDTCalendar DateTab ORDTDateTab The table of dates DateTab parameter includes all dates in the time series for example all dates on which stock XYZ traded A calendar is returned that is defined on the same pattern and frequency as the input calendar and the exception lists of the returned calendar are populated to be consistent with the time series data in DateTab The exception lists are updated based on finding timestamps that are in the calendar pattern or in the table of dates but not in both A timestamp is in the calendar pattern if it is within the date range of the calendar and maps to an on 1 bit in the pattern Time Series Usage 3 13 Deriving Calendar Exceptions The returned calendar s on
205. oncepts manual 3 Install the UTLREF package which is needed by the Time Series cartridge SVRMGR gt SORACLE_HOME rdbms admin utlrefld sql 4 Ifthe ORDSYS account does not already exist create it SVRMGR gt CREATE USER ORDSYS IDENTIFIED BY lt password gt The lt password gt is the password you chose in step 1 5 Set the privileges for ORDSYS user SVRMGR gt GRANT connect resource create library TO ORDSYS 6 Install the Time Series cartridge datatypes and stored procedures Introduction 1 3 Creating Public Synonyms for Time Series Packages SVRMGR gt CONNECT ORDSYS lt password gt SVRMGR gt SORACLE_HOME ord ts admin ordtinst sql The user group PUBLIC is granted execute privilege on all Time Series car tridge datatypes and packages 1 5 Creating Public Synonyms for Time Series Packages All Time Series cartridge packages and datatypes are installed under the ORDSYS schema and all users must include the ORDSYS schema name when referring to these packages and datatypes However to simplify references to packages you can define public synonyms for the Calendar and TimeSeries packages To create public synonyms run the ordtsyn sql file supplied with the Time Series cartridge in the admin directory The ordtsyn sql file creates the following public synonyms CREATE PUBLIC SYNONYM TimeSeries for ORDSYS TimeSeries CREATE PUBLIC SYNONYM Calendar for ORDSYS Calendar
206. ons offExceptions 11 28 1996 00 00 00 12 25 1996 00 00 00 Series Data Date Value 11 01 1996 00 00 00 59 11 04 1996 00 00 00 60 11 05 1996 00 00 00 61 11 06 1996 00 00 00 62 11 07 1996 00 00 00 63 11 08 1996 00 00 00 64 11 11 1996 00 00 00 65 11 12 1996 00 00 00 66 11 13 1996 00 00 00 67 11 14 1996 00 00 00 68 11 15 1996 00 00 00 69 11 18 1996 00 00 00 70 11 19 1996 00 00 00 71 11 20 1996 00 00 00 72 11 21 1996 00 00 00 73 11 22 1996 00 00 00 74 11 25 1996 00 00 00 75 Time Series and Time Scaling Functions Reference 5 49 GetSeries 11 26 1996 00 00 00 76 11 27 1996 00 00 00 77 11 29 1996 00 00 00 78 12 02 1996 00 00 00 79 12 03 1996 00 00 00 80 12 04 1996 00 00 00 81 12 05 1996 00 00 00 82 12 06 1996 00 00 00 83 12 09 1996 00 00 00 84 2 10 1996 00 00 00 85 2 11 1996 00 00 00 86 2 12 1996 00 00 00 87 2 13 1996 00 00 00 88 2 16 1996 00 00 00 89 2 17 1996 00 00 00 90 2 18 1996 00 00 00 91 2 19 1996 00 00 00 92 2 20 1996 00 00 00 93 2 23 1996 00 00 00 94 2 24 1996 00 00 00 95 2 26 1996 00 00 00 96 2 27 1996 00 00 00 97 2 30 1996 00 00 00 98 2 31 1996 00 00 00 99 5 50 Oracle8 Time Series Cartridge User s Guide IsValidTS IsValidTS Format Description Parameters Usage ORDSYS TimeSeries IsValidTS ts INORDSYS ORDTNumSerieslOT Ref RETURN INTEGER or ORDSYS TimeSeries IsValidTS ts INORDSYS ORDTVarchar2SerieslOTRef RETURN INTEGER Returns
207. or details DisplayValCal Procedure TS WRN removed superfluous dates in the on exception list refer invalidOnExc TS WRN fixed imprecise dates in the on exception list refer impreciseOnExc TS WRN removed null dates in the on exception list TS WRN sorted the on exceptions list TS WRN removed duplicate dates in the on exceptions list TS WRN removed superfluous dates in off exceptions list refer invalidOffExc TS WRN fixed imprecise dates in the off exception list refer impreciseOffExc TS WRN removed null dates in the off exception list TS WRN sorted the off exceptions list TS WRN removed duplicate dates in the off exceptions list TS WRN the on exceptions list was trimmed between calendar minDate amp maxDate TS WRN the off exceptions list was trimmed between calendar minDate amp maxDate list of invalid on exceptions 01 03 1996 00 00 00 02 19 1996 00 00 00 03 18 1996 00 00 00 05 27 1996 00 00 00 01 17 1996 00 00 00 05 28 1996 00 00 00 06 18 1996 00 00 00 04 23 1996 00 00 00 list of invalid off exceptions 12 31 1995 00 00 00 01 13 1996 00 00 00 02 24 1996 00 00 00 03 30 1996 00 00 00 list of imprecise on exceptions 03 23 1996 01 01 01 02 18 1996 01 01 01 05 26 1996 01 01 01 list of imprecise off exceptions 02 02 1996 01 01 01 03 04 1996 01 01 01 04 05 1996 02 02 02 the validated calendar Calendar Name CALENDAR FOO Frequency 4 MinDate 01 01 1975 00 00 00 MaxDa
208. or performing an incremental load of such additional data The following example shows a SQL Loader script with an excerpt from the sample daily data stockinc dat and the SQL Loader control file stockinc ctl The SQL Loader script contains the following sqlldr userid ordtdev ordtdev control stockinc ctl log stockinc log bad stockinc bad errors 1000 The stockinc dat sample data file includes the following ACME 02 JAN 97 100 00 101 00 99 00 100 00 1000 FUNCO 02 JAN 97 25 00 25 00 25 00 25 00 2000 SAMCO 02 JAN 97 39 00 40 00 38 00 39 50 30000 The stockinc ctl file contains the following Oracle8 Time Series Cartridge User s Guide Deriving Calendar Exceptions load data infile stockinc dat append into table stockdemo fields terminated by whitespace ticker tstamp DATE 13 DD MON YY open high low close volume Note the following differences in the control file for incremental loading as opposed to bulk loading a The conventional path is used instead of the direct path That is the control file for incremental loading does not contain the line options direct true The conventional path is better for incremental loading because the amount of new data daily stock information is small relative to the total amount of data For an explanation of conventional and direct paths including situations in which the conventional path is necessary or preferable see the SQL Loader documentati
209. orm which can be found either in 0RACLE_HOME ord ts admin UNIX systems or ORACLE_HOME ord80 ts admin Windows NT systems On many platforms automated default installation is available using Oracle Installer however on some platforms manual installation of the database objects is required This section describes the steps required to manually install the Time Series car tridge It is intended for users who want to customize the database installation or who simply want a better understanding of the Time Series installation process To use the Time Series cartridge at least the following software components must be installed Oracle8 Enterprise Edition RDBMS PL SQL on platforms on which it is a separate installation option and the Oracle8 Time Series Cartridge These components can be installed all at once or the Oracle8 Time Series Cartridge can be added to an existing Oracle8 Enterprise Edition release 8 0 4 installation that includes PL SQL Follow these steps to perform a manual installation of the Time Series cartridge 1 If the ORDSYS user does not already exist decide on a password ORDSYS is the standard schema for Oracle supplied cartridges and it has spe cial privileges for data cartridges 2 Create and start the database For detailed information about database creation and startup see the Oracle Installation and Configuration Guide for your operating system the Oracle8 Administrator s Guide and the Oracle8 C
210. p for a specified interval over a range of dates For example the 30 day moving average for a stock is the average of the closing price for the specified date and the 29 trading days preceding it Time Series Concepts 2 29 Time Series Functions The Moving Sum Msum function returns a sum of values from each successive timestamp for a specified interval over a range of dates For example the 30 day moving sum of trading volumes for a stock is the sum of the volume for the speci fied date and for 29 trading days preceding it Table 2 12 Moving Average and Sum Functions Function Returns Mavg Moving average Msum Moving sum The relationship between the input and output time series in the computation of a moving average or sum is illustrated in Figure 2 5 The figure focuses on the com mon invocation of moving average or sum where k is the number of timestamps in the look back window for example 30 and a date range startDate and endDate is supplied For more information about the parameters see the Mavg function description in Chapter 5 Figure 2 5 Relationship of Input and Output Time Series in Moving Average Sum A k Input Time Series BE __ E TT 4 startDate endDate E ers Q Y NU 3692A RA 2 8 10 Conversion Functions Conversion functions fill missing elements of a numeric time series ORDTNum Series Missing elements are those where their timestamps are defined by the cal endar and are in the r
211. p values are to be calculated If endDate is specified startDate must also be specified An exception is returned if any of the following conditions is true a The time series ts is null a The time series ts does not have an associated calendar Time Series and Time Scaling Functions Reference 5 107 TSMaxN a endDate is earlier than startDate a NumValues is zero 0 or negative Example Return the 10 highest closing prices for stock AONE for the month of January 1996 SELECT FROM THE SELECT CAST ORDSYS TimeSeries TSMaxN close 10 to date 01011996 MMDDYYYY to date 01311996 MMDDYYYY as ORDSYS ORDTNumTab FROM ORDTDEV stocks_ts WHERE ticker AONE This example might produce the following output TSTAMP VALUE 24 JAN 96 43 9138 25 JAN 96 42 9925 31 JAN 96 42 9925 26 JAN 96 42 7413 30 JAN 96 42 7413 29 JAN 96 42 5738 23 JAN 96 41 9875 22 JAN 96 41 82 19 JAN 96 41 485 18 JAN 96 40 815 10 rows selected 5 108 Oracle8 Time Series Cartridge User s Guide TSMedian TSMedian Format Description Parameters Usage Example ORDSYS TimeSeries TSMedian ts ORDSYS ORDTNumSeries OT Ref startDate DATE endDate DATE RETURN NUMBER Given an input ORDTNumsSeries and optionally starting and ending dates returns a number corresponding to the median of all non null time series entries
212. playValTS Procedure Add Dates Before numTS cal minDate numTS series 10 tstamp numTS cal minDate 1 numTS series 11 tstamp numTS cal minDate 2 Add Dates Beyond numTS cal maxDate numTS series 12 tstamp numTS cal maxDate 1 numTS series 13 tstamp numTS cal maxDate 2 Add some null timestamps numTS series 14 tstamp NULL numTS series 15 tstamp NULL Add some imprecise dates some are duplicated numTS series 17 tstamp numTS series 16 tstamp 1 24 numTS series 18 tstamp numTS series 16 tstamp 15 24 Add some duplicate timestamps numTS series 19 tstamo numTS series 18 tstamp numTS series 21 tstamo numTS series 20 tstamp Add some extra dates in the middl numTS series 37 tstamo TO _DATE 12 28 1996 numTS series 36 tstamo TO _DATE 12 29 1996 Add some holes at th nd numTS series numTS series count tstamp TO_DATE 01 Example of validating an invalid time series 04 1997 SELECT ordsys timeseries display numTS AN INVALID TI INTO tempVal FROM dual retIsValid ORDSYS TIMESERIES IsValidTS numTS E SERI retValTS ORDSYS TIMESERIES ValidateTS numTS outMesg loDateTab hiDateTab impDateTab ES dupDateTab extraDateTab missingDateTab retIsValid
213. plify the process You can use one of two approaches with DeriveExceptions depending on your needs and the require ments for each approach The first approach uses a DeriveExceptions call with input parameters of a cal endar and an ORDTDateTab instance An ORDTDateTab instance is a collec tion of dates these dates can be compared with the set of valid timestamps implied by the calendar A calendar is returned with the appropriate exception lists populated This returned calendar is defined on the pattern and frequency of the input calendar and it is consistent with the timestamps of the ORDT DateTab instance The second approach uses a DeriveExceptions call with two time series as input parameters The first time series is essentially an expansion of a pattern only calendar As in the first approach a calendar is returned with the appro priate exception lists populated The returned calendar is defined on the pat tern and frequency of the calendar of the first input time series and it is consistent with the timestamps of the second input time series Time Series Concepts 2 9 Time Series Cartridge Architecture While the first approach can be performed in a single step the second approach requires an additional step before DeriveExceptions is called in order to construct the first time series Although the first approach is simpler in practice the second approach has signifi cant performance advantages when you need to def
214. racted from a table of calendars CalendarTab which is of the form CREATE TABLE CalendarTab of ORDTCalendar Time Series Concepts 2 33 Time Scaling Functions The Scaleup function accepts a timestamp and a calendar and returns a timestamp If the input timestamp is a valid timestamp of the calendar the input timestamp is returned otherwise the closest timestamp in that calendar that precedes the input timestamp is returned Only SQL aggregate functions are supported in the GROUP BY interface 2 34 Oracle8 Time Series Cartridge User s Guide 3 Time Series Usage This chapter explains important procedures related to using the Oracle8 Time Series Cartridge It covers the following topics a using the cartridge major steps a loading time series data a deriving calendar exceptions from time series data a using product developer functions 3 1 Using the Cartridge This section provides a technical overview of using the Time Series cartridge It pre sents the major steps with examples For more detailed explanations of the concepts and terminology see Chapter 2 3 1 1 Step 1 Create the Underlying Storage Table Create the table to hold the time series data Example 3 1 shows the table definition for a stock trading database Example 3 1 Create a Stock Data Table Table Creation user CREATE TABLE stockdemo ticker VARCHAR2 5 tstamp DATE open NUMBER high NUMBER low NUMBER Tim
215. racteristics a At daily intervals historical data is updated with daily summary data main update cycle Atsome period after the main update cycle corrections of the daily summary data may need to be applied a Queries may be executed at any time even during the update cycle a Queries do not observe the current day s summary information until after the main update cycle has completed Time Series Concepts 2 3 Overview of Time Series Data This historical data is modeled using multiple regular time series The Time Series cartridge and the Oracle8 utilities with their bulk loading capabili ties and transactional semantics are well suited for the requirements of time series data generation 2 1 2 Historical Data The Time Series cartridge is especially useful in dealing with historical data This type of data typically has relatively simple metadata but massive data storage requirements That is the data attributes columns are relatively few and easy to understand such as ticker volume and opening high low and closing prices however the number of rows is enormous for example data for all listed stocks for all trading days for several years Moreover the number of functions that users might want to perform on the data is large for example finding various sums counts maximum and minimum values averages number of trading days between two dates moving average and so on Figure 2 2 shows an example o
216. re EPS is computed quarterly and stocks trade daily To compute a price earnings PE ratio earnings per share is first con verted to a daily time series using forward repeat Then the daily PE ratio is calculated by dividing the daily price time series value by the corresponding daily EPS time series value An exception is returned if the specified fill_type value is not 0 1 or 2 Return a time series illustrating each fill_type value SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE FORMAT MM DD YYYY HH24 MI SS For illustrating Fill we need a timeseries with missing dates In the following example the timeseries FOO has some missing dates 07 DEC 1996 and 08 DEC 1996 Also note that the calendar associated with FOO has an all one pattern DECLARE tstCal ORDSYS ORDTCalendar ts ORDSYS ordtnumseries ORDSYS ordtnumseries FOO Time Series and Time Scaling Functions Reference 5 35 Fill ORDSYS ORDTCalendar 0 FOO CALENDAR 4 ORDSYS ORDTPattern ORDSYS ORDTPatternBits 1 1 1 1 1 1 1 TO_DATE 01 07 1996 701 01 1996 701 01 1997 TO_DATI TO_DATI ORDSYS ORDTExceptions ORDSYS ORDTExceptions ORDSYS ordtnumtab ORDSYS ordtnumcell TO_DATE ORDSYS ordtnumcell TO_DATE ORDSYS ordtnumcell TO_DATE ORDSYS ordtnumcell TO_DATE ORDSYS ordtnumcell TO_DATE ORDSYS
217. retValTS ORDSYS TIMESERIES DisplayValTS retValTS outMesg loDateTab hiDateTab impDateTab dupDateTab extraDateTab missingDateTab DBMS_OUTPUT PUT_LINE Value returned by IsValid DBMS_OUTPUT PUT_LINE Value returned by ValidateTS Testing DisplayValTS END This example might produce the following output A VALID TIME SERIES Time Series and Time Scaling Functions Reference 5 21 DisplayValTS Procedure Name ACME open NumSeries Calendar Data Calendar Name BUSINESS 96 Frequency 4 MinDate 01 01 1990 00 00 00 MaxDate 01 01 2001 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions offExceptions 11 28 1996 00 00 00 12 25 1996 00 00 00 Series Data Date Value 11 01 1996 00 00 00 59 11 04 1996 00 00 00 60 11 05 1996 00 00 00 61 11 06 1996 00 00 00 62 11 07 1996 00 00 00 63 11 08 1996 00 00 00 64 11 11 1996 00 00 00 65 11 12 1996 00 00 00 66 11 13 1996 00 00 00 67 11 14 1996 00 00 00 68 11 15 1996 00 00 00 69 11 18 1996 00 00 00 70 11 19 1996 00 00 00 71 11 20 1996 00 00 00 72 11 21 1996 00 00 00 73 11 22 1996 00 00 00 74 11 25 1996 00 00 00 75 11 26 1996 00 00 00 76 11 27 1996 00 00 00 TT 11 29 1996 00 00 00 78 12 02 1996 00 00 00 79 12 03 1996 00 00 00 80 12 04 1996 00 00 00 81 12 05 1996 00 00 00 82 12 06 1996 00 00 00 83 12 09 1996 00 00 00 84 12 10 1996 00 00 00 85 12 11 1996
218. ridge has encountered a null series within a time series Action Ensure that all time series have a non null series component TS 00520 the input calendar is null Cause The Time Series Cartridge has encountered a null calendar Action Ensure that all calendars are non null TS 00522 error scaling date to calendar Cause Input date cannot be scaled to given calendar Action Ensure that the given calendar is valid and that the calendar s mindate and maxdate encompass all potential timestamp values TS 00523 the input date is null Cause Scaleup has encountered a null date No scaling semantics are defined for a null date Action Ensure that all input to Scaleup is non null TS 00525 the input time series is null Cause The Time Series Cartridge has encountered a null time series Action Ensure that all time series are not atomically null TS 00526 the input time series has a null calendar Cause The Time Series Cartridge has encountered a null calendar within a time series Action Ensure that all time series include valid non null calendars TS 00527 error scaling up to the target calendar frequency Error Messages A 3 Error Messages Cause Scaleup encountered a target calendar of finer frequency than that of the input time series calendar Action Scaleup requires a target calendar of equal or coarser frequency TS 00528 calendar has a null mindate or a null maxdate Cause The T
219. rms a pairwise division operation on each element of the time series or first time series by the corresponding element in the second time series or by aconstant This operation determines the value of each element of the returned time series For example a If two time series contain daily trade volumes for two stocks each element of the returned time series contains the result of dividing the volume in the first time series by the volume in the second time series for that day a Ifa time series ts1 contains closing prices for a stock and if a constant k of 2 is specified each element of the returned time series contains the closing price of ts1 divided by 2 If ts1 and ts2 are specified the function returns a time series whose calendar is the result of using the CombineCals function on the calendars associated with these two time series An exception is returned if any of the following conditions is true a An input time series is null a An input time series does not have an associated calendar a The calendars associated with ts1 and ts2 do not have the same frequency and aligned pattern a endDate is earlier than startDate Example Divide the high price for stock ACME by the low price for stock FUNCO for each trading day from 14 Nov 1996 through 14 Dec 1996 CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE FORMAT MM DD YYYY HH24 MI SS 5 102 Oracle8 Time Ser
220. rom the specified calendar all exceptions that either match a specified date delExcDate or are included in a table of dates delExcTab and returns the resulting calendar inputCal The calendar from which one or more exceptions are to be deleted delExcDate The date to be deleted from the exceptions of the calendar delExcTab A table of dates to be deleted from the exceptions of the calendar If a date to be deleted is in either the on exception list or off exception list of the cal endar the function deletes the date from the appropriate list Calendar Functions Reference 4 7 DeleteExceptions If delExcDate is not in either the on exception list or off exception list of the calen dar the function returns the input calendar with no changes For any date in delExcTab that is not in either the on exception list or off exception list of the calendar the function ignores the date If no date in delExcTab is in either the on exception list or off exception list of the calendar the function returns the input calendar with no changes Example Delete some exceptions from a calendar CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE_ FORMAT MM DD YYYY HH24 MI SS DECLARE tstCal ORDSYS ORDTCalendar tstDTab ORDSYS ordtDateTab resultCal ORDSYS ORDTCalendar dummyVal INTEGER relOffset INTEGER BEGIN Select a ca
221. s Demonstrations iciococociononnnenonononinnnncanonanancnonananananons 1 4 1 6 1 Running the Usage Demo vestida nn ia 1 5 1 6 2 Usage Demo Filesi nnr a aa E E 1 5 1 6 3 Tables and Views in the Usage Demo ocicocococicinononononinnoninananonononincncnononon anar anonananananons 1 6 2 Time Series Concepts 2 1 Overview of Time Series Data ccccccccessesssessesssescesceceseseecseessecsecssecaecssseasceeseseseeseesenseaes 2 1 2 1 1 Data Generation for a Time Series ccccccccsecsecssesscesceeeeeeceseecsceseecsecssesaecsseeaecneeeasens 2 2 2 1 2 Historical Data o 2 4 2 2 Galen ANO 2 5 2 2 1 Frequencysand Preciado wien eae Westend 2 6 2 2 2 Calendar Datatypes nasisisi rn dada dra 2 7 2 2 3 Overview of Calendar Definition coococcconcoononncononononnnononn non nono noononncon non ccnn nono conncnnnnos 2 8 2 2 4 Deriving Calendar Exceptions from Time Series Data oocinicicinononicinnonirnnncnoninananons 2 9 2 3 Time Series Cartridge Architecture ocococicoinnnononcnnononnonencnnonanannonicconananonononononanonononananananonos 2 10 2 4 Storage of Time Series Data iii bn bateas ae acota cia 2 11 2 4 1 Flat IOE Stora Se ceso te a A aii 2 12 2 5 Interfaces to Time Series and Time Scaling Functions cocococicinonononinnnnoconininonacanononanonos 2 12 2 5 1 Instance Based Inter tae ion atada lie eli lianas 2 13 2 5 2 Reference Based Interface miii anda ida 2 15 2 6 Consistency of Time Series Data cocnocicioionononinnononon
222. s Reference 4 21 GetOffset 01 21 1996 04 27 1996 07 07 1996 offExceptions 01 08 1996 04 04 1996 07 09 1996 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 03 1996 00 05 19 1996 00 08 04 1996 00 02 02 1996 00 05 08 1996 00 Get Offset 04 03 1996 00 00 00 06 05 1996 4 22 Oracle8 Time Series Cartridge User s Guide 00 00 00 00 00 00 00 00 00 00 00 00 00 03 24 1996 00 00 00 06 23 1996 00 00 00 09 15 1996 00 00 00 03 05 1996 00 00 00 06 25 1996 00 00 00 45 InsertExceptions InsertExceptions Format Description Parameters Usage ORDSYS Calendar InsertExceptions inputCal INORDSYS ORDTCalendar newExcDate IN DATE RETURN ORDSYS ORDT Calendar or ORDSYS Calendar InsertExceptions inputCal INORDSYS ORDTCalendar newExcTab INORDSYS ORDTDateTab RETURN ORDSYS ORDT Calendar Inserts into the specified calendar all exceptions that either match a specified date newExcDate or are included in a table of dates newExcTab and returns the result ing calendar inputCal The calendar into which one or more exceptions are to be inserted newExcDate The date to be inserted as an exception in the calendar newExcTab A table of dates to be inserted as exceptions in the calendar For each date to be inserted the function inserts it in the appropriate list off excep tions or on exceptions according to t
223. s 1 5 2 1 Erequendies ct o ia T S 2 6 2 2 PESCISTON Sut diana 2 7 2 3 End User Calendar Functions cccccccsssseeceeceasesseeeae sea eeeeecenseeseeeeeaueuseseeeseanaesees 2 21 2 4 Product Developer Calendar Functions oooconnccnonnnnonanonnninnncnnnc nan canon ona nn nan nn rn n canon 2 22 25 Extraction FUNCHONS toi in rra pet aaa aa EnEn ENa oid 2 26 26 Retrieval and Trim Func di eE AD anid da atea 2 27 2 7 SHift RUN CHOLS ia o Testa sues tacwetaustansanieuae 2 27 2 8 SOL Formatting FUNCH ONS midi de 2 27 2 9 Aperegate FUnCtHONS asii nta ir lt apreta aprisa intense 2 28 2 10 Arithmetic Functions it AA ALA E AAA ta 2 29 2 11 Cumulative Sequence FuNctiONS ooonccnnncnnocnnonnnnonaninancn nono nc nan cnn non nro n anar cnn nn nara nann nano 2 29 2 12 Moving Average and Sum Functions occonnccnncnnnonnnnnnnnonnn sees anna nnn canon anno cnn cnn anna nan 2 30 2213 Conversion FUNCHONS eena aae aa carnada lata a eaaa era aa Ee nanao Enina rae 2 31 2 14 Scaleup Functions for Collections oooncnnnnnnnoconicnnnonnnoccnronacnrnc nro canon anno rr crr car cnn 2 33 4 1 SetPrecision and Timestamp of 19 Sep 1997 09 09 09 cocoocccccccinnnnnannnarnnnacanananinanann nos 4 58 4 2 Errors Repaired by ValidateCal ooonnnonnccnnnnnnncnnocnnnonnnonnnnoncrancn nn cono no nnrnncnnnnrn cnica canos 4 70 5 1 Lagging a Time Series by Two DayS coomconnconoccnnocnnionnnonncronacanccano canon anno cn car nnan cana nan 5 60 5 2 Leading a Time Series by Two D
224. s ORDSYS ORDTNumsSerieslOTRef target_date date RETURN ORDSYS ORDTNumCell Given a time series and a date returns the time series element for that date ts The input time series target_date Positive integer specifying the date of the element to be returned The function returns the cell from the input time series ts at the specified date target_date If there is no data in ts at target_date the function returns a null An exception is returned if the time series ts is null Return the timestamp and opening price for 26 Nov 1996 for stock ACME SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE_ FORMAT MM DD YYYY HH24 MI SS DECLARE dummyval INTEGER tstDate date BEGIN Get the cell for 26 NOV 1996 from ACME s open and display it 5 44 Oracle8 Time Series Cartridge User s Guide GetDatedElement tstDate TO DATE 11 26 1996 SELECT ORDSYS TimeSeries Display ORDSYS TimeSeries GetDatedElement ts open tstDate GetDatedElement Results INTO dummyval FROM ORDTDEV stockdemo_ts ts WHERE ts ticker ACME END This example might produce the following output GetDatedElement Results Timestamp 11 26 1996 00 00 00 Value 76 Time Series and Time Scaling Functions Reference 5 45 GetNthElement GetNthElement Format ORDSYS TimeSeries GetNthElement ts ORDSYS ORDTNumSerieslOTRef targ
225. s data interfaces instance based and reference based to time series and time scaling functions calendar functions time series functions time scaling functions The chapter concludes with the steps for using the Time Series cartridge 2 4 Storage of Time Series Data The underlying storage model must satisfy the following requirements for time series data The data must be stored in timestamp order because many of the analytical functions require access to the data in this order It must be possible to couple a time series with a calendar In general each time series is associated with a distinct instance of a calendar Time series and time Time Series Concepts 2 11 Interfaces to Time Series and Time Scaling Functions scaling functions generally require an input parameter that is typed to contain both a time series and its associated calendar 2 4 1 Flat IOT Storage A time series is stored as multiple rows in a flat index organized table IOT Each row stores a ticker a timestamp and composite data This storage option is shown in Figure 2 2 The flat IOT storage model provides efficient utilization of disk storage for exam ple the timestamp data is stored once per composite entry and allows flexibility in queries however it does require that users perform certain manual actions An object view must be defined to form the collection and to couple a time series with a calendar see Section 2 5 2 a A s
226. s ref was invalid Action Verify the validity of the time series ref e Verify the validity of all components of the time series ref e No spaces or invalid punctuation may appear in table or column names The user must have select privileges on the table referenced e The table name must be qualified with its schema name TS 00553 divide by zero error Cause An attempt was made to divide by zero with TSDivide Action When dividing by a constant ensure that the constant is non zero TS 00554 the input calendar patterns are not equal Cause DeriveExceptions requires the reference time series calendar to have the same pattern as the time series being processed Action Ensure that DeriveExceptions is called only with time series having the same pattern A 6 Oracle8 Time Series Cartridge User s Guide Error Messages TS 00555 the input calendar frequencies are not equal Cause DeriveExceptions requires the reference time series calendar to have the same frequency as the time series being processed Action Ensure that DeriveExceptions is called only with time series having the same frequency TS 00556 mindate of the ref calendar exceeds the mindate of the target calendar Cause DeriveExceptions encountered a reference time series calendar having a mindate greater than that of the target time series calendar Action Ensure that DeriveExceptions is called only with appropriate time series m TS 00
227. s specified endDate must also be specified endDate Ending date within the time series for which the addition is to be performed If end Date is specified startDate must also be specified Usage The function performs a pairwise addition operation on each element of the time series This operation determines the value of each element of the returned time series For example a If two time series contain daily trade volumes for two stocks each element of the returned time series contains the sum of the trade volumes for the two stocks for that day a Ifa time series ts1 contains closing prices for a stock and if a constant k of 1 is specified each element of the returned time series contains the closing price of ts1 incremented by 1 If ts1 and ts2 are specified the function returns a time series whose calendar is the result of using the CombineCals function on the calendars associated with these two time series An exception is returned if any of the following conditions is true a An input time series is null a An input time series does not have an associated calendar a The calendars associated with ts1 and ts2 do not have the same frequency and aligned pattern a endDate is earlier than startDate Example Add the high price for stock ACME and the low price for stock FUNCO for each trading day from 14 Nov 1996 through 14 Dec 1996 CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON ALTER SESSION SET NLS DATE FORMAT
228. s to be created If startDate is specified endDate must also be specified endDate Ending date in the input time series for which the output time series is to be cre ated If endDate is specified startDate must also be specified The function creates a time series whose elements reflect an input time series adjusted by a number of timestamps For example using the United States stock trading calendar for 1997 if the first timestamp in the input time series is 02 Jan 1997 Thursday and the units value is 2 the first timestamp in the output time series is 06 Jan 1997 Monday and its associated value such as closing price is the same as that for 02 Jan 1997 in the input time series Subsequent elements of the output time series reflect the timestamp adjustment For example assuming the United States stock trading calendar for 1997 Table 5 2 shows some time series data with a two day lead period Table 5 2 Leading a Time Series by Two Days Input Time Series Output Time Series Timestamp Closing Price Timestamp Closing Price 02 Jan 1997 49 00 06 Jan 1997 49 00 03 Jan 1997 50 00 07 Jan 1997 50 00 06 Jan 1997 49 50 08 Jan 1997 49 50 Time Series and Time Scaling Functions Reference 5 67 Lead Example For convenience both the Lead and Lag functions are provided The functions oper ate identically except that they interpret the sign of the units value in opposite ways For example Lead with 10 for units is
229. ser s Guide ValidateTS numTS cal minDate TO_DAT numTS cal maxDate TO_ DAT 110 28 1996 101 05 1997 Dy E Add Dates Before numTS cal minDate numTS series 10 tstamp numTS cal minDate 1 numTS series 11 tstamp numTS cal minDate 2 Add Dates Beyond numTS cal maxDate numTS series 12 tstamp numIS cal maxDate 1 numTS series 13 tstamp numTS cal maxDate Add some null timestamps numTS series 14 tstamp NULL numTS series 15 tstamp NULL Add some imprecise dates some are duplicated 7 numTS series 17 tstamp numTS series 16 tstamo 1 24 numTS series 18 tstamp numTS series 16 tstamp 15 24 Add some duplicate timestamps numTS series 19 tstamp numTS series 18 tstamp numTS series 21 tstamp numTS series 20 tstamp Add some extra dates in the middl numTS series 37 tstamo TO_DATE 12 28 1996 numTS series 36 tstamo TO _DATE 12 29 1996 Add some holes at th nd numTS series numTS series count tstamp TO_DATE 01 04 199 Example of validating an invalid time series SELECT ordsys timeseries display numTS AN INVALID TIME SERI INTO tempVal FROM dual retIsValid ORDSYS TIMESERIES IsValidTS numTS retValTS ORDSYS TIMESERIES ValidateTS numTS outMesg loDateTab hi
230. series 2 2 2 6 IsValidCal function 4 34 IsValidDate function 4 40 IsValidTS function 5 51 K kit installation 1 3 L Lag function 5 59 Last function 5 62 LastN function 5 64 Lead function 5 66 loading time series data 3 9 lowest values TSMinN 5 113 M Mavg function 2 29 5 69 maximum TSMax function 5 105 median TSMedian function 5 109 messages error A 1 metadata for usage demo 1 6 2 16 minimum TSMin function 5 111 moving average Mavg function 2 29 5 69 moving sum Msum function 2 29 5 72 Msum function 2 29 5 72 multiplication TSMultiply function 5 115 TSProd function 5 119 N null operand semantics 2 24 NumInvalidTimeStampsBetween function 4 43 NumOffExceptions function 4 46 NumOnExceptions function 4 49 NumTimeStampsBetween function 4 52 O object relational technology 1 2 OCI demo 1 4 off exception 2 5 semantics 2 25 OffsetDate function 4 55 on exception 2 5 Oracle Forms demo Developer 2000 1 4 ORDSYS schema 1 4 ORDT Calendar datatype 2 7 ORDTDateTab datatype 2 24 ORDTExceptions datatype 2 7 ORDTNumCell datatype 2 23 ORDTNumSeries datatype 2 23 ORDTNumSeriesIOTRef datatype 2 23 ORDTNumSeriesIOTRef type 2 15 Index 3 ORDTNumTab datatype 2 23 ORDTPattern datatype 2 7 ORDTPatternBits datatype 2 7 ordtsyn sql public synonyms 1 4 ORDTVarchar2Cell datatype 2 23 ORDTVarchar2Series datatype 2 23 ORDTVarchar2SeriesIOTRe
231. series functions can derive the instance ORDTNumSeries at runtime using dynamic SQL The convention of defining an interface on a DATE column and a single NUMBER column provides a uniform interface for time series functions Because the underly ing IOT that stores time series data may have multiple NUMBER columns the view defining the REF also maps the underlying storage to conform to the two col umn interface defined by the ORDTNumSeries type The following are the key aspects of the instance based interface to time series func tions The input parameter of a time series function is a REF to a time series object for example ORDTNumSeries OTRef a Time series functions operate on time series instances for example ORDT NumSeries 2 14 Oracle8 Time Series Cartridge User s Guide Interfaces to Time Series and Time Scaling Functions Note In addition to numeric series a character time series is also provided with the types ORDTVarchar2Series and ORDTVarchar2SeriesIOTRef a You should use a view to construct the reference descriptor a The REF couples the calendar with the time series a Instances of calendars are typically stored in a table separate from time series data a Itis important to ensure and maintain consistency between time series data and the corresponding calendar Section 2 6 discusses consistency of time series data including ways of ensuring consistency 2 5 2 Reference Based Interf
232. t fix Then use ValidateCal again and use the calen dar only if the function returns 0 or 1 You can use the DisplayValCal procedure to display the information returned by the ValidateCal function See the information on DisplayValCal in this chapter The IsValidCal function described in this chapter checks the validity of the calen dar but does not perform any repair operations Use the IsValidCal and ValidateCal functions and the DisplayValCal procedure with an invalid calendar CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE FORMAT MM DD YYYY HH24 MI SS Calendar Functions Reference 4 71 ValidateCal DECLARE outMessage varchar2 32750 invOnExc ORDSYS ORDTDateTab invOffExc ORDSYS ORDTDateTab impOnExc ORDSYS ORDTDateTab impOffExc ORDSYS ORDTDateTab dummyval integer validFlag integer tstCall ORDSYS ORDTCalendar ORDSYS ORDTCalendar 0 CALENDAR FOO 4 ORDSYS ORDTPattern ORDSYS ORDTPatternBits 1 1 1 1 1 0 0 TO_DATE 01 08 1996 01 01 01 TO_DATE 01 01 1975 TO_DATE 01 01 1999 ORDSYS ORDTExceptions O_DATE 02 03 1969 Date lt minDate O_DATE 02 14 1969 Date lt minDate O_DATE 02 03 1999 Date gt maxDate O_DATE 02 17 1999 Date gt maxDate O_DATE 12
233. t time series fill_type One of the following integers indicating how missing values are to be filled a O null Insert nulls a 1 forward repeat Use the values from the preceding most recent timestamp a 2 backward repeat Use the values from the following next in the future timestamp If fill_type is omitted 0 is assumed The function inserts timestamps and associated values for timestamps that are included in a calendar but for which no entries exist in the time series The fill_type parameter lets you choose the manner in which missing values will be defaulted For example assume that data for 30 Jan 1997 Thursday is missing from a time series and that it should be included because this date is within the cal endar definition Assume the following closing prices for stock XYZ 5 34 Oracle8 Time Series Cartridge User s Guide Fill Example a 49 on 29 Jan 1997 a 50 on 31 Jan 1997 The following table shows the closing price that would be inserted for 30 Jan 1997 with each of the fill_type parameter values fill_type Closing Price for 30 Jan 1997 0 null 1 49 2 50 Some potential uses for this function include a deriving the price of a stock for a nontrading day For example you may want to compare prices for a stock that trades on several stock exchanges where the exchanges have different trading days converting a quarterly time series to a daily time series For example earnings per sha
234. ta cleanup sql Deletes database objects created by the demo 1 6 3 Tables and Views in the Usage Demo The stock database consists of three tables a stockdemo stores historical time series pricing data a stockdemo_calendars stores instances of calendars stockdemo_metadata maintains mapping between time series here for tickers and calendars This metadata table would not be needed if all tickers were asso ciated with a private calendar that is named by the ticker or if a single calendar were shared by all tickers The stockdemo_metadata table allows for example five tickers to be associated with one calendar two tickers with another calen dar and so on To maintain time series consistency and provide a collection based interface for time series functions two views are constructed using these tables a stockdemo_svis a security view A security view should be used for any insert update and delete operations to time series data a _ stockdemo_ts is a reference based view A reference based view provides an object model of a time series and it can be used for efficient read only access using Time Series cartridge functions The security view ensures that insert update and delete operations maintain a time series that is consistent with the associated calendar Time series consistency is explained in Section 2 6 The security view and the reference based view access the three underlying tables The reference based vi
235. tance of a time series The datatypes related to the instance based and reference based interfaces for example ORDTNumSeries and ORDTNumSeriesIOTRef are discussed in Sections 2 5 1 and 2 5 2 Note that both types of interfaces return only instances of time series for example ORDTNum6eries Also because nesting of time series functions is allowed for example SELECT Lead Mavg the instance based interface is used inter nally for the second and subsequent levels of nesting When possible you should use the reference based interface Although this inter face may be difficult to understand initially it offers significant performance advan tages over the instance based interface The examples in this manual emphasize the reference based interface 2 5 1 Instance Based Interface Time series functions operate on instances of time series objects for example an ORDTNumeSeries An instance of a time series object includes a name field an instance of a calendar and an instance of a time series For example as the follow ing type definitions for a numeric time series show ORDTNumTab defines a collec tion and ORDTNumSeries bundles a calendar instance with a collection CREATE TYPE ORDSYS ORDTNumCell AS OBJECT tstamp DATE value NUMBER CREATE TYPE ORDSYS ORDTNumTab AS TABLE OF ORDTNumCell CREATE TYPE ORDSYS ORDTNumSeries AS OBJECT name VARCHAR2 256 cal ORDTCalendar series ORDTNumTab
236. tart of 01 Jan 1997 and ends at the start of 01 Jan 1998 04 Jul 1997 and 25 Dec 1997 are off exceptions that is excluded from the calen dar NULL indicates that there are no on exceptions that is no Saturday or Sunday dates to be included in the calendar Time Series Usage 3 3 Using the Cartridge 3 1 3 Step 3 Load Time Series Data Perform a bulk load of the time series data in order to populate the underlying data storage tables Follow the guidelines and instructions for bulk loading in Section 3 2 3 1 4 Step 4 Create a Security View and INSTEAD OF Triggers Create a security view and INSTEAD OF triggers to ensure the consistency and integrity of time series data as explained in Section 2 6 2 Example 3 3 creates a security view stockdemo_sv to get all ticker values Example 3 3 Create a Security View CREATE OR REPLACE VIEW stockdemo_sv AS SELECT FROM stockdemo After you create the view create INSTEAD OF triggers using the definitions in the securevw sql demo file as examples or templates Example 3 4 creates an INSTEAD OF trigger stockdemo_sv_delete that ensures the following a An exception is raised if a delete operation is attempted on an empty time series a Fora non empty time series a delete operation is allowed on either the first or last timestamp in an existing series If you grant users access to the security view and deny access to the underlying tables
237. te 01 01 1999 00 00 00 patBits 1111100 patAnchor 01 08 1996 00 00 00 onExcept ions 01 06 1996 00 00 00 02 03 1996 00 00 00 03 23 1996 00 00 00 offExceptions 01 13 1996 00 00 00 02 18 1996 00 00 00 05 26 1996 00 00 00 01 14 1996 00 00 00 02 24 1996 00 00 00 05 04 1997 00 00 00 Calendar Functions Reference 4 15 DisplayValCal Procedure 4 16 Oracle8 Time Series Cartridge User s Guide 01 17 1996 00 00 00 02 12 1996 00 00 00 04 05 1996 00 00 00 05 28 1996 00 00 00 01 22 1996 00 00 00 03 04 1996 00 00 00 04 23 1996 00 00 00 06 18 1996 00 00 00 02 02 1996 00 00 00 03 25 1996 00 00 00 04 30 1996 00 00 00 05 06 1997 00 00 00 EqualCals EqualCals Format Description Parameters Usage ORDSYS Calendar EqualCals call ORDSYS ORDTCalendar cal2 ORDSYS ORDTCalendar stariDate DATE endDate DATE RETURN BINARY_INTEGER Checks if two calendars completely or within a specified date range are equal cal1 The first calendar to be checked cal2 The second calendar to be checked startDate Starting date for the checking If startDate is not specified the starting date is the starting date for the calendars or the higher later of the starting dates if they are different endDate Ending date for the checking If endDate is not specified the ending date is the end ing date for the calendars or the lower earlier of the ending dates if they are dif ferent The function
238. teTab DBMS_OUTPUT NEW_LINE For illus impDateTab dupDateTab extraDateTab missingDateTab Testing DisplayValTS tration let us first create an invalid timeseries Here we are adjusting the calendar s minDate and maxDate to avoid getting a huge list of missing dates num S cal minDate TO DATE numTS cal maxDate TO DATE 01 05 1997 110 28 1996 Add Dates Before numTS cal minDate numTS series 10 tstamp numTS series 11 tstamp numTS cal minDate 1 numTS cal minDate 2 Add Dates Beyond numTS cal maxDate numTS series 12 tstamp numTS series 13 tstamp Add some null timestamps numTS series 14 tstamp numTS series 15 tstamp NULL NULL numTS cal maxDate 1 numTS cal maxDate 2 Add some imprecise dates numTS series 17 tstamp numTS series 18 tstamp som are duplicated numTS series 16 tstamp 1 24 numTS series 16 tstamp 15 24 Add some duplicate timestamps numTS series 19 tstamp numTS series 21 tstamp Add some extra dates in num num numTS series 18 tstamp numTS series 20 tstamp the middl S series 37 tstamp S series 36 tstamp Add some holes at th n TO_DATI TO_DATI d By By 12 28 1996 12 29 1996
239. the new timestamp must be a valid date in the calen dar a Fora non empty time series an insertion is allowed immediately after the last timestamp or immediately before the first timestamp but nowhere else For delete operations the following rules apply a For an empty time series an exception is raised a For a non empty time series only the first or last timestamp can be deleted For update operations the following rules apply a The timestamp must exist in the time series a Updates are not allowed to the timestamp and qualifier columns for example tstamp and ticker in the usage demo security view INSTEAD OF triggers in a security view enable you to ensure that a time series meets the consistency requirements described in Section 2 6 1 Time Series Concepts 2 19 Calendar Functions INSTEAD OF triggers allow for multiple timestamps to be inserted or deleted in a single query given that the group of timestamps inserted or deleted are in the proper order For example a specified number of timestamps can be deleted from the beginning of a time series by using a simple range restriction on the timestamp A specified number of timestamps can be inserted at the end of a time series by using a subquery that references another table containing time series data 2 6 3 Bulk Loading and Consistency The SQL Loader utility is useful for loading large amounts of data into a table For better performance you should perform bulk
240. ther empty or null Cause The Time Series Cartridge encountered a calendar with an empty or null array of pattern bits Action Update the calendar to include a valid array of pattern bits TS 00512 invalid frequency value valid frequencies are 1 2 3 4 6 8 Cause The Time Series Cartridge has encountered a calendar with an unsup ported frequency Action Restrict all calendars to frequencies 1 2 3 4 6 8 TS 00513 the input dates are in the wrong order Cause The date range provided was in reverse order Action When specifying a date range always list the earlier date first TS 00514 calendar pattern has an imprecise anchor date Cause The Time Series Cartridge has encountered a calendar with an anchor having the wrong precision Action Adjust the precision of the anchor to match the calendars frequency TS 00515 input date is less than calendar mindate Cause The Time Series Cartridge has encountered a date less than mindate A 2 Oracle8 Time Series Cartridge User s Guide Error Messages Action Ensure that all input dates are within the mindate maxdate range of the calendar TS 00516 input date is greater than calendar maxdate Cause The Time Series Cartridge has encountered a date greater than max date Action Ensure that all input dates are within the mindate maxdate range of the calendar TS 00519 the series attribute of the time series type is null Cause The Time Series Cart
241. tions for querying and modifying calendars The calendar functions can be divided into the following categories 2 20 Oracle8 Time Series Cartridge User s Guide Calendar Functions a End user functions allow application developers to use the main calendar related features of the Time Series cartridge a Product developer functions allow developers to modify or supplement the Time Series cartridge capabilities by creating value added enhancements Reference information for all calendar functions is in Chapter 4 2 7 1 End User Functions End user functions let you use the main calendar related features of the Time Series cartridge If you do not need to modify or expand the Time Series cartridge capabilities you probably can limit your use of calendar functions to those listed in Table 2 3 Table 2 3 End User Calendar Functions Function Description Calendar Related Functions EqualCals Returns 1 if the two calendars are equivalent Ifa date range is provided tests only equivalence between the supplied dates IntersectCals Intersects two calendars UnionCals Returns the union of two calendars ValidateCal Validates a calendar repairs errors where possible Exception Related Functions InsertExceptions Inserts a list of timestamps into the appropriate exceptions list s DeleteExceptions Deletes a list of timestamps from the appropriate exceptions list s 2 7 2 Product Developer Functions Product develop
242. to be checked for invalid timestamps endDate Ending date in the range to be checked for invalid timestamps A timestamp is invalid if any of the following conditions is true a Itis outside the date range of the calendar a Itis an off exception in the calendar a Itis not sufficiently precise for example a timestamp of 01 Jul 1997 if the calen dar has a frequency of year a Itisnull startDate and endDate are included in the check for invalid timestamps If there are no invalid timestamps in the date range the function returns 0 zero Calendar Functions Reference 4 43 NuminvalidTimeStampsBetween If startDate is greater later than endDate an exception is raised Contrast this function with NumTimeStampsBetween which returns the number of valid timestamps in a date range Example Return the number of invalid timestamps between 03 Feb 1996 and 16 May 1996 in the GENERIC CAL1 calendar CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE_ FORMAT MM DD YYYY HH24 MI SS DECLARE tstCal ORDSYS ORDTCalendar tstDatel DATE tstDate2 DATE result INTEGER dummyVal INTEGER E BEGIN Select a calendar say GENERIC CAL1 from stockdemo_calendars SELECT value cal INTO tstCal FROM ORDTDEV stockdemo_calendars cal WHERE cal name GENERIC CAL1
243. to the SOL group function VAR 2 8 7 Arithmetic Functions Arithmetic functions accept two time series ORDTNumSeries1 ORDTNumSeries2 or a time series and a constant ORDTNumSeries1 Const and perform a pairwise arithmetic operation on each element of the time series This operation determines the value of each element of the returned time series 2 28 Oracle8 Time Series Cartridge User s Guide Time Series Functions Algorithm for f tsl ts2 ForAll i tsRet i tsl i op ts2 i Table 2 10 Arithmetic Functions Function Description TSAdd Time series addition TSDivide Time series division TSMultiply Time series multiplication TSSubtract Time series subtraction 2 8 8 Cumulative Sequence Functions Cumulative sequence functions operate on successive elements of a time series accumulating the result into the current element of the output time series For example CSUM 1 2 3 4 5 gt 1 3 6 10 15 In this example the result time series f i is computed from the input time series I i as follows f 1 1 1 ForAll i gt 1 f i f i 1 1 1 Table 2 11 Cumulative Sequence Functions Function Returns Cavg Cumulative average Cmax Cumulative maximum Cmin Cumulative minimum Cprod Cumulative product Csum Cumulative sum 2 8 9 Moving Average and Sum Functions The Moving Average Mavg function returns a time series that contains the aver ages of values from each successive timestam
244. tockdemo_sv sv ordtdev stockdemo_calendars cal MONTHLY GROUP BY ticker ORDSYS TimeSeries Scaleup sv tstamp value cal This example might produce the following output TICKE ORDSYS OR SUM VOLUME AVG CLOSE ACME 01 NOV 96 20000 68 5 ACME 01 DEC 96 21000 89 FUNCO 01 NOV 96 20000 23 823 FUNCO 01 DEC 96 21000 23 8257143 SAMCO 01 NOV 96 10207000 39 83125 SAMCO 01 DEC 96 3719450 38 2738095 XCORP 01 OCT 96 10270250 79 1458333 XCORP 01 NOV 96 100243350 84 6973684 XCORP 01 DEC 96 141838350 91 9572368 9 rows selected Time Series and Time Scaling Functions Reference 5 75 ScaleupAvg ScaleupAvg Format Description Parameters Usage ORDSYS TimeSeries ScaleupAvg ts ORDSYS ORDTNumSerieslOTRef calendar ORDSYS ORDTCalendar stariDate 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 reflecting the average value of each scaled group of non null values ts The input time series calendar The calendar to be used for the scaling startDate The starting date to be used If startDate is specified endDate must also be specified endDate The ending date to be used If endDate is specified startDate must also be specified An exception is returned for any of the following conditions a The input time series the calendar on which the
245. true a The time series ts is null a The time series ts does not have an associated calendar a endDate is earlier than startDate Time Series and Time Scaling Functions Reference 5 11 Csum If startDate and endDate are specified the time series is trimmed to the date range before the cumulative sum is computed Example Return the cumulative sum of the daily volume of stock ACME for November 1996 SELECT FROM the SELECT CAST ORDSYS TimeSeries ExtractTable ORDSYS TimeSeries Csum ts volume to_date 01 NOV 96 DD MON YY to_date 30 NOV 96 DD MON YY AS ORDSYS ORDTNumTab FROM ORDTDEV stockdemo_ts ts WHERE ts ticker ACME This example might produce the following output 01 NOV 96 1000 04 NOV 96 2000 05 NOV 96 3000 06 NOV 96 4000 07 NOV 96 5000 08 NOV 96 6000 11 NOV 96 7000 12 NOV 96 8000 13 NOV 96 9000 14 NOV 96 0000 15 NOV 96 1000 18 NOV 96 2000 19 NOV 96 3000 00 00 00 00 00 00 00 29 NOV 96 200 20 rows selected 5 12 Oracle8 Time Series Cartridge User s Guide DeriveExceptions DeriveExceptions Format Approach 1 ORDSYS TimeSeries DeriveExceptions inputCal INORDSYS ORDTCalendar DateTab IN ORDSYS ORDTDateTab RETURN ORDSYS ORDT Calendar Approach 2 ORDSYS TimeSeries DeriveExceptions series ORDTNumSerieslOTRef series2 ORDTNumsSerieslOTRef RETURN ORDSYS ORDT Cale
246. ts is null or if NumValues is zero 0 or negative Return the last 10 timestamps and opening prices in the time series for stock ACME SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE FORMAT MM DD YYYY HH24 MI SS DECLARE dummyval INTEGER 5 64 Oracle8 Time Series Cartridge User s Guide LastN BEGIN SELECT ORDSYS TimeSeries Display ORDSYS TimeSeries LastN ts open 10 LastN Results INTO dummyval FROM ORDTIDEV stockdemo_ts ts WHERE ts ticker ACME END This example might produce the following output LastN Results Calendar Data Calendar Name BUSINESS 96 Frequency 4 MinDate 01 01 1990 00 00 00 MaxDate 01 01 2001 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions offExceptions 11 28 1996 00 00 00 12 25 1996 00 00 00 Series Data Date Value 2 17 1996 00 00 00 90 2 18 1996 00 00 00 91 2 19 1996 00 00 00 92 2 20 1996 00 00 00 93 2 23 1996 00 00 00 94 2 24 1996 00 00 00 95 2 26 1996 00 00 00 96 2 27 1996 00 00 00 97 2 30 1996 00 00 00 98 2 31 1996 00 00 00 99 Time Series and Time Scaling Functions Reference 5 65 Lead Lead Format ORDSYS TimeSeries Lead ts ORDSYS ORDTNumSerieslOTRef units INTEGER stariDate DATE endDate DATE RETURN ORDSYS ORDTNumSeries or ORDSYS TimeSeries Lead ts ORDSYS ORDTNumSerieslOTRef lead_date DATE stariDate DATE
247. tstCal tstDatel DBMS_OUTPUT PUT_LINE IsValidDate tstDatel result END This example might produce the following output In this example the returned value of 1 indicates that 02 Jan 1996 is a valid timestamp for the BUSINESS 96 cal endar Calendar Name GENERIC CAL1 Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1996 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions 01 21 1996 00 00 00 02 03 1996 00 00 00 03 24 1996 00 00 00 04 27 1996 00 00 00 05 19 1996 00 00 00 06 23 1996 00 00 00 07 07 1996 00 00 00 08 04 1996 00 00 00 09 15 1996 00 00 00 offExceptions 01 08 1996 00 00 00 02 02 1996 00 00 00 03 05 1996 00 00 00 Calendar Functions Reference 4 41 IsValidDate 04 04 1996 00 00 00 05 08 1996 00 00 00 06 25 1996 00 00 00 07 09 1996 00 00 00 IsValidDate 01 02 1996 00 00 00 1 4 42 Oracle8 Time Series Cartridge User s Guide NuminvalidTimeStampsBetween NuminvalidTimeStampsBetween Format Description Parameters Usage ORDSYS Calendar NuminvalidTimeStampsBetween inputCal IN ORDSYS ORDT Calendar startDate IN DATE endDate IN DATE RETURN INTEGER Given starting and ending input timestamps returns the number of invalid timestamps within that range according to the specified calendar inputCal The calendar to be used to determine whether a timestamp is valid or invalid startDate Starting date in the range
248. ull imprecise or outside the date range of the calendar a One or more timestamps are included in the time series but should be excluded based on the calendar definition for example a Saturday timestamp that is in a Monday Friday calendar and that is not an on exception One or more timestamps are excluded from the time series but should be included based on the calendar definition for example a Wednesday date that is not a holiday in a Monday Friday calendar and for which there is no data Such dates can be considered as holes in the time series Contrast this function with IsValidTS which simply checks whether a time series is valid You can use the DisplayValTS procedure documented in this chapter to display the information returned by the ValidateTS function The ValidateTS function cannot be called from SQL It must be called from PL SQL because of the OUT parameters Use the IsValidTS and ValidateTS functions and the DisplayValTS procedure with an invalid time series SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE FORMAT MM DD YYYY HH24 MI SS Time Series and Time Scaling Functions Reference 5 133 ValidateTS DECLARE numTS ORDSYS ORDTNumSeries tempVal integer retIsValid integer retValTS integer loDateTab ORDSYS ORDTDateTab NULL hiDateTab ORDSYS ORDTDateTab NULL impDateTab ORDSYS ORDTDateTab NULL dupDateTab ORDSYS ORDTDateTab NUL
249. ultiply ts1 ORDSYS ORDTNumSerieslOTRef ts2 ORDSYS ORDTNumsSerieslOTRef startDate DATE endDate DATE RETURN ORDSYS ORDTNumSeries or ORDSYS TimeSeries TSMultiply ts1 ORDSYS ORDTNumSerieslOTRef k NUMBER startDate DATE endDate DATE RETURN ORDSYS ORDTNumSeries Given two input time series or a time series and a constant and optionally starting and ending dates returns a time series that reflects the multiplication of the first parameter by the second parameter ts1 The time series or first time series whose elements are to be multiplied by either the corresponding elements in the second time series or a constant ts2 The time series whose elements are to be multiplied by corresponding elements in the first time series k A constant to be multiplied by corresponding elements in the first time series Time Series and Time Scaling Functions Reference 5 115 TSMultiply startDate Starting date within the time series for which the multiplication is to be performed If startDate is specified endDate must also be specified endDate Ending date within the time series for which the multiplication is to be performed If endDate is specified startDate must also be specified Usage The function performs a pairwise multiplication operation on each element of the time series or first time series by the corresponding element in the second time series or by a constant This operation determines the value of each el
250. umSeries ts The input time series startDate Starting date within the time series for which the cumulative average is to be com puted If startDate is specified endDate must also be specified endDate Ending date within the time series for which the cumulative average is to be com puted If endDate is specified startDate must also be specified Only non null values are considered in computing the cumulative average An exception is returned if any of the following conditions is true a The time series ts is null a The time series ts does not have an associated calendar a endDate is earlier than startDate Time Series and Time Scaling Functions Reference 5 3 Cavg If startDate and endDate are specified the time series is trimmed to the date range before the cumulative average is computed Example Return the cumulative average of the closing price of stock ACME for November 1996 SELECT FROM the SELECT CAST ORDSYS TimeSeries ExtractTable ORDSYS TimeSeries Cavg ts close to_date 01 NOV 96 DD MON YY to_date 30 NOV 96 DD MON YY AS ORDSYS ORDTNumTab FROM ORDTDEV stockdemo_ts ts WHERE ts ticker ACME This example might produce the following output 01 NOV 96 59 04 NOV 96 59 5 05 NOV 96 60 06 NOV 96 60 5 07 NOV 96 61 08 NOV 96 61 5 11 NOV 96 62 12 NOV 96 62 5 13 NOV 96 63 14 NOV 96 63 5 15 NOV 96 64
251. usinessDays calendar includes Mondays through Fridays in 1997 but excludes 04 Jul 1997 and 25 Dec 1997 Explanatory notes fol low the example 3 2 Oracle8 Time Series Cartridge User s Guide Using the Cartridge Example 3 2 Create a Calendar of Business Days CREATE TABLE stockdemo_calendars of ORDSYS ORDTCalendar INSERT INTO stockdemo_calendars 1 VALUES ORDSYS ORDTCalendar o BusinessDays 3 4 9 ORDSYS ORDTPattern ORDTPatternBits 0 1 1 1 1 1 0 O to date 01 05 97 MM DD YY to date 01 01 97 MM DD YY Q to date 01 01 98 MM DD YY ORDSYS ORDTExceptions to_date 07 04 97 MM DD YY Q to date 12 25 97 MM DD YY NULL O Notes on Example 3 2 ooo 8 stockdemo_calendars is a table of ORDSYS ORDTCalendar objects The ORDTCal endar datatype is described in Section 2 2 2 0 zero for calendar type caltype indicates that this is an exception based cal endar This is the only calendar type currently supported BusinessDays is the name of this calendar 4 is the frequency code for day The pattern is defined as an excluded occurrence followed by five included occurrences followed by an excluded occurrence 0 1 1 1 1 1 0 Because the frequency is daily and because the anchor date 05 Jan 1997 is a Sunday Sun days are excluded Mondays through Fridays are included and Saturdays are excluded O The calendar begins at the s
252. xc impOffI ESERIES DisplayValCal ry XC IsValidCal validFlag outMes sage invOnExc invOffExc impOnExc impOffExc tstCall Your Message END IF END This example might produce the following output tstCall Calendar Name CALENDAR FOO Frequency 4 MinDate 01 01 1975 00 00 00 MaxDate 01 01 1999 00 00 00 patBits 1111100 patAnchor 01 08 1996 01 01 01 onExceptions 02 08 1969 00 00 00 02 15 1969 00 00 00 02 13 1999 00 00 00 02 20 1999 00 00 00 01 03 1996 00 00 00 02 19 1996 00 00 00 03 18 1996 00 00 00 05 27 1996 00 00 00 03 23 1996 01 01 01 02 18 1996 01 01 01 05 26 1996 01 01 01 01 13 1996 00 00 00 01 14 1996 00 00 00 02 24 1996 00 00 00 03 23 1996 00 00 00 01 13 1996 00 00 00 01 14 1996 00 00 00 02 24 1996 00 00 00 03 23 1996 00 00 00 01 17 1996 00 00 00 05 28 1996 00 00 00 06 18 1996 00 00 00 04 23 1996 00 00 00 01 06 1996 00 00 00 02 03 1996 00 00 00 05 04 1997 00 00 00 offExceptions 02 03 1969 00 00 00 02 14 1969 00 00 00 02 03 1999 00 00 00 02 17 1999 00 00 00 12 31 1995 00 00 00 01 13 1996 00 00 00 02 24 1996 00 00 00 03 30 1996 00 00 00 02 02 1996 01 01 01 03 04 1996 01 01 01 04 05 1996 02 02 02 03 25 1996 00 00 00 01 22 1996 00 00 00 02 12 1996 00 00 00 04 30 1996 00 00 00 02 12 1996 00 00 00 04 30 1996 00 00 00 03 25 1996 00 00 00 01 22 1996 00 00 00 01 17 1996 00 00 00 05 28 1996 00 00 00 06 18 1996 00 00 00 04 23 1996 00 00 00 02 02 199
253. xception list sorted the off exceptions list removed duplicate dates in the off exceptions list S WRN the on exceptions list was trimmed between calendar minDate amp maxDate the off exceptions list was trimmed between calendar minDate amp maxDate list of invalid on exceptions 01 03 1996 00 00 00 02 19 1996 00 00 00 03 18 1996 00 00 00 05 27 1996 00 00 00 01 17 1996 00 00 00 05 28 1996 00 00 00 06 18 1996 00 00 00 04 23 1996 00 00 00 list of invalid off exceptions 12 31 1995 00 00 00 01 13 1996 00 00 00 02 24 1996 00 00 00 03 30 1996 00 00 00 list of imprecise on exceptions 03 23 1996 01 01 01 02 18 1996 01 01 01 05 26 1996 01 01 01 list of imprecise off exceptions 02 02 1996 01 01 01 03 04 1996 01 01 01 04 05 1996 02 02 02 the validated calendar Calendar Name CALENDAR FOO Frequency 4 MinDate MaxDate 01 01 1975 00 00 00 01 01 1999 00 00 00 patBits Calendar Functions Reference 4 75 ValidateCal 1111100 patAnchor 01 08 1996 00 00 00 onExcept ions offExceptions 01 17 1996 02 12 1996 04 05 1996 05 28 1996 OOOO 4 76 Oracle8 Time Series Cartridge User s Guide 01 06 1996 00 02 03 1996 00 03 23 1996 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 13 1996 02 18 1996 05 26 1996 01 22 1996 03 04 1996 04 23 1996 06 18 1996 00 00 00 00 00 00 00 00 00 00
254. y is day For an explanation of concepts related to time scaling see Section 2 9 Return the first closing prices for stock SAMCO for the months of October Novem ber and December of 1996 SELECT FROM THE SELECT CAST ORDSYS TimeSeries Extract Table ORDSYS TimeSeries ScaleupFirst ts close sc calendar to date 01 OCT 1996 DD MON YYYY to date 01 JAN 1997 DD MON YYYY AS ORDSYS ORDTNumTab FROM ORDTDEV stocks_ts ts ordtdev scale sc WHERE ts ticker SAMCO and sc name MONTHLY This example might produce the following output TSTAMP VALUE 01 OCT 96 42 75 01 NOV 96 41 875 01 DEC 96 38 125 3 rows selected Time Series and Time Scaling Functions Reference 5 81 ScaleupLast ScaleupLast Format Description Parameters Usage ORDSYS TimeSeries ScaleupLast ts ORDSYS ORDTNumSerieslOTRef calendar ORDSYS ORDTCalendar stariDate 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 reflecting the last non null value of each scaled group of values ts The input time series calendar The calendar to be used for the scaling startDate The starting date to be used If startDate is specified endDate must also be specified endDate The ending date to be used If endDate is specified startDat
255. y or null pattern 4 20 Oracle8 Time Series Cartridge User s Guide GetOffset Example Return the offset of 05 Jun 1996 from 04 Mar 1996 in the GENERIC CAL1 calendar CONNECT ORDTUSER ORDTUSER SET SERVEROUTPUT ON ALTER SESSION SET NLS_DATE FORMAT MM DD YYYY HH24 MI SS DECLARE tstCal ORDSYS ORDTCalendar tstDatel DATE tstDate2 DATE result INTEGER dummyVal INTEGER BEGIN Select a calendar say GENERIC CAL1 into tstCal from stockdemo_calendars SELECT value cal INTO tstCal FROM ORDTIDEV stockdemo_calendars cal WHERE cal name GENERIC CAL1 Display the calendar SELECT ORDSYS TimeSeries Display tstCal INTO dummyVal FROM dual DBMS_OUTPUT NEW_LINE Get offset of 05 JUN 1996 from 04 MAR 1996 tstDatel TO_DATE 04 03 1996 tstDate2 TO_DATE 06 05 1996 result ORDSYS Calendar GetOffset tstCal tstDatel tstDate2 DBMS_OUTPUT PUT_LINE GetOffset tstDatel tstDate2 11 result END This example might produce the following output In this example 05 Jun 1996 is 45 timestamps later than 04 Mar 1996 Calendar Name GENERIC CAL1 Frequency 4 MinDate 01 01 1996 00 00 00 MaxDate 12 31 1996 00 00 00 patBits 0111110 patAnchor 01 07 1996 00 00 00 onExcept ions Calendar Function
256. y problems loDateTab A table of dates before the starting date of the calendar associated with the time series hiDateTab A table of dates after the ending date of the calendar associated with the calendar impreciseDateTab A table of the imprecise timestamps found in the time series duplicateDateTab A table of the duplicate timestamps found in the time series extraDateTab A table of dates that are included in the time series but that should be excluded based on the calendar definition for example a Saturday timestamp that is in a Monday Friday calendar and that is not an on exception missingDateTab A table of dates that are excluded from the time series but that should be included based on the calendar definition for example a Wednesday date that is not a holi day in a Monday Friday calendar and for which there is no data Such dates can be considered as holes in the time series 5 132 Oracle8 Time Series Cartridge User s Guide ValidateTS Usage Example The function returns one of the following values Value Meaning 1 The time series is valid No errors were found 0 The time series in invalid A time series is invalid if one or more of the following conditions are true a The time series ts is null a The time series ts does not have an associated calendar a The calendar associated with the time series is invalid a The timestamps are not sorted One or more timestamps are n
257. you can ensure that all delete operations are checked and performed by the trigger Similar INSTEAD OF triggers can be written to allow safe insert and update operations For more information about using INSTEAD OF triggers with security views see Section 2 6 2 2 Example 3 4 Create an INSTEAD OF Trigger CREATE OR REPLACE TRIGGER stockdemo sv_delete INSTEAD OF DELETE on stockdemo_sv REFERENCING old AS o FOR EACH row DECLARE cal ORDSYS ORDTCalendar NULL purifieddate DATE startdate DATE enddate DATE BEGIN 3 4 Oracle8 Time Series Cartridge User s Guide Using the Cartridge Retrieve the calendar that maps to the stock ticker SELECT VALUE c INTO cal FROM stockdemo_calendars c stockdemo_metadata m WHERE m tickername 0 ticker AND c name m calendarname EXCEPTION when NO_DATA FOUND THEN raise _ application error 20000 Could not find calendar END IF cal IS null THEN raise_application_error 20000 NULL calendar found END IF Set the precision of timestamp to correspond to the precision of the calendar purifieddate ORDSYS Calendar SetPrecision o tstamp cal frequency Retrieve the current startdate AND enddate for the stock ticker SE Hi ECT max tstamp min tstamp INTO enddate startdate ROM stockdemo_sv WHERE ticker 0 ticker ny There
Download Pdf Manuals
Related Search
Related Contents
取扱説明書 Home Run 2.0 Daewoo DR-C912B System Design DVD/HDD-Rekorder mit DVB Email Marketer Pro User Manual DECRETO 31 gennaio 2014. - Il Quotidiano Giuridico AT Series Transformer Testers Calibration System User Manual Service manual - Wassermann Dental PS8 Metallique (manuel de service) Copyright © All rights reserved.
Failed to retrieve file