SlideShare a Scribd company logo
1 of 40
Download to read offline
Oracle Edition Based
    Redefinition

       Presentation for




                          http://surachartopun.com
Introduction
•   Surachart Opun
•   Blog: surachartopun.com
•   Oracle ACE
•   OCP 10G/11G and OCE (RAC)
•   Member: OUGTH, IOUG, UKOUG, RAC SIG
•   Twitter: @surachart




                                          http://surachartopun.com
Edition Based Redefinition (EBR)?
• New Feature on 11gR2
• Upgrade an application while it is in use
• Edition object types
   – SYNONYM
   – VIEW
   – All PL/SQL object types:
     (FUNCTION,LIBRARY,PACKAGE and PACKAGE
     BODY,PROCEDURE,TRIGGER,TYPE and TYPE BODY)


                                       http://surachartopun.com
Three New Object Types
• Edition
   – Replacing Edition object types (PL/SQL, synonyms,
     and views)
• Editioning View
   – Table is not an edition type. If you change the
     structure of one or more tables.
• Crossedtion trigger
   – Other users must be able to change data in the
     tables while you are changing their structure
   – If the pre- and post-upgrade applications will be in
     ordinary use at the same time
                                               http://surachartopun.com
Dictionary Views
• Edition
   – dba_editions
   – dba_edition_comments
• Editioning View
   – dba_editioning_views
   – dba_editioning_views_ae (edition_name)
   – dba_editioning_view_cols
• Crossedition Trigger
   – dba_triggers (crossedition)
                                          http://surachartopun.com
What is an Edition?
• A nonschema object type, uniquely identified,
  therefore, by just its name.
• Be able to check in DBA_OBJECTS.

    select * from dba_objects where object_type=
                      ’EDITION’;

• Every database from 11.2 onwards - Least one
  edition.
• The default edition name is ORA$BASE
                                            http://surachartopun.com
• A new edition must be created as the child of an
  existing one.

      create edition version2 as child of ora$base;

• An edition may have no more than one child.

   ORA$BASE <- VERSION2 <- VERSION3 <- VERSION4

create edition version2 as child of ora$base;
create edition version3 as child of version2;
create edition version4 as child of version3;
                                                http://surachartopun.com
SQL> select * from dba_editions;
EDITION_NAME PARENT_EDITION_NAME                           USA
---------------------- ------------------------------ ---
ORA$BASE                                              YES
VERSION4                       VERSION3                   YES
VERSION2                       ORA$BASE                   YES
VERSION3                       VERSION2                   YES




                                                       http://surachartopun.com
• A new database property, DEFAULT_EDITION.

     alter database default edition = Some_Edition

SQL> select PROPERTY_NAME, PROPERTY_VALUE
from database_properties
where PROPERTY_NAME='DEFAULT_EDITION';
PROPERTY_NAME                        PROPERTY_VALUE
------------------------------ --------------------
DEFAULT_EDITION                     ORA$BASE


                                               http://surachartopun.com
• A new alter session command allows the edition that
  a session is using to be changed.

      alter session set edition = Some_Edition

SQL> alter session set edition=version3;
Session altered.
SQL> SELECT SYS_CONTEXT
 ('userenv','current_edition_name') ce FROM DUAL;
CE
----------
VERSION3
                                                 http://surachartopun.com
Edition Privileges
• System Privileges
   – CREATE ANY EDITION
   – ALTER ANY EDITION
   – DROP ANY EDITION
• Object Privileges - USE (not granted by default)
      GRANT USE ON <edition_name> TO <user_name>;

• Roles
  system privileges are granted to the DBA role (only).
• Enable Editioning
      ALTER USER <user_name> ENABLE EDITIONS;

                                                     http://surachartopun.com
Edition Enabled Data Dictionary
               Views
• AUD$ (obj$edition)
• DBA_EDITIONS (edition_name,
  parent_edition_name)
• DBA_OBJECTS (edition_name)
• DBA_OBJECTS_AE (edition_name)
• DBA_SOURCE_AE (edition_name)
• DBA_USERS (editions_enabled)

             • AE = All Editions
                                   http://surachartopun.com
Edition Enabled Data Dictionary
                 Views
•   FGA_LOG$ (obj$edition)
•   UTL_RECOMP_ALL_OBJECTS (edition_name)
•   V$LOGMNR_CONTENTS (edition_name)
•   V$SESSION (session_edition_id)

                 • AE = All Editions




                                        http://surachartopun.com
SQL> SELECT * FROM DBA_EDITIONS;
EDITION_NAME                       PARENT_EDITION_NAME              USA
------------------------------ ------------------------------ ---
 ORA$BASE                                              YES

SQL> CREATE EDITION VERSION2 AS CHILD OF ORA$BASE;
Edition created.

SQL> SELECT * FROM DBA_EDITIONS;
    EDITION_NAME                        PARENT_EDITION_NAME           USA
------------------------------ ------------------------------ ---
ORA$BASE                                              YES
VERSION2                      ORA$BASE                        YES

SQL> ALTER USER DEMO ENABLE EDITIONS;

SQL> GRANT USE ON EDITION VERSION2 TO DEMO;
                                                                          http://surachartopun.com
SQL> connect demo/demo
Connected.

SQL> SELECT SYS_CONTEXT ('userenv','current_edition_name') ce FROM DUAL;

CE
--------------------------------------------------------------------------------
ORA$BASE

SQL> create or replace procedure my_procedure
as
Begin
  dbms_output.put_line ( 'I am version 1.0' );
end;
/




                                                                                   http://surachartopun.com
SQL> ALTER SESSION SET EDITION=VERSION2;
Session altered.

SQL> create or replace procedure my_procedure
as
Begin
  dbms_output.put_line ( 'I am version 2.0' );
end;
/

SQL> SELECT SYS_CONTEXT ('userenv','current_edition_name') ce FROM
    DUAL;
CE
--------------------------------------------------------------------------------
ORA$BASE


                                                                       http://surachartopun.com
SQL> exec my_procedure;
I am version 1.0

SQL> ALTER SESSION SET EDITION=VERSION2;
Session altered.

SQL> SELECT SYS_CONTEXT ('userenv','current_edition_name') ce FROM
    DUAL;
CE
--------------------------------------------------------------------------------
VERSION2

SQL> exec my_procedure;
I am version 2.0



                                                                       http://surachartopun.com
What is an Editioning View?
• Editioning view selects a subset of the columns from
  a single base table.
• Use the SQL statement CREATE VIEW with the OR
  REPLACE clause and the keyword EDITIONING.

      CREATE OR REPLACE EDITIONING VIEW …

• Partition-Extended Editioning View Names


                                             http://surachartopun.com
Editioning View Related Data
            Dictionary Views
•   DBA_EDITIONING_VIEW_COLS
•   DBA_EDITIONING_VIEW_COLS_AE
•   DBA_EDITIONING_VIEWS
•   DBA_EDITIONING_VIEWS_AE
•   DBA_ERRORS_AE (editioning_name)
•   DBA_OBJECTS_AE (editioning_name)
•   DBA_VIEWS (editioning_view)

                  • AE = All Editions

                                        http://surachartopun.com
SQL> CREATE EDITIONING VIEW ed01_tab AS SELECT name, tel_num FROM
   ed01_tab_tmp;

SQL> select * from ED01_TAB partition (par_1);
NAME                        TEL_NUM
------------------------------ ----------
TEST1                      1234567
TEST5                      1234567

SQL> CREATE TRIGGER ed01_tab_tri
BEFORE INSERT ON ed01_tab FOR EACH ROW
BEGIN
     null;
END;
/
Trigger created.

                                                       http://surachartopun.com
What is a Crossedition Trigger?
• A new, and special type of trigger specific to
  editioning
• Can only be created on a table (not on an editioning
  view)
• Propagates transactions between editions
• Two types
   – FORWARD
   – REVERSE



                                             http://surachartopun.com
• Crossedition triggers are always created in the child
• Crossedition triggers are temporary—drop them
  after you have made the restructured tables
  available to all users.




                                               http://surachartopun.com
Crossedition Trigger Types
• Forward Crossedition Triggers
   – Only fired by code running in the parent edition
   – Transforms from the old representation to the
     new
• Reverse Crossedition Triggers
   – Only fired by code running in the child edition
   – Transforms from the new representation to the
     old


                                              http://surachartopun.com
Crossedition Trigger Related Data
             Dictionary Views
•   DBA_TRIGGERS
•   DBA_TRIGGER_ORDERING
•   DBA_ERRORS_AE (editioning_name)
•   DBA_OBJECTS_AE (editioning_name)



                  • AE = All Editions



                                        http://surachartopun.com
CREATE TABLE PERSONS (ID NUMBER(10) NOT NULL, FIRST_NAME VARCHAR2(100)
   NOT NULL, LAST_NAME VARCHAR2(100) NOT NULL,EMAIL VARCHAR2(100) NOT
   NULL)
/

RENAME persons TO persons_tab;

CREATE EDITIONING VIEW persons AS
SELECT id, first_name AS firstname, last_name AS lastname, email FROM persons_tab;

create sequence persons_seq;




                                                                    http://surachartopun.com
CREATE OR REPLACE TRIGGER persons_bi_trg
BEFORE INSERT ON persons FOR EACH ROW
BEGIN
 :new.id := persons_seq.nextval;
END;
/

insert into persons values (null,'Somchai','A.','somchai@test.com');
commit;

ALTER TABLE persons_tab ADD (email_recipient VARCHAR2(100),email_domain
   VARCHAR2(100));

SQL> select * from persons;
      ID FIRSTNAME             LASTNAME             EMAIL
---------- --------------- --------------- --------------------
       1 Somchai            A.           somchai@test.com

                                                                       http://surachartopun.com
alter session set edition=VERSION2;

CREATE TRIGGER persons_fc_trg
BEFORE INSERT OR UPDATE ON persons_tab FOR EACH ROW
FORWARD CROSSEDITION
DISABLE
BEGIN
:new.email_recipient :=
   regexp_substr(:new.email,'(.*)@',1,1,NULL,1);
:new.email_domain :=
regexp_substr(:new.email,'@(.*)',1,1,NULL,1);
END;
/




                                                      http://surachartopun.com
column CE for a10
SELECT SYS_CONTEXT ('userenv','current_edition_name') ce FROM DUAL;

CREATE OR REPLACE EDITIONING VIEW persons AS
SELECT id, first_name AS firstname, last_name AS
   lastname,email_recipient,email_domain FROM persons_tab;

SQL> select * from persons;

      ID FIRSTNAME             LASTNAME             EMAIL_RECIPIENT EMAIL_DOMAIN
---------- --------------- --------------- -------------------- --------------------
       1 Somchai            A.




                                                                               http://surachartopun.com
ALTER TRIGGER persons_fc_trg ENABLE;

DECLARE
c INTEGER;
r INTEGER;
BEGIN
c := dbms_sql.open_cursor;
dbms_sql.parse(
c => c,
statement => 'UPDATE persons SET email_domain = email_domain',language_flag =>
     dbms_sql.native,
apply_crossedition_trigger => 'persons_fc_trg');
r := dbms_sql.execute(c);
dbms_sql.close_cursor(c);
COMMIT;
END;
/


                                                                  http://surachartopun.com
SQL> select * from persons;
      ID FIRSTNAME             LASTNAME             EMAIL_RECIPIENT EMAIL_DOMAIN
---------- --------------- --------------- -------------------- --------------------
       1 Somchai            A.           somchai               test.com

---TEST FORWARD ---

alter session set edition=ORA$BASE;

update persons set email='surachart@gmail.com' where id=1;
commit;

SQL> select * from persons;
      ID FIRSTNAME             LASTNAME             EMAIL
---------- --------------- --------------- -------------------------
       1 Somchai            A.           surachart@gmail.com



                                                                               http://surachartopun.com
alter session set edition=version2;

SQL> select * from persons;
      ID FIRSTNAME             LASTNAME             EMAIL_RECIPIENT EMAIL_DOMAIN
---------- --------------- --------------- -------------------- --------------------
       1 Somchai            A.           surachart             gmail.com




                                                                               http://surachartopun.com
---TEST REVERSE---

alter session set edition=version2;

CREATE TRIGGER persons_rc_trg
BEFORE INSERT OR UPDATE ON persons_tab FOR EACH ROW
 REVERSE CROSSEDITION
 DISABLE
 BEGIN
 :new.email := :new.email_recipient || '@' || :new.email_domain;
END;
/

alter trigger persons_rc_trg enable;

insert into persons values (null,'Surachart','O.','surachart',‘test.com');
commit;



                                                                             http://surachartopun.com
SQL> select * from persons;
      ID FIRSTNAME             LASTNAME             EMAIL_RECIPIENT EMAIL_DOMAIN
---------- --------------- --------------- -------------------- --------------------
       1 Somchai           A.           surachart             gmail.com
       2 Surachart         O.            surachart             test.com

alter session set edition=ORA$BASE;

SQL> select * from persons;
      ID FIRSTNAME             LASTNAME             EMAIL
---------- --------------- --------------- ------------------------------
       1 Somchai           A.           surachart@gmail.com
       2 Surachart         O.            surachart@test.com




                                                                            http://surachartopun.com
Learn More…
• Oracle Documents (E11882_01)




                                 http://surachartopun.com
Learn More..
• Tom Kyte on Edition Based Redefinition




                                       http://surachartopun.com
Learn More…
• Bryn Llewellyn's White Paper




                                 http://surachartopun.com
Learn More…
• Morgan Library www.morganslibrary.org




                                     http://surachartopun.com
Learn More…
• IOUG – Select Journal




                            http://surachartopun.com
Q&A



      http://surachartopun.com
THANK YOU




            http://surachartopun.com

More Related Content

What's hot

Oracle applications 11i hot backup cloning with rapid clone
Oracle applications 11i hot backup cloning with rapid cloneOracle applications 11i hot backup cloning with rapid clone
Oracle applications 11i hot backup cloning with rapid cloneDeepti Singh
 
Oracle 12c: Database Table Rows Archiving testing
Oracle 12c: Database Table Rows Archiving testingOracle 12c: Database Table Rows Archiving testing
Oracle 12c: Database Table Rows Archiving testingMonowar Mukul
 
آموزش مدیریت بانک اطلاعاتی اوراکل - بخش پانزدهم
آموزش مدیریت بانک اطلاعاتی اوراکل - بخش پانزدهمآموزش مدیریت بانک اطلاعاتی اوراکل - بخش پانزدهم
آموزش مدیریت بانک اطلاعاتی اوراکل - بخش پانزدهمfaradars
 
Oracle applications 11i hot backup cloning with rapid clone
Oracle applications 11i hot backup cloning with rapid cloneOracle applications 11i hot backup cloning with rapid clone
Oracle applications 11i hot backup cloning with rapid cloneDeepti Singh
 
Database administration commands
Database administration commands Database administration commands
Database administration commands Varsha Ajith
 
Install and upgrade Oracle grid infrastructure 12.1.0.2
Install and upgrade Oracle grid infrastructure 12.1.0.2Install and upgrade Oracle grid infrastructure 12.1.0.2
Install and upgrade Oracle grid infrastructure 12.1.0.2Biju Thomas
 
12c database migration from ASM storage to NON-ASM storage
12c database migration from ASM storage to NON-ASM storage12c database migration from ASM storage to NON-ASM storage
12c database migration from ASM storage to NON-ASM storageMonowar Mukul
 
Flashback (Practical Test)
Flashback (Practical Test)Flashback (Practical Test)
Flashback (Practical Test)Anar Godjaev
 
Moving 12c database from NON-ASM to ASM
Moving 12c database from NON-ASM to ASMMoving 12c database from NON-ASM to ASM
Moving 12c database from NON-ASM to ASMMonowar Mukul
 
Cloning Oracle EBS R12: A Step by Step Procedure
Cloning Oracle EBS R12: A Step by Step ProcedureCloning Oracle EBS R12: A Step by Step Procedure
Cloning Oracle EBS R12: A Step by Step ProcedureOrazer Technologies
 
12c db upgrade from 11.2.0.4
12c db upgrade from 11.2.0.412c db upgrade from 11.2.0.4
12c db upgrade from 11.2.0.4uzzal basak
 
Oracle 10g Performance: chapter 00 sampling
Oracle 10g Performance: chapter 00 samplingOracle 10g Performance: chapter 00 sampling
Oracle 10g Performance: chapter 00 samplingKyle Hailey
 
Les 02 Config Rec
Les 02 Config RecLes 02 Config Rec
Les 02 Config Recvivaankumar
 
Optimizer Cost Model MySQL 5.7
Optimizer Cost Model MySQL 5.7Optimizer Cost Model MySQL 5.7
Optimizer Cost Model MySQL 5.7I Goo Lee
 
Rman cloning when both directory and db name are same.
Rman cloning when both directory and db name are same.Rman cloning when both directory and db name are same.
Rman cloning when both directory and db name are same.subhani shaik
 

What's hot (19)

Physical_Standby_Database_R12.2.4
Physical_Standby_Database_R12.2.4Physical_Standby_Database_R12.2.4
Physical_Standby_Database_R12.2.4
 
Oracle ORA Errors
Oracle ORA ErrorsOracle ORA Errors
Oracle ORA Errors
 
Oracle applications 11i hot backup cloning with rapid clone
Oracle applications 11i hot backup cloning with rapid cloneOracle applications 11i hot backup cloning with rapid clone
Oracle applications 11i hot backup cloning with rapid clone
 
Oracle 12c: Database Table Rows Archiving testing
Oracle 12c: Database Table Rows Archiving testingOracle 12c: Database Table Rows Archiving testing
Oracle 12c: Database Table Rows Archiving testing
 
آموزش مدیریت بانک اطلاعاتی اوراکل - بخش پانزدهم
آموزش مدیریت بانک اطلاعاتی اوراکل - بخش پانزدهمآموزش مدیریت بانک اطلاعاتی اوراکل - بخش پانزدهم
آموزش مدیریت بانک اطلاعاتی اوراکل - بخش پانزدهم
 
Oracle applications 11i hot backup cloning with rapid clone
Oracle applications 11i hot backup cloning with rapid cloneOracle applications 11i hot backup cloning with rapid clone
Oracle applications 11i hot backup cloning with rapid clone
 
8i standby
8i standby8i standby
8i standby
 
Database administration commands
Database administration commands Database administration commands
Database administration commands
 
Install and upgrade Oracle grid infrastructure 12.1.0.2
Install and upgrade Oracle grid infrastructure 12.1.0.2Install and upgrade Oracle grid infrastructure 12.1.0.2
Install and upgrade Oracle grid infrastructure 12.1.0.2
 
12c database migration from ASM storage to NON-ASM storage
12c database migration from ASM storage to NON-ASM storage12c database migration from ASM storage to NON-ASM storage
12c database migration from ASM storage to NON-ASM storage
 
Flashback (Practical Test)
Flashback (Practical Test)Flashback (Practical Test)
Flashback (Practical Test)
 
Moving 12c database from NON-ASM to ASM
Moving 12c database from NON-ASM to ASMMoving 12c database from NON-ASM to ASM
Moving 12c database from NON-ASM to ASM
 
Db health check
Db health checkDb health check
Db health check
 
Cloning Oracle EBS R12: A Step by Step Procedure
Cloning Oracle EBS R12: A Step by Step ProcedureCloning Oracle EBS R12: A Step by Step Procedure
Cloning Oracle EBS R12: A Step by Step Procedure
 
12c db upgrade from 11.2.0.4
12c db upgrade from 11.2.0.412c db upgrade from 11.2.0.4
12c db upgrade from 11.2.0.4
 
Oracle 10g Performance: chapter 00 sampling
Oracle 10g Performance: chapter 00 samplingOracle 10g Performance: chapter 00 sampling
Oracle 10g Performance: chapter 00 sampling
 
Les 02 Config Rec
Les 02 Config RecLes 02 Config Rec
Les 02 Config Rec
 
Optimizer Cost Model MySQL 5.7
Optimizer Cost Model MySQL 5.7Optimizer Cost Model MySQL 5.7
Optimizer Cost Model MySQL 5.7
 
Rman cloning when both directory and db name are same.
Rman cloning when both directory and db name are same.Rman cloning when both directory and db name are same.
Rman cloning when both directory and db name are same.
 

Viewers also liked

การเพิ่มประสิทธิภาพ Instance memory - Oracle 11G
การเพิ่มประสิทธิภาพ Instance memory  - Oracle 11Gการเพิ่มประสิทธิภาพ Instance memory  - Oracle 11G
การเพิ่มประสิทธิภาพ Instance memory - Oracle 11GN/A
 
การตรวจเช็คฐานข้อมูล Oracle v1 draft
การตรวจเช็คฐานข้อมูล Oracle v1 draftการตรวจเช็คฐานข้อมูล Oracle v1 draft
การตรวจเช็คฐานข้อมูล Oracle v1 draftN/A
 
บทที่ 2 (1)
บทที่ 2 (1)บทที่ 2 (1)
บทที่ 2 (1)nopphanut
 
ออราเคิล (Oracle) Statspack (ติดตั้งและใช้งานเบื้องต้น)
ออราเคิล (Oracle) Statspack (ติดตั้งและใช้งานเบื้องต้น)ออราเคิล (Oracle) Statspack (ติดตั้งและใช้งานเบื้องต้น)
ออราเคิล (Oracle) Statspack (ติดตั้งและใช้งานเบื้องต้น)N/A
 

Viewers also liked (6)

การเพิ่มประสิทธิภาพ Instance memory - Oracle 11G
การเพิ่มประสิทธิภาพ Instance memory  - Oracle 11Gการเพิ่มประสิทธิภาพ Instance memory  - Oracle 11G
การเพิ่มประสิทธิภาพ Instance memory - Oracle 11G
 
การตรวจเช็คฐานข้อมูล Oracle v1 draft
การตรวจเช็คฐานข้อมูล Oracle v1 draftการตรวจเช็คฐานข้อมูล Oracle v1 draft
การตรวจเช็คฐานข้อมูล Oracle v1 draft
 
Web 2.0 สู่ Library 2.0
Web 2.0 สู่ Library 2.0Web 2.0 สู่ Library 2.0
Web 2.0 สู่ Library 2.0
 
บทที่ 2 (1)
บทที่ 2 (1)บทที่ 2 (1)
บทที่ 2 (1)
 
ออราเคิล (Oracle) Statspack (ติดตั้งและใช้งานเบื้องต้น)
ออราเคิล (Oracle) Statspack (ติดตั้งและใช้งานเบื้องต้น)ออราเคิล (Oracle) Statspack (ติดตั้งและใช้งานเบื้องต้น)
ออราเคิล (Oracle) Statspack (ติดตั้งและใช้งานเบื้องต้น)
 
Database Tuning for e-Learning
Database Tuning for e-LearningDatabase Tuning for e-Learning
Database Tuning for e-Learning
 

Similar to Basic - Oracle Edition Based Redefinition Presentation

Liquibase for java developers
Liquibase for java developersLiquibase for java developers
Liquibase for java developersIllia Seleznov
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowAlex Zaballa
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowAlex Zaballa
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowAlex Zaballa
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slidesmetsarin
 
DNN Database Tips & Tricks
DNN Database Tips & TricksDNN Database Tips & Tricks
DNN Database Tips & TricksWill Strohl
 
E business suite r12.2 changes for database administrators
E business suite r12.2 changes for database administratorsE business suite r12.2 changes for database administrators
E business suite r12.2 changes for database administratorsSrinivasa Pavan Marti
 
E business suite r12.2 changes for database administrators
E business suite r12.2 changes for database administratorsE business suite r12.2 changes for database administrators
E business suite r12.2 changes for database administratorsSrinivasa Pavan Marti
 
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Alex Zaballa
 
Liquibase migration for data bases
Liquibase migration for data basesLiquibase migration for data bases
Liquibase migration for data basesRoman Uholnikov
 
Sql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ISql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ICarlos Oliveira
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsAlex Zaballa
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsAlex Zaballa
 
resource governor
resource governorresource governor
resource governorAaron Shilo
 
Editioning use in ebs
Editioning use in  ebsEditioning use in  ebs
Editioning use in ebspasalapudi123
 
Refresh development from productions
Refresh development from productionsRefresh development from productions
Refresh development from productionsOsama Mustafa
 

Similar to Basic - Oracle Edition Based Redefinition Presentation (20)

Liquibase for java developers
Liquibase for java developersLiquibase for java developers
Liquibase for java developers
 
IR SQLite Session #1
IR SQLite Session #1IR SQLite Session #1
IR SQLite Session #1
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
 
DNN Database Tips & Tricks
DNN Database Tips & TricksDNN Database Tips & Tricks
DNN Database Tips & Tricks
 
E business suite r12.2 changes for database administrators
E business suite r12.2 changes for database administratorsE business suite r12.2 changes for database administrators
E business suite r12.2 changes for database administrators
 
E business suite r12.2 changes for database administrators
E business suite r12.2 changes for database administratorsE business suite r12.2 changes for database administrators
E business suite r12.2 changes for database administrators
 
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
 
Liquibase migration for data bases
Liquibase migration for data basesLiquibase migration for data bases
Liquibase migration for data bases
 
Less04 Instance
Less04 InstanceLess04 Instance
Less04 Instance
 
Sql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ISql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices I
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
Less04_Database_Instance.ppt
Less04_Database_Instance.pptLess04_Database_Instance.ppt
Less04_Database_Instance.ppt
 
resource governor
resource governorresource governor
resource governor
 
Editioning use in ebs
Editioning use in  ebsEditioning use in  ebs
Editioning use in ebs
 
Editioning use in ebs
Editioning use in  ebsEditioning use in  ebs
Editioning use in ebs
 
Refresh development from productions
Refresh development from productionsRefresh development from productions
Refresh development from productions
 

Basic - Oracle Edition Based Redefinition Presentation

  • 1. Oracle Edition Based Redefinition Presentation for http://surachartopun.com
  • 2. Introduction • Surachart Opun • Blog: surachartopun.com • Oracle ACE • OCP 10G/11G and OCE (RAC) • Member: OUGTH, IOUG, UKOUG, RAC SIG • Twitter: @surachart http://surachartopun.com
  • 3. Edition Based Redefinition (EBR)? • New Feature on 11gR2 • Upgrade an application while it is in use • Edition object types – SYNONYM – VIEW – All PL/SQL object types: (FUNCTION,LIBRARY,PACKAGE and PACKAGE BODY,PROCEDURE,TRIGGER,TYPE and TYPE BODY) http://surachartopun.com
  • 4. Three New Object Types • Edition – Replacing Edition object types (PL/SQL, synonyms, and views) • Editioning View – Table is not an edition type. If you change the structure of one or more tables. • Crossedtion trigger – Other users must be able to change data in the tables while you are changing their structure – If the pre- and post-upgrade applications will be in ordinary use at the same time http://surachartopun.com
  • 5. Dictionary Views • Edition – dba_editions – dba_edition_comments • Editioning View – dba_editioning_views – dba_editioning_views_ae (edition_name) – dba_editioning_view_cols • Crossedition Trigger – dba_triggers (crossedition) http://surachartopun.com
  • 6. What is an Edition? • A nonschema object type, uniquely identified, therefore, by just its name. • Be able to check in DBA_OBJECTS. select * from dba_objects where object_type= ’EDITION’; • Every database from 11.2 onwards - Least one edition. • The default edition name is ORA$BASE http://surachartopun.com
  • 7. • A new edition must be created as the child of an existing one. create edition version2 as child of ora$base; • An edition may have no more than one child. ORA$BASE <- VERSION2 <- VERSION3 <- VERSION4 create edition version2 as child of ora$base; create edition version3 as child of version2; create edition version4 as child of version3; http://surachartopun.com
  • 8. SQL> select * from dba_editions; EDITION_NAME PARENT_EDITION_NAME USA ---------------------- ------------------------------ --- ORA$BASE YES VERSION4 VERSION3 YES VERSION2 ORA$BASE YES VERSION3 VERSION2 YES http://surachartopun.com
  • 9. • A new database property, DEFAULT_EDITION. alter database default edition = Some_Edition SQL> select PROPERTY_NAME, PROPERTY_VALUE from database_properties where PROPERTY_NAME='DEFAULT_EDITION'; PROPERTY_NAME PROPERTY_VALUE ------------------------------ -------------------- DEFAULT_EDITION ORA$BASE http://surachartopun.com
  • 10. • A new alter session command allows the edition that a session is using to be changed. alter session set edition = Some_Edition SQL> alter session set edition=version3; Session altered. SQL> SELECT SYS_CONTEXT ('userenv','current_edition_name') ce FROM DUAL; CE ---------- VERSION3 http://surachartopun.com
  • 11. Edition Privileges • System Privileges – CREATE ANY EDITION – ALTER ANY EDITION – DROP ANY EDITION • Object Privileges - USE (not granted by default) GRANT USE ON <edition_name> TO <user_name>; • Roles system privileges are granted to the DBA role (only). • Enable Editioning ALTER USER <user_name> ENABLE EDITIONS; http://surachartopun.com
  • 12. Edition Enabled Data Dictionary Views • AUD$ (obj$edition) • DBA_EDITIONS (edition_name, parent_edition_name) • DBA_OBJECTS (edition_name) • DBA_OBJECTS_AE (edition_name) • DBA_SOURCE_AE (edition_name) • DBA_USERS (editions_enabled) • AE = All Editions http://surachartopun.com
  • 13. Edition Enabled Data Dictionary Views • FGA_LOG$ (obj$edition) • UTL_RECOMP_ALL_OBJECTS (edition_name) • V$LOGMNR_CONTENTS (edition_name) • V$SESSION (session_edition_id) • AE = All Editions http://surachartopun.com
  • 14. SQL> SELECT * FROM DBA_EDITIONS; EDITION_NAME PARENT_EDITION_NAME USA ------------------------------ ------------------------------ --- ORA$BASE YES SQL> CREATE EDITION VERSION2 AS CHILD OF ORA$BASE; Edition created. SQL> SELECT * FROM DBA_EDITIONS; EDITION_NAME PARENT_EDITION_NAME USA ------------------------------ ------------------------------ --- ORA$BASE YES VERSION2 ORA$BASE YES SQL> ALTER USER DEMO ENABLE EDITIONS; SQL> GRANT USE ON EDITION VERSION2 TO DEMO; http://surachartopun.com
  • 15. SQL> connect demo/demo Connected. SQL> SELECT SYS_CONTEXT ('userenv','current_edition_name') ce FROM DUAL; CE -------------------------------------------------------------------------------- ORA$BASE SQL> create or replace procedure my_procedure as Begin dbms_output.put_line ( 'I am version 1.0' ); end; / http://surachartopun.com
  • 16. SQL> ALTER SESSION SET EDITION=VERSION2; Session altered. SQL> create or replace procedure my_procedure as Begin dbms_output.put_line ( 'I am version 2.0' ); end; / SQL> SELECT SYS_CONTEXT ('userenv','current_edition_name') ce FROM DUAL; CE -------------------------------------------------------------------------------- ORA$BASE http://surachartopun.com
  • 17. SQL> exec my_procedure; I am version 1.0 SQL> ALTER SESSION SET EDITION=VERSION2; Session altered. SQL> SELECT SYS_CONTEXT ('userenv','current_edition_name') ce FROM DUAL; CE -------------------------------------------------------------------------------- VERSION2 SQL> exec my_procedure; I am version 2.0 http://surachartopun.com
  • 18. What is an Editioning View? • Editioning view selects a subset of the columns from a single base table. • Use the SQL statement CREATE VIEW with the OR REPLACE clause and the keyword EDITIONING. CREATE OR REPLACE EDITIONING VIEW … • Partition-Extended Editioning View Names http://surachartopun.com
  • 19. Editioning View Related Data Dictionary Views • DBA_EDITIONING_VIEW_COLS • DBA_EDITIONING_VIEW_COLS_AE • DBA_EDITIONING_VIEWS • DBA_EDITIONING_VIEWS_AE • DBA_ERRORS_AE (editioning_name) • DBA_OBJECTS_AE (editioning_name) • DBA_VIEWS (editioning_view) • AE = All Editions http://surachartopun.com
  • 20. SQL> CREATE EDITIONING VIEW ed01_tab AS SELECT name, tel_num FROM ed01_tab_tmp; SQL> select * from ED01_TAB partition (par_1); NAME TEL_NUM ------------------------------ ---------- TEST1 1234567 TEST5 1234567 SQL> CREATE TRIGGER ed01_tab_tri BEFORE INSERT ON ed01_tab FOR EACH ROW BEGIN null; END; / Trigger created. http://surachartopun.com
  • 21. What is a Crossedition Trigger? • A new, and special type of trigger specific to editioning • Can only be created on a table (not on an editioning view) • Propagates transactions between editions • Two types – FORWARD – REVERSE http://surachartopun.com
  • 22. • Crossedition triggers are always created in the child • Crossedition triggers are temporary—drop them after you have made the restructured tables available to all users. http://surachartopun.com
  • 23. Crossedition Trigger Types • Forward Crossedition Triggers – Only fired by code running in the parent edition – Transforms from the old representation to the new • Reverse Crossedition Triggers – Only fired by code running in the child edition – Transforms from the new representation to the old http://surachartopun.com
  • 24. Crossedition Trigger Related Data Dictionary Views • DBA_TRIGGERS • DBA_TRIGGER_ORDERING • DBA_ERRORS_AE (editioning_name) • DBA_OBJECTS_AE (editioning_name) • AE = All Editions http://surachartopun.com
  • 25. CREATE TABLE PERSONS (ID NUMBER(10) NOT NULL, FIRST_NAME VARCHAR2(100) NOT NULL, LAST_NAME VARCHAR2(100) NOT NULL,EMAIL VARCHAR2(100) NOT NULL) / RENAME persons TO persons_tab; CREATE EDITIONING VIEW persons AS SELECT id, first_name AS firstname, last_name AS lastname, email FROM persons_tab; create sequence persons_seq; http://surachartopun.com
  • 26. CREATE OR REPLACE TRIGGER persons_bi_trg BEFORE INSERT ON persons FOR EACH ROW BEGIN :new.id := persons_seq.nextval; END; / insert into persons values (null,'Somchai','A.','somchai@test.com'); commit; ALTER TABLE persons_tab ADD (email_recipient VARCHAR2(100),email_domain VARCHAR2(100)); SQL> select * from persons; ID FIRSTNAME LASTNAME EMAIL ---------- --------------- --------------- -------------------- 1 Somchai A. somchai@test.com http://surachartopun.com
  • 27. alter session set edition=VERSION2; CREATE TRIGGER persons_fc_trg BEFORE INSERT OR UPDATE ON persons_tab FOR EACH ROW FORWARD CROSSEDITION DISABLE BEGIN :new.email_recipient := regexp_substr(:new.email,'(.*)@',1,1,NULL,1); :new.email_domain := regexp_substr(:new.email,'@(.*)',1,1,NULL,1); END; / http://surachartopun.com
  • 28. column CE for a10 SELECT SYS_CONTEXT ('userenv','current_edition_name') ce FROM DUAL; CREATE OR REPLACE EDITIONING VIEW persons AS SELECT id, first_name AS firstname, last_name AS lastname,email_recipient,email_domain FROM persons_tab; SQL> select * from persons; ID FIRSTNAME LASTNAME EMAIL_RECIPIENT EMAIL_DOMAIN ---------- --------------- --------------- -------------------- -------------------- 1 Somchai A. http://surachartopun.com
  • 29. ALTER TRIGGER persons_fc_trg ENABLE; DECLARE c INTEGER; r INTEGER; BEGIN c := dbms_sql.open_cursor; dbms_sql.parse( c => c, statement => 'UPDATE persons SET email_domain = email_domain',language_flag => dbms_sql.native, apply_crossedition_trigger => 'persons_fc_trg'); r := dbms_sql.execute(c); dbms_sql.close_cursor(c); COMMIT; END; / http://surachartopun.com
  • 30. SQL> select * from persons; ID FIRSTNAME LASTNAME EMAIL_RECIPIENT EMAIL_DOMAIN ---------- --------------- --------------- -------------------- -------------------- 1 Somchai A. somchai test.com ---TEST FORWARD --- alter session set edition=ORA$BASE; update persons set email='surachart@gmail.com' where id=1; commit; SQL> select * from persons; ID FIRSTNAME LASTNAME EMAIL ---------- --------------- --------------- ------------------------- 1 Somchai A. surachart@gmail.com http://surachartopun.com
  • 31. alter session set edition=version2; SQL> select * from persons; ID FIRSTNAME LASTNAME EMAIL_RECIPIENT EMAIL_DOMAIN ---------- --------------- --------------- -------------------- -------------------- 1 Somchai A. surachart gmail.com http://surachartopun.com
  • 32. ---TEST REVERSE--- alter session set edition=version2; CREATE TRIGGER persons_rc_trg BEFORE INSERT OR UPDATE ON persons_tab FOR EACH ROW REVERSE CROSSEDITION DISABLE BEGIN :new.email := :new.email_recipient || '@' || :new.email_domain; END; / alter trigger persons_rc_trg enable; insert into persons values (null,'Surachart','O.','surachart',‘test.com'); commit; http://surachartopun.com
  • 33. SQL> select * from persons; ID FIRSTNAME LASTNAME EMAIL_RECIPIENT EMAIL_DOMAIN ---------- --------------- --------------- -------------------- -------------------- 1 Somchai A. surachart gmail.com 2 Surachart O. surachart test.com alter session set edition=ORA$BASE; SQL> select * from persons; ID FIRSTNAME LASTNAME EMAIL ---------- --------------- --------------- ------------------------------ 1 Somchai A. surachart@gmail.com 2 Surachart O. surachart@test.com http://surachartopun.com
  • 34. Learn More… • Oracle Documents (E11882_01) http://surachartopun.com
  • 35. Learn More.. • Tom Kyte on Edition Based Redefinition http://surachartopun.com
  • 36. Learn More… • Bryn Llewellyn's White Paper http://surachartopun.com
  • 37. Learn More… • Morgan Library www.morganslibrary.org http://surachartopun.com
  • 38. Learn More… • IOUG – Select Journal http://surachartopun.com
  • 39. Q&A http://surachartopun.com
  • 40. THANK YOU http://surachartopun.com