Showing posts with label Data Warehousing. Show all posts
Showing posts with label Data Warehousing. Show all posts

Searching for Triggers in the Database

Create this simple function and use it to search for triggers.

 create or replace    function trigger_like
     ( p_schema in varchar2,
       p_trigger_name in varchar2,
       p_search in varchar2
     )
     return number
     as
             l_text long;
    begin
            select trigger_body
              into l_text
              from all_triggers
             where owner = p_schema
               and trigger_name = p_trigger_name;

            if ( upper(l_text) like upper(p_search) )
            then
                    return 1;
            else
                    return 0;
            end if;
    exception
            when no_data_found then return null;
    end;

Once created use this sql to search for triggers:


select trigger_name
      from all_triggers
     where trigger_like( owner, trigger_name, '%X%' ) = 1

Oracle Warehouse Builder

Oracle Warehouse Builder is a GUI tool used for building Oracle data warehouses and data marts.

OWB10g consists of two main components: the design environment, which is concerned with working with metadata (abstract representations of warehouse objects, together with business rules), and the runtime environment, which takes this metadata and turns it into physical database objects and process flows.
The design environment consists of the OWB client and a number of utility programs used for setting up the runtime environment, reporting on the repository, and providing a command-line interface for OWB.

Once the DBA has built the logical model in the repository, he needs to translate it into a physical design using the OWB Runtime component. This runtime component creates physical database objects, together with scripts and packages to extract data from source system, and populate the warehouse objects. OWB10g can extract data from any database that has either an ODBC driver, or an Oracle Gateway, together with flat files and data held in SAP.

Dimensions

A dimension declares a parent/child relationship between pairs of columns. We can use it to describe to Oracle that, within a row of a table, the MONTH column implies the
value you’ll find in the QTR column, the QTR column implies the value you’ll find in the YEAR column, and so on. Using a dimension, we can have a materialized view that has fewer details than the detailed records (summarized to the monthly level perhaps). This may still be at a higher level of aggregation than the query requests (the query wants data by quarter, say), but Oracle will recognize that it can use the materialized view to get the answer.


 create table sales
2 (trans_date date, cust_id int, sales_amount number );

Now we need to set up our TIME_HIERARCHY table, to roll up the date field by month, year, quarter, and so on:

 create table time_hierarchy
2 (day primary key, mmyyyy, mon_yyyy, qtr_yyyy, yyyy)
3 organization index
4 as
5 select distinct
6 trans_date DAY,
7 cast (to_char(trans_date,’mmyyyy’) as number) MMYYYY,
8 to_char(trans_date,’mon-yyyy’) MON_YYYY,
9 ‘Q’ || ceil( to_char(trans_date,’mm’)/3) || ‘ FY’
10 || to_char(trans_date,’yyyy’) QTR_YYYY,
11 cast( to_char( trans_date, ‘yyyy’ ) as number ) YYYY
12 from sales

create materialized view sales_mv
2 build immediate
3 refresh on demand
4 enable query rewrite
5 as
6 select sales.cust_id, sum(sales.sales_amount) sales_amount,
7 time_hierarchy.mmyyyy
8 from sales, time_hierarchy
9 where sales.trans_date = time_hierarchy.day
10 group by sales.cust_id, time_hierarchy.mmyyyy


 create dimension time_hierarchy_dim
2 level day is time_hierarchy.day
3 level mmyyyy is time_hierarchy.mmyyyy
4 level qtr_yyyy is time_hierarchy.qtr_yyyy
5 level yyyy is time_hierarchy.yyyy
6 hierarchy time_rollup
7 (
8 day child of
9 mmyyyy child of
10 qtr_yyyy child of
11 yyyy
12 )
13 attribute mmyyyy
14 determines mon_yyyy;


This tells Oracle that the DAY column of the TIME_HIERARCHY table implies MMYYYY, which in turn implies QTR_YYYY. Finally, QTR_YYYY implies YYYY.

By creating the above dimension, the above MV will be used by query re-writes even if higher levels of aggregation was used in calling sqls.