Saved Queries & Scheduling
Saved queries are named points of view stored with a cube. They let you define a report once and reuse its POV. Saved queries can also be scheduled to materialize into reporting tables on a recurring basis.
MANAGE_SAVED_QUERY
Section titled “MANAGE_SAVED_QUERY”Minimum role: CUBE_ADMIN
MANAGE_SAVED_QUERY( P_ACTION, P_PARAMS) -> VARCHARCreates, updates, or deletes saved queries.
Parameters
Section titled “Parameters”| Parameter | Type | Req/Opt | Description |
|---|---|---|---|
P_ACTION |
VARCHAR |
req | ADD, UPDATE, or DELETE. |
P_PARAMS |
VARCHAR |
req | JSON object containing the saved-query parameters. For ADD, cube_name and query_name are required. Supply pov as a JSON object. |
Example
Section titled “Example”CALL CUBE.MANAGE_SAVED_QUERY('ADD', '{ "cube_name":"FINANCE", "query_name":"Monthly P&L", "pov":{ "ACCOUNT":[{"idescendants":"Net Income"}], "PERIOD":[{"children":"YearTotal"}], "VIEW":["MTD"], "SCENARIO":["Actual"], "YEARS":["&CurrentYear"] }}');GET_SAVED_QUERIES
Section titled “GET_SAVED_QUERIES”Minimum role: CUBE_PUBLIC
GET_SAVED_QUERIES(P_CUBE_NAME) -> TABLELists the saved queries defined for a cube.
Parameters
Section titled “Parameters”| Parameter | Type | Req/Opt | Description |
|---|---|---|---|
P_CUBE_NAME |
VARCHAR |
req | Cube name. |
Returns
Section titled “Returns”Returns:
QUERY_NAMEPOVFORMULAS
QUERY_CUBE accepts a POV rather than a saved-query name. To run a saved query interactively, retrieve its POV with GET_SAVED_QUERIES and pass that POV to QUERY_CUBE. For unattended execution, schedule the saved query.
Example
Section titled “Example”CALL CUBE.GET_SAVED_QUERIES('FINANCE');SCHEDULE_SAVED_QUERY
Section titled “SCHEDULE_SAVED_QUERY”Minimum role: CUBE_ADMIN
SCHEDULE_SAVED_QUERY( P_CUBE_NAME, P_QUERY_NAME, P_TARGET_TABLE, P_SCHEDULE, P_WAREHOUSE_SIZE, P_ENABLED) -> VARCHARSchedules a saved query to materialize into a reporting table on a recurring basis.
Each execution fully replaces the target table so consumers read a complete current snapshot.
Parameters
Section titled “Parameters”| Parameter | Type | Req/Opt | Description |
|---|---|---|---|
P_CUBE_NAME |
VARCHAR |
req | Cube name. |
P_QUERY_NAME |
VARCHAR |
req | Active saved-query name. |
P_TARGET_TABLE |
VARCHAR |
req | Unqualified target table name. The table is created in SHARED_DATA; targets outside that schema are rejected. |
P_SCHEDULE |
VARCHAR |
opt | Cron expression or interval. |
P_WAREHOUSE_SIZE |
VARCHAR |
opt | XSMALL, SMALL, MEDIUM, LARGE, or XLARGE. |
P_ENABLED |
BOOLEAN |
opt | Whether to start the schedule immediately. |
The application requires EXECUTE MANAGED TASK to run scheduled queries. Re-running SCHEDULE_SAVED_QUERY for the same saved query replaces its existing schedule.
Schedule formats
Section titled “Schedule formats”USING CRON 0 6 * * * America/New_YorkUSING CRON 0 8 * * MON-FRI America/New_York60 MINUTEThese examples represent daily at 06:00 Eastern, weekdays at 08:00 Eastern, and hourly execution, respectively.
Example
Section titled “Example”CALL CUBE.SCHEDULE_SAVED_QUERY( 'FINANCE', 'Monthly P&L', 'RPT_MONTHLY_PL', 'USING CRON 0 6 * * * America/New_York', 'SMALL', TRUE);LIST_SAVED_QUERY_SCHEDULES
Section titled “LIST_SAVED_QUERY_SCHEDULES”Minimum role: CUBE_ADMIN
LIST_SAVED_QUERY_SCHEDULES(P_CUBE_NAME) -> TABLELists registered saved-query schedules, including their current live state and most recent run outcome.
Parameters
Section titled “Parameters”| Parameter | Type | Req/Opt | Description |
|---|---|---|---|
P_CUBE_NAME |
VARCHAR |
opt | Cube name. Omit or pass NULL to list schedules for all cubes. |
Returns
Section titled “Returns”Returns:
QUERY_NAMETARGET_TABLESCHEDULEWAREHOUSE_SIZESTATELAST_RUN_ATLAST_RUN_STATUSLAST_RUN_ROWSLAST_RUN_MSLAST_RUN_ERRORTASK_NAME
STATE is read live. If a schedule is suspended outside the application, including suspension after repeated failures, the procedure reports the current state accurately.
Example
Section titled “Example”CALL CUBE.LIST_SAVED_QUERY_SCHEDULES(NULL);SET_SAVED_QUERY_SCHEDULE_STATE
Section titled “SET_SAVED_QUERY_SCHEDULE_STATE”Minimum role: CUBE_ADMIN
SET_SAVED_QUERY_SCHEDULE_STATE( P_CUBE_NAME, P_QUERY_NAME, P_ENABLED) -> VARCHARSuspends or resumes a saved-query schedule without discarding its configuration.
Parameters
Section titled “Parameters”| Parameter | Type | Req/Opt | Description |
|---|---|---|---|
P_CUBE_NAME |
VARCHAR |
req | Cube name. |
P_QUERY_NAME |
VARCHAR |
req | Scheduled saved-query name. |
P_ENABLED |
BOOLEAN |
req | TRUE resumes the schedule; FALSE suspends it. |
Example
Section titled “Example”CALL CUBE.SET_SAVED_QUERY_SCHEDULE_STATE( 'FINANCE', 'Monthly P&L', FALSE);UNSCHEDULE_SAVED_QUERY
Section titled “UNSCHEDULE_SAVED_QUERY”Minimum role: CUBE_ADMIN
UNSCHEDULE_SAVED_QUERY( P_CUBE_NAME, P_QUERY_NAME) -> VARCHARRemoves and deregisters a saved-query schedule.
Parameters
Section titled “Parameters”| Parameter | Type | Req/Opt | Description |
|---|---|---|---|
P_CUBE_NAME |
VARCHAR |
req | Cube name. |
P_QUERY_NAME |
VARCHAR |
req | Scheduled saved-query name. |
Example
Section titled “Example”CALL CUBE.UNSCHEDULE_SAVED_QUERY( 'FINANCE', 'Monthly P&L');