set echo on


connect /
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
create or replace 
procedure my_procedure
as
begin
   dbms_output.put_line( 'I am buggy version 1.0' );
end;
/
create or replace 
procedure my_procedure2
as
begin
   my_procedure;
end;
/
pause

clear screen
exec my_procedure2
pause

clear screen
alter session 
  set edition = version2;
pause

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

set linesize 150
column object_name format a14
column object_type format a11
column status format a6
column edition_name format a12


clear screen
connect demo/demo
alter session 
set edition = version2;
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 fixed in version 2.0' );
end;
/
pause

clear screen
select object_name, edition_name 
  from user_objects;
select object_name, edition_name 
  from user_objects_AE;
pause

clear screen
grant execute  on my_procedure2 to scott;
pause

clear screen
select object_name, edition_name 
  from user_objects;
select object_name, edition_name 
  from user_objects_AE;
pause

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


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

clear screen
alter session set edition = version2;
SELECT SYS_CONTEXT ('userenv', 'current_edition_name') sc
  FROM DUAL;
exec my_procedure2
pause


column sc format a15
clear screen
connect scott/tiger
SELECT SYS_CONTEXT ('userenv', 'current_edition_name') sc
  FROM DUAL;
exec demo.my_procedure2
pause

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

connect /
drop user demo cascade;
drop edition version2;
