Wednesday, 7 January 2015

A Brief Introduction to Materialized Views.

Oracle Materialized View

This article is taken from: http://practical-tech.blogspot.com/2012/01/brief-introduction-to-materialized.html
The Following tutorial is prepared on Oracle Database 11gR2.

Materialized views facilitate you to execute a SQl query and 
save its results either locally or in a remote database.

After the Materialized view is initially populated it can be
refreshed later on to store fresh results into the underlying 
table.

Materialized Views are mainly used for two reasons:

1) Replication of data to separate remote databases.

2) For improving the performance of queries by computing
   and storing the results of complex aggregations of data.

   In situations where complex sql queries are performed
   mainly in reporting or datawarehouse environments
   Materialized Views are really helpful in improving 
   performance.
  
   Because whenever a SQL query is executed oracle database
   has to lot of work in order to retrieve the data, For
   example it may have to do sorting (Memory or Disk Based),
   it has to decide the execution plan for the sql statement
   (Do a full tables scan or a indexed based scan) and lots
   of other stuff before retrieving the requested data.

   These type of queries if performed repeatedly will
   affect the performance of the server in a negative
   way.

   But with Materialized Views the performance can be improved
   significantly, because when a materialized view is created
   it stores all the data along with the execution plans.
   So even if the query is executed repeatedly it will not eat
   up all the resources as it did earlier.
   

The Materialized view can be created on the base of tables,
views or other materialized views.

When a Materialized View is created, oracle also create a 
table with the same name as that of the materialized view
and also creates a materialized view object.
   
For the sake of simplicity we will only cover two
types of materialized views:

1) Complete - Refreshable Materialzed Views
2) Fast-refresh Materialized Views



COMPLETE REFERSH MATERIALIZED VIEWS


In this type of materialized view there is a complete
refresh of data at periodic intervals.


SQL> alter user scott identified by tiger account unlock;

User altered.

SQL> grant create materialized view to scott;

Grant succeeded.

SQL> conn scott;
Enter password: 
Connected.


SQL> create table sales(
  2  sales_id int,  
  3  sales_amt int,
  4  region_id int,
  5  sales_dtt timestamp,
  6  constraint sales_pk primary key (sales_id));

Table created.

SQL> insert into sales values(1,101,100,sysdate-50);
SQL> insert into sales values(2,511,200,sysdate-20)
SQL> insert into sales values(3,11,100,sysdate)
SQL> commit;

Now lets create a materialized view.

SQL> create materialized view sales_mv
  2  refresh
  3  complete
  4  next sysdate+1/1440
  5  as
  6  select sales_amt, sales_dtt from sales;

Materialized view created.


So above we have created a materialized view based on the sales
table, which will completely refresh itself after every one minute.



SQL> select mview_name, refresh_method, refresh_mode, build_mode,
fast_refreshable from user_mviews
where mview_name = 'SALES_MV';

MVIEW_NAME           REFRESH_ REFRESH_MODE BUILD_MOD FAST_REFRESHABLE
-------------------- -------- ------------ --------- ----------------
SALES_MV             COMPLETE DEMAND       IMMEDIATE NO

Materialized views can also be refreshed by (ON DEMAND or ON COMMIT).
Since i did not mention either of these clauses the default refresh is on
demand as seen above in REFRESH_MODE column.

If you query the user_objects you can see that several objects have 
been created.


SQL> col object_name format a20
SQL> select object_name, object_type from user_objects
     where object_name like 'SALES%'
     order by object_name;


OBJECT_NAME          OBJECT_TYPE
-------------------- -------------------
SALES                TABLE
SALES_MV             MATERIALIZED VIEW
SALES_MV             TABLE
SALES_PK             INDEX



The materialized view is basically a logical container that
stores data in a regular table.

If you query the USER_SEGMENTS view you will find the base table
its primary-key and the table that stores the data returned by
the Materialized View.


SQL> select segment_name,segment_type from user_segments
  2  where segment_name like 'SALES%'
  3  order by segment_name;

SEGMENT_NAME    SEGMENT_TYPE
------------    ---------------
SALES           TABLE
SALES_MV        TABLE
SALES_PK        INDEX


Now lets check the already existing data and some more.

SQL> select sales_amt, to_char(sales_dtt,'dd-mon-yyyy') from sales_mv;


 SALES_AMT TO_CHAR(SAL
---------- -----------
       101 22-nov-2011
       511 22-dec-2011
        11 11-jan-2012


SQL> insert into sales values(4,99,200,sysdate);

1 row created.


SQL>insert into sales values(5,127,300,sysdate);

1 row created.

SQL> commit;

Commit complete.


After one minute the materialized view will get updated.

SQL> select sales_amt, to_char(sales_dtt,'dd-mon-yyyy') from sales_mv;

SQL>  SALES_AMT  TO_CHAR(SAL
      ---------- -----------
             101 22-nov-2011
             511 22-dec-2011
              11 11-jan-2012
              99 11-jan-2012
             127 11-jan-2012

 
if you have set a longer refresh interval and you do not
want to wait that long you can order the refresh manually
through the following command.


SQL> exec dbms_mview.refresh('SALES_MV','C');

PL/SQL procedure successfully completed.

# Where "C" stands for complete refresh.


So the whole process can ve summarized as following.

1) User or application creates transactions.
2) Base table is updated because of the transactions.
3) A complete refresh occurs or is done manually and
   the data in the materialized view is deleted and completely
   refreshed with the contents of the master table(SALES).
4) The User or application can query the materialized view
   which contains a point in time snapshot of the base table's data.



FAST REFRESH MATERIALIZED VIEW

Fast refreshable materialized views work a little bit differently.
When a fast refresh materialized view is created it initially
populates the materialized view table with data from the base or
master table.

After the initial data is populated only modified data is applied
to the materialized view table after each refresh, Instead of a
complete refresh like that in Complete refresh materialized views.

Three basic steps are required to create a fast refresh
materialized view.

1) Create a base or master table if it does not exist.
2) Create a Materialized view log on the base table.
3) Create a fast refresh materialized view.

Since i have already created a materialized view and base table 
i am going to drop them and make a fresh start.

SQL> drop materialized view sales_mv;

Materialized view dropped.

SQL> drop table sales purge;

Table dropped.


SQL> create table sales(
  2  sales_id int,
  3  sales_amt int,
  4  region_id int,
  5  sales_dtt timestamp
  6 );


SQL> alter table sales add constraint sales_pk primary key(sales_id);

Table altered.


SQL> desc sales;

 Name                 Null?    Type
 ------------------ -------- ---------------------
 SALES_ID           NOT NULL NUMBER(38)
 SALES_AMT                   NUMBER(38)
 REGION_ID                   NUMBER(38)
 SALES_DTT                   TIMESTAMP(6)



SQL> insert into sales values(1,101,100,sysdate-50);

1 row created.

SQL> insert into sales values(2,511,200,sysdate-20);

1 row created.

SQL> insert into sales values(3,11,100,sysdate);

1 row created.

SQL> commit;

Commit complete.

SQL> 

When creating a fast refreshable materialized view a materialized
view log is required.

The reason behind this is that the log keeps track of all the 
changes made to the master table, so when a materialized view 
is refreshed only updated data is applied.

It is something similar to the "block change tracking file" 
feature in RMAN.

Further a materialized view can be created on the basis of
primary key or by ROWID.

If the master table has a primary key then primary key clause
can be used otherwise use ROWID.

Now lets create a materialized view log on the master table.

SQL> create materialized view log on sales with primary key;

Materialized view log created.

If your base table does not have a primary key then a following
error will occur.

ORA-12014: table does not contain primary key constraint

In that case make materialized view log based on ROWID.

SQL> create materialized view log sales with rowid;


Also, when creating a materialized view you have to mention whether
the data is refreshed via PRIMARY KEY or ROWID.

We are creating a materialized view based on primary key refresh.

NOTE: The primary key columns must be part of the MV select query from
      the base table.


SQL> create materialized view sales_mv
     refresh
     with primary key
     fast
     next sysdate+3/1440
     as
     select sales_id, sales_amt, sales_dtt from sales


Materialized view created.

Now lets query the USER_OBJECTS view.

SQL> select object_name, object_type from user_objects
  2  where object_name like '%SALES%'
  3  order by object_name;

OBJECT_NAME          OBJECT_TYPE
-------------------- -------------------
MLOG$_SALES          TABLE
RUPD$_SALES          TABLE
SALES                TABLE
SALES_MV             MATERIALIZED VIEW
SALES_MV             TABLE
SALES_PK             INDEX
SALES_PK1            INDEX

7 rows selected.


Explanation.

MLOG$_SALES = This is a table created along with the materialized view.
              It contains data that has changed in the base table.

RUPD$_SALES = This table is created when a materialized view
              uses primary key for fast refresh. This is used
              to support updatable materialized views. But right
              now we are creating Read only MVs so ignore this table. 

SALES_PK1 = This index is automatically created and is based on the
            primary key columns of the base table.



SQL> select sales_amt, to_char(sales_dtt,'dd-mon-yyyy') from sales_mv;

 SALES_AMT TO_CHAR(SAL
---------- -----------
       101 23-nov-2011
       511 23-dec-2011
        11 12-jan-2012

Lets add some records.

SQL> insert into sales values(4,99,200,sysdate);

1 row created.

SQL> insert into sales values(5,127,300,sysdate);

1 row created.

SQL> commit;

Commit complete.


Now before refresh the mlog$_sales table
will contain information about the two changes that
have been made to the base table.


SQL> select count(*) from mlog$_sales;

  COUNT(*)
----------
         2

Wait for three minutes or refresh the view manually.

SQL> exec dbms_mview.refresh('SALES_MV','F');

Lets check the records.

SQL> select sales_amt, to_char(sales_dtt,'dd-mon-yyyy') from sales_mv;

 SALES_AMT TO_CHAR(SAL
---------- -----------
       101 23-nov-2011
       511 23-dec-2011
        11 12-jan-2012
        99 12-jan-2012
       127 12-jan-2012


After the refresh is complete and the data is refreshed
the MLOG$_SALES table will contain no records.

SQL> select count(*) from mlog$_sales;

  COUNT(*)
----------
         0

You can also check time of the last refresh when it happened.

 SQL> select mview_name, last_refresh_type, last_refresh_date
     from user_mviews;

MVIEW_NAME                     LAST_REF LAST_REFR
------------------------------ -------- ---------
SALES_MV                       FAST     12-JAN-12

The whole process above is summarized as following:

1) User or application creates transactions.
2) Data is commited in the base table.
3) Then the MVlog table is populated with the changes.
4) A fast refresh occurs automatically or manually.
5) All the changes that have been made since last refresh
   are applied to the materialized view and rows that are no
   longer required are deleted from MVlog table.
6) The users can query the materialized view which contains
   point in time snapshot of master tables data.



---------------------------------------------------------------------
Working script example to test Materialized View
create table custusg.test
(id number(4) primary key,
name varchar2(40),
createdon date);

insert into custusg.test
values(2,'MOHSIN',sysdate);

update custusg.test
set name = 'FAHAD'
where id = 2;

select * from  custusg.test;

drop materialized view custusg.mv_test;

create  materialized view custusg.mv_test
refresh complete
next sysdate+1/1440
as 
select i.inquiry_id,inquiry_number 
from custusg.cust_usg_ont_inquiry i, custusg.cust_usg_ont_pcosting p
where i.inquiry_id = p.inquiry_id;



select * from custusg.mv_test;


select mview_name, refresh_method, refresh_mode, build_mode,
fast_refreshable 
from all_mviews
where mview_name = 'MV_TEST';





Wednesday, 24 December 2014

Oracle Cash Management Configuration

Oracle Cash Management Configuration

Oracle Cash Management

Oracle Cash Management is an open integrated solution for managing your company/enterprise-wide cash cycle. Oracle Cash Management is an enterprisewide solution for managing liquidity and controlling cash. Cash Management gives you direct access to expected cash flows from your operational systems. You can quickly analyze enterprisewide cash management, cash requirements and currency exposures, ensuring liquidity and optimal use of cash resources. Using Oracle Cash Management companies can project cash flows from Oracle General Ledger, Oracle Receivables, Oracle Payables, Oracle Payroll, Oracle Projects and Oracle Purchasing. Oracle Cash Management lets you automatically or manually record and reconcile bank statements, matching against system transactions using rules and tolerance levels. You can review and correct any import validation or reconciliation errors online. Oracle Cash Management can automatically reconcile correcting statement lines against error statement lines and provide an audit trail for verifying correction of bank errors. Oracle Cash Management is part of the Oracle Financials family of applications.

Configuration Steps

1. Define System Parameters

Use the System Parameters window to configure your Cash Management system to meet your business needs. System parameters determine, for example, which set of books Cash Management uses, the default options for manual reconciliation windows, and the control settings for the AutoReconciliation program. Navigation path: Cash Management>Setup>System>System Parameters

2. Run Security Wizard

Using the Cash Management Security wizard, an administrator can assign multiple legal entities to a role or roles to set up the following three securities:
  • Bank Account Maintenance security – control bank account creation and updates
  • Bank Account Use security – control bank account access
  • Bank Account Fund Transfers security – control bank account transfers
For this purpose login through SYSADMIN default user and assign legal entity. Otherwise the user has to be given with relevant privileges to run this security wizard. User Name: SYSADMIN Navigation path: User Management>Roles & Role Inheritance

3. Bank Account Lookup Types

In Oracle Cash Management we can define lookup values for Bank Account Type. This lookup is extensible which can be defined current, saving, etc.Navigation path: Cash Management>Lookups

4. Define Bank(s)

The first step in the bank account creation is the bank definition. This means that which are the banks in which a company has accounts. This page allows you to search for existing banks, view and update them or create new banks.Navigation path: Cash Management>Setup>Banks>Banks

5. Define Branch(s)

Bank branch creation is the next step after the bank creation. Under a bank there must be branch(s) at different locations. This setup step allows you to search for existing bank branches, view and update them or create new bank branches. Navigation path:  Cash Management>Setup>Banks>Banks

6. Define Bank Account(s)

Once the bank and branch are created, you can proceed to the bank account setup. Select the bank branch you want to associate to your bank account. Assign the owner of the bank account. There are four areas associated to defining the account: general information, control of the account, security access to the account, and business unit assignment. If this is a Payable or Receivable account, the accounts are identified by business unit, and if a Payroll account, by legal entity. Navigation path: Cash Management>Setup>Banks>Bank Accounts

7. Define Check Book(s)

For each account Check Book is created in Oracle Cash Management. On payment automatic sequence number is assigned to the payment document.Navigation path: Cash Management>Setup>Banks>Bank Accounts After the configuration of these steps we are able to make entries in Oracle Cash Management.

Tuesday, 23 December 2014

oci_connect() ora-06413

To resolve oci_connect() ora-06413 error. Simple move your installation from Program Files (x86) folder to some where else. Because of () in the path connectivity issue arises.

Tags:
Oracle PHP Connection error, oci_connect() ora-06413

Thursday, 18 December 2014

Deploy Oracle EBS OAF Page on Server

Deploy Oracle EBS OAF Page on Server

1: Copy your all OAF page files to the server on a path similar like: /u01/oracle/PROD/apps/apps_st/comn/java/classes/oracle/apps/fnd

2 Execute Import Command (For Windows) through Command prompt similar like:
D:\OAF\jdevbin\oaext\bin>import D:\OAF\jdevhome\jdev\myprojects\oracle\apps\fnd\
sample_pic\webui\samplePicPg.xml -username apps -password appsSu990rt -rootdir
D:\OAF\jdevhome\jdev\myprojects -dbconnection "(DESCRIPTION=(ADDRESS=(PROTOCOL=t
cp)(HOST=192.168.20.101)(PORT=1521))(CONNECT_DATA=(SID=prod)))"


3) Create Function 

Type: Sswa jsp function
HTML path should be something like: OA.jsp?page=/oracle/apps/ak/emp_pic/webui/empPicPg

4) Bounce Apps Node only

5) Check your Oracle OAF Deployed page.


Tags:
Oracle EBS, OAF, Deploy OAF page

Wednesday, 10 December 2014

Error: JSP files must reside in the server root directory or a subdirectory beneath it

Oracle OAF E Business Suite Errors


Error: JSP files must reside in the server root directory or a subdirectory beneath it 

























Tags:
Error: JSP files must reside in the server root directory or a subdirectory beneath it 

Thursday, 4 December 2014

Oracle EBusiness Suite script commands

DB Node Commands
adautocfg.sh  
addbctl.sh   
adexecsql.pl  
adpreclone.pl  
adstrtdb.sql
adchknls.pl   
addlnctl.sh  
adlsnodes.sh  
adstopdb.sql



Apps Node Commands

adstpall.sh
To Down the apps node

adstrtal.sh
To start the apps node

adalnctl.sh   
adforms-c4wsctl.sh  
adopmnctl.sh             
mwactlwrpr.sh
adapcctl.sh   
adformsctl.sh       
adpreclone.pl  
java.sh      
adautocfg.sh  
adformsrvctl.sh     
jtffmctl.sh
adcmctl.sh    
adoacorectl.sh      
adexecsql.pl  
adoafmctl.sh        
gsmstart.sh    
mwactl.sh

Monday, 1 December 2014

Work Flow Builder Error Messages

Work Flow Builder Error Messages

Error:
3146: Commit happened in activity/function error in my workflow.
Resolution:


Error:
Error in Workflow NEW_TYPE/100_242 ORA-04061: existing state of has been invalidated ORA-04061: existing state of package 
Resolution:





Tags: Work Flow Builder Error Message