Setting the application time for a session
Setting the application time in the CURRENT TEMPORAL BUSINESS_TIME special register can reduce or eliminate the changes required when running an application against different points in time.
About this task
The BIND command contains the BUSTIMESENSITIVE option and is set to YES by default. The BUSTIMESENSITIVE option determines whether references to application-period temporal tables and bitemporal tables in both static SQL statements and dynamic SQL statements in a package are affected by the value of the CURRENT TEMPORAL BUSINESS_TIME special register. The bind option can be set to YES or NO. For more information about the type of objects that CURRENT TEMPORAL BUSINESS_TIME also affects, see CURRENT TEMPORAL BUSINESS_TIME special register. If queries in the application are meant to access only the current version of data, set BUSTIMESENSITIVE to NO to optimize the static queries. For SQL procedures, use the SET_ROUTINE_OPTS procedure to set the bind-like options, called query compiler variables.
Procedure
When this special register is set to a non-null value,
applications that issue a query returns data as of that date. The
following examples request information from the result tables in the Deleting data from an application-period temporal table
topic.
Results
policy_info
table is as follows:
policy_id | coverage | bus_start | bus_end |
---|---|---|---|
A123 | 12000 | 2008-01-01 | 2008-06-01 |
A123 | 14000 | 2008-06-01 | 2008-06-15 |
A123 | 16000 | 2008-08-15 | 2009-01-01 |
B345 | 18000 | 2008-03-01 | 2009-01-01 |
C567 | 25000 | 2008-01-01 | 2009-01-01 |
- The request for data as of 2008-01-01 queries the
policy_info
table. The query is implicitly rewritten to:
The query returns:SELECT * FROM policy_info FOR BUSINESS_TIME AS OF '2008-01-01';
A123, 12000, 2008-01-01, 2008-06-01 C567, 25000, 2008-01-01, 2009-01-01
- The query on
view1
is implicitly rewritten to:
and then to:SELECT * FROM view1 FOR BUSINESS_TIME AS OF CURRENT TEMPORAL BUSINESS_TIME;
The query returns:SELECT policy_id, coverage FROM policy_info FOR BUSINESS_TIME AS OF '2008-01-01';
The query onA123, 12000 C567, 25000
view2
involves a view on a regular table that references an application-period temporal table, causing an implicit relationship between a regular table and the special register. The query is implicitly rewritten to:
and then to:SELECT * FROM view2 FOR BUSINESS_TIME AS OF CURRENT TEMPORAL BUSINESS_TIME;
The SELECT returns rows whereSELECT * FROM regular_table WHERE col1 in (SELECT coverage FROM policy_info FOR BUSINESS_TIME AS OF '2008-01-01');
col1
values match values incoverage
. - An error is returned because there are multiple time period specifications. The special register was set to a non-null value and the query also specified a time.