Saturday, November 23, 2013

COMPOUND Triggers in Oracle 11G

Let see how to use compound triggers in ORACLE 11G onwards...

Before start with compound trigger, first we will go through the existing trigger flow prior to ORACLE 11G.

Before 11G:
---------------

Create a test table and before statement, before row level, after row level, after statement triggers on the test table created.

SQL> create table triggertest_tab (col1 int);
Table created.
SQL> create or replace trigger triggertest_tab_before_stmt
  2  before insert on triggertest_tab
  3  begin
  4  dbms_output.put_line ('Message From before insert stmt level trigger');
  5  end;
  6  /
Trigger created.
SQL> create or replace trigger triggertest_tab_before_row
  2  before insert on triggertest_tab
  3  for each row
  4  begin
  5  dbms_output.put_line ('Message From before insert row level trigger');
  6  end;
  7  /
Trigger created.
SQL> create or replace trigger triggertest_tab_after_row
  2  after insert on triggertest_tab
  3  for each row
  4  begin
  5  dbms_output.put_line ('Message From after insert row level trigger');
  6  end;
  7  /
Trigger created.
SQL> create or replace trigger triggertest_tab_after_stmt
  2  after insert on triggertest_tab
  3  begin
  4  dbms_output.put_line ('Message From after insert stmt level trigger');
  5  end;
  6
  7  /
Trigger created.


Now, try insert a record into test table

SQL> set serveroutput on;

SQL> insert into triggertest_tab values(1);
Message From before insert stmt level trigger
Message From before insert row level trigger
Message From after insert row level trigger
Message From after insert stmt level trigger
1 row created.

This is how the existing functionality in prior to ORACLE 11G. We have to define triggers at various level separately.

From ORACLE 11G Onwards:
Now, From ORACLE 11G onwards, we can use compound trigger functionality to club one or more triggers into single compound trigger.


Lets create test table and write a compound trigger to have before statement, before row, after row, after statement triggers.

SQL> create table compound_test_tab (col1 int);

Table created.

SQL> create or replace trigger compound_trigger
  2  for insert
  3  on compound_test_tab
  4  compound trigger
  5      before statement is
  6          begin
  7              dbms_output.put_line ('Message From before insert stmt level trigger');
  8          end before statement;
  9      before each row is
 10          begin
 11              dbms_output.put_line ('Message From before insert row level trigger');
 12          end before each row;
 13      after each row is
 14          begin
 15              dbms_output.put_line ('Message From after insert row level trigger');
 16          end after each row;
 17      after statement is
 18          begin
 19              dbms_output.put_line ('Message From after insert stmt level trigger');
 20          end after statement;
 21  end compound_trigger;
 22  /
Trigger created.
SQL>
SQL>

Now, try insert into test table

SQL> insert into compound_test_tab values(1);
Message From before insert stmt level trigger
Message From before insert row level trigger
Message From after insert row level trigger
Message From after insert stmt level trigger
1 row created.

SQL>

This is how we can club multiple trigger levels into single compound trigger.

For more details, Refer Here

How to recover a dropped table in ORACLE

How to recover a dropped table in ORACLE

Use flashback table command to recover dropped table from ORACLE.

Lets observe the following example to recover a table:

First create a sample table:

SQL> create table test_recycle (column1 int);
Table created.

Now, lets check the contents of recyclebin

SQL> show recyclebin;

You may find the dropped objects after executing the above command or it may give no output which means none of the objects is dropped after last purge of recyclebin.

Now, drop the table we created

SQL> drop table test_recycle;
Table dropped.

Check the contents of recyclebin again

SQL> show recyclebin;
ORIGINAL NAME    RECYCLEBIN NAME                OBJECT TYPE  DROP TIME
---------------- ------------------------------ ------------ -------------------
TEST_RECYCLE     BIN$LkAZkkSCRV6VeiHhANUiHg==$0 TABLE        2013-11-24:11:32:58

See now, the table is in recyclebin. Which means we can recover this table using FLASHBACK TABLE command as follows

SQL> flashback table test_recycle to before drop;
Flashback complete.

Now, check whether table is recovered or not

SQL> desc test_recycle;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 COLUMN1                                            NUMBER(38)


This is how we can recover table...


ORA-38305: object not in RECYCLE BIN

This error is because we are trying to recover a table/object which is not in recyclebin.

Lets observe the following example:

Create a test table:
SQL> create table test_purge (column1 int);
Table created.
Now, drop the table using following command which will permanently drop the table from database

SQL> drop table test_purge purge;
Table dropped.

View the contents of recyclebin:
SQL> show recyclebin;

Object wont found in recyclebin

Now, try to recover the table using FLASHBACK BEFORE DROP, which will give the error as follows

SQL> flashback table test_purge to before drop;
flashback table test_purge to before drop
*
ERROR at line 1:
ORA-38305: object not in RECYCLE BIN


 

Monday, October 14, 2013

How to Install Oracle Database 11GR2 in Windows7


How to Install Oracle Database 11GR2 in Windows7

Step1: Download the Oracle database from http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html

Step2: In step-1, you are going to download 2 zip files. Make sure you extract both the zip files into same location/folder on Windows.

Step3: Click on setup.exe which starts the database installation

Step4:  Uncheck the checkbox as shown in below screen, if you dont want to receive security alerts
Oracle DB 11gR2 Win32 Windows2003-02B.jpg

Step5: Ignore the below warning, Click on YES to proceed further.

Oracle DB 11gR2 Win32 Windows2003-03.jpg

Step6:  Choose Create and Configure a database option and click next

Oracle DB 11gR2 Win32 Windows2003-04.jpg

Step7: Select Desktop Class if you are installing the Oracle on your personal laptop/desktop and click next

Oracle DB 11gR2 Win32 Windows2003-05.jpg

Step8: Accept the default paths and SID info as shown in below screen and click next
Oracle DB 11gR2 Win32 Windows2003-06.jpg

Step9:Installation do some memory checks and after sometime you could see the below screen
Oracle DB 11gR2 Win32 Windows2003-09.jpg

Step10: Click FINISH in above screen and installation starts
Oracle DB 11gR2 Win32 Windows2003-10.jpg

Step11: Note that step-10 take time to install the database and after few minutes you will get below window (DBCA) which creates and configures the database

Oracle DB 11gR2 Win32 Windows2003-11.jpg

Step-12: Installation completes and the below screen will display
Oracle DB 11gR2 Win32 Windows2003-12.jpg

Step13: Click on Password Management to change password of system accounts like sys, system, scott etc....

Step14:After the installation, you can access enterprise managet by using following link
https://localhost:1158/em

OEL DB 11gR2 64bit screenshot-17B.jpg

OEL DB 11gR2 64bit screenshot-18.jpg

Step15: Congratulations, Oracle Database is now ready to use :)

Thursday, September 26, 2013

Errors while running the reports 6i, reports 10g from sun solaris


REP-0004: Warning: Unable to open user preference file.
REP-3000: Internal error starting Oracle Toolkit.
REP-3000: Internal error starting Oracle Toolkit.
Xlib: connection to "160.95.49.111:1.0" refused by server
Xlib: Client is not authorized to connect to Server
REP-3000: Internal error starting Oracle Toolkit.


Fix:

Some times xvfb services on sun solaris server were not recongnized when we try to run reports 6i and/or reorts 10g.

We have to restart xvfb services on server to fix this error.