set echo on
column object_name format a14
column object_type format a11
column status format a6
column edition_name format a12


clear screen
connect /
@sql
drop user demo cascade;
alter edition version2 unusable;
drop edition version2;

clear screen
create user demo 
   identified by demo;
grant create session, 
      create procedure 
   to demo;
create edition version2 
    as child of ora$base;
pause



clear screen
connect demo/demo
@sql

create or replace 
procedure my_procedure
as
begin
   dbms_output.put_line
   ( 'I am version 1.0' );
end;
/
create or replace 
procedure my_procedure2
as
begin
   my_procedure;
end;
/
pause


clear screen
exec my_procedure2
pause
alter session 
  set edition = version2;
pause

clear screen
connect /
@sql
alter user demo 
  enable editions;
grant use  
 on edition version2 
 to demo;
grant use  
 on edition version2 
 to scott;
pause


clear screen
connect demo/demo
@sql
alter session 
set edition = version2;
set linesize 150
column object_name format a14
column object_type format a11
column status format a6
column edition_name format a12
select object_name, 
       object_type, 
       status, 
       edition_name 
  from user_objects;
pause

clear screen
create or replace 
procedure my_procedure
as
begin
   dbms_output.put_line
   ( 'I am version 2.0' );
end;
/
set linesize 150
select object_name, 
       object_type, 
       status, 
       edition_name 
  from user_objects;
grant execute on my_procedure2 to scott;
select object_name, 
       object_type, 
       status, 
       edition_name 
  from user_objects;
pause

column sc format a15
clear screen
SELECT SYS_CONTEXT('userenv', 
                   'current_edition_name') sc
  FROM DUAL;
exec my_procedure2
pause

clear screen
connect demo/demo
@sql
column sc format a15
clear screen
SELECT SYS_CONTEXT('userenv', 
                   'current_edition_name') sc
  FROM DUAL;
exec my_procedure2
pause
alter session 
  set edition = version2;
SELECT SYS_CONTEXT('userenv', 
                   'current_edition_name') sc
  FROM DUAL;
exec my_procedure2
pause

clear screen
connect scott/tiger
column sc format a15
SELECT SYS_CONTEXT('userenv', 
                   'current_edition_name') sc
  FROM DUAL;
exec demo.my_procedure2
alter session 
  set edition = version2;
exec demo.my_procedure2

clear screen
connect /
column object_name format a14
column object_type format a11
column status format a6
column edition_name format a12
@sql
drop user demo cascade;
drop edition version2;
