Monday, April 28, 2014

How Oracle Database Works

The following example describes Oracle Database operations at the most basic level. 
This illustrates an Oracle Database configuration where the user and associated server 
process are on separate computers, connected through a network.

1.   An instance has started on the computer running Oracle Database, often called the 
     host or database server. 

2.   A computer running an application (a local computer or client workstation) runs 
     an application in a user process. The client application attempts to establish a 
     connection to the server using the proper Oracle Net Services driver.

3.   The server is running the proper Oracle Net Services driver. The server detects the 
     connection request from the application and creates a dedicated server process on 
     behalf of the user process. 

4.   The user runs a SQL statement and commits the transaction. For example, the user 
     changes a name in a row of a table. 

5.   The server process receives the statement and checks the shared pool (an SGA 
     component) for any shared SQL area that contains a similar SQL statement. If a 
     shared SQL area is found, then the server process checks the user's access 
     privileges to the requested data, and the existing shared SQL area is used to 
     process the statement. If not, then a new shared SQL area is allocated for the 
     statement, so it can be parsed and processed. 

6.   The server process retrieves any necessary data values, either from the actual 
     datafile (table) or those stored in the SGA. 

7.   The server process modifies data in the system global area. The database writer 
     process (DBWn) writes modified blocks permanently to disk when doing so is 
     efficient. Because the transaction is committed, the log writer process (LGWR) 
     immediately records the transaction in the redo log file. 

8.   If the transaction is successful, then the server process sends a message across the 
     network to the application. If it is not successful, then an error message is 
     transmitted. 

9.   Throughout this entire procedure, the other background processes run, watching 
     for conditions that require intervention. In addition, the database server manages 
     other users' transactions and prevents contention between transactions that 
     request the same data. 

Sunday, April 27, 2014

Find Top 10 SQL In Oracle Database

Using this you can find out TOP SQL Statement from your database.


SELECT *
  FROM (  SELECT username,
                 LAST_LOAD_TIME,
                 sql_text,
                 sql_id,
                 elapsed_time,
                 cpu_time,
                 user_io_wait_time
            FROM sys.v_$sqlarea s, dba_users u
           WHERE     u.USER_ID = s.PARSING_USER_ID
                 AND TRUNC (LAST_LOAD_TIME) = TRUNC (SYSDATE)
                 AND u.username =user
        ORDER BY 6 DESC)
 WHERE ROWNUM < 10;

Thursday, April 24, 2014

Filter data from Oracle PL/SQL Collection.

This is very interesting for me. I have fine a solution for filter data form collection. 

CREATE TYPE dept_t AS OBJECT
(
DEPARTMENT_ID NUMBER (10) ,
DEPARTMENT_NAME VARCHAR2 (300) ,
MANAGER_ID NUMBER (10) ,
LOCATION_ID NUMBER (10)) ;

CREATE TYPE dept_tab IS TABLE OF dept_t;

create or replace PROCEDURE DPR_COLLECTION_FILTER IS

T_RC dept_tab:=dept_tab();
T_DATA dept_tab:=dept_tab();

BEGIN

SELECT dept_t (DEPARTMENT_ID , DEPARTMENT_NAME , MANAGER_ID , LOCATION_ID) bulk collect INTO T_RC FROM DEPARTMENTS;

SELECT dept_t (DEPARTMENT_ID , DEPARTMENT_NAME , MANAGER_ID , LOCATION_ID) bulk collect INTO T_DATA FROM TABLE(T_RC) t WHERE t.DEPARTMENT_ID > 30;

FOR I IN T_DATA.FIRST .. T_DATA.LAST LOOP

DBMS_OUTPUT.PUT_LINE(T_DATA(I).DEPARTMENT_ID|| ' >> '||T_DATA(I).DEPARTMENT_NAME);

END LOOP;

END;