Rem
Rem $Header: emcore/source/oracle/sysman/emdrep/sql/core/latest/admin/admin_cutover_synonym_to_ne_per_edition.sql gbafna_ne_cutover_timestamp_fix_ru02/2 2025/04/30 12:23:16 gbafna Exp $
Rem
Rem admin_cutover_synonym_to_ne_per_edition.sql
Rem
Rem Copyright (c) 2025, Oracle and/or its affiliates.

Rem BEGIN EMRU_FILE_METADATA
Rem EMRU_SOURCE_FILE:emcore/source/oracle/sysman/emdrep/sql/core/latest/admin/admin_cutover_synonym_to_ne_per_edition.sql
Rem EMRU_UNIX_DELIVERABLES:
Rem emcore/source/oracle/sysman/emdrep/sql/core/latest/admin/admin_cutover_synonym_to_ne_per_edition.sql

Rem EMRU_FILE_POSTINSTALL:<!!! enter the view based location of the executable file. If there is NONE leave as-is !!!>
Rem EMRU_GENERIC_FLAG:NONE
Rem END EMRU_FILE_METADATA

Rem
Rem    NAME
Rem      admin_cutover_synonym_to_ne_per_edition.sql - <one-line expansion of the name>
Rem
Rem    DESCRIPTION
Rem      <short description of component this file declares/defines>
Rem
Rem    NOTES
Rem      <other useful comments, qualifications, etc.>
Rem
Rem    BEGIN SQL_FILE_METADATA
Rem    SQL_SOURCE_FILE: emcore/source/oracle/sysman/emdrep/sql/core/latest/admin/admin_cutover_synonym_to_ne_per_edition.sql
Rem    SQL_SHIPPED_FILE:
Rem    SQL_PHASE:
Rem    SQL_STARTUP_MODE: NORMAL
Rem    SQL_IGNORABLE_ERRORS: NONE
Rem    END SQL_FILE_METADATA
Rem
Rem    MODIFIED   (MM/DD/YY)
Rem    gbafna      04/25/25 - timestamp fix
Rem    gbafna      02/10/25 - 
Rem    gbafna      02/03/25 - 
Rem    gbafna      12/12/24 - Created
Rem

DEFINE TARGET_EDITION = "&1"
DEFINE DEFAULT_EDITION = "&2"
DEFINE DBADMIN_USER = "&3"
DEFINE EM_REPOS_USER =  "&4"

ALTER SESSION SET EDITION = &TARGET_EDITION;
ALTER SESSION SET CURRENT_SCHEMA = &EM_REPOS_USER;

CREATE OR REPLACE PROCEDURE config_sql_retry_ne(sql_statement in  varchar2, sql_error_msg varchar2)
is
  l_retry_exist     number := 0;
  l_retry_value     varchar2(30) := '"';
  l_retry_count     number := 0;
  l_retry_duration  number := 0;
  l_error_message   varchar2(256);
begin
  MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'DDL_RETRY','DDL_RETRY_ID', 'DDL to execute: ' || sql_statement);
    select count(1) into l_retry_exist from "&EM_REPOS_USER".MGMT_UPGRADEUTIL_PROPS where property_name = 'RETRY_COUNT:RETRY_DURATION';
  if l_retry_exist = 0 then
      MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'DDL_RETRY','DDL_RETRY_ID', 'DDL: '||sql_statement||' RETRY_COUNT:RETRY_DURATION=' || l_retry_exist);
      insert into "&EM_REPOS_USER".MGMT_UPGRADEUTIL_PROPS values ('RETRY_COUNT:RETRY_DURATION', '120:5');
          l_retry_count := 120;
          l_retry_duration := 5;
    commit;
  else
         select property_value into l_retry_value from "&EM_REPOS_USER".MGMT_UPGRADEUTIL_PROPS where property_name = 'RETRY_COUNT:RETRY_DURATION';
         MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'DDL_RETRY','DDL_RETRY_ID', 'DDL: '||sql_statement||' RETRY_COUNT:RETRY_DURATION=' || l_retry_exist);
         l_retry_count := substr(l_retry_value, 1, instr(l_retry_value,':',1,1)-1);
         l_retry_duration := substr(l_retry_value, instr(l_retry_value,':',1,1)+1, length(l_retry_value));
        MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'DDL_RETRY','DDL_RETRY_ID', 'DDL: '||sql_statement||' RETRY_COUNT: ' || l_retry_count || ' RETRY_DURATION= ' || l_retry_duration);
  end if;

  for l_retry in 1..l_retry_count loop
    MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'DDL_RETRY','DDL_RETRY_ID','executing DDL: '||sql_statement||' , retry count: ' || l_retry);
    begin
      execute immediate SYS.DBMS_ASSERT.NOOP(sql_statement);
      EXIT;
    exception when others then
       DBMS_LOCK.Sleep(l_retry_duration);
       l_error_message := 'DDL: '||sql_statement||' error: ' || SQLERRM;
       MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'DDL_RETRY','DDL_RETRY_ID',l_error_message);
       if l_retry = l_retry_count then
         MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'DDL_RETRY','DDL_RETRY_ID', 'DDL: '||sql_statement||' error: ' || sql_error_msg || ' - after retrying logic for ''' || sql_statement || ''' Error : ' || SQLERRM);
         raise_application_error(-20000, sql_error_msg || ' - after retrying logic for ''' || sql_statement || ''' Error : ' || SQLERRM);
       else
         continue;
       end if;
    end;
  end loop;
end config_sql_retry_ne;
/

DECLARE
    l_sql VARCHAR2(2000);
    l_flag_state VARCHAR2(256);
    l_org_flag_state VARCHAR2(256);
    l_force_failure NUMBER;
    l_mgmt_admin_msg_synonym_exists NUMBER;
    l_synonym_exists NUMBER;
    l_final_ne_synonym_check NUMBER;
    l_loop_counter NUMBER := 0; 
    l_max_count NUMBER := 0; 
    l_property_value VARCHAR2(256);
    l_error_message VARCHAR2(2000);
BEGIN
    
    BEGIN
        SELECT PROPERTY_VALUE
        INTO l_flag_state
        FROM SYSMAN.MGMT_LCM_PROPERTIES_E
        WHERE PROPERTY_NAME = 'EM_NE_SYNONYMS_CUTOVER_DONE';

        l_org_flag_state := l_flag_state;
        l_property_value := l_flag_state;

    EXCEPTION
        WHEN NO_DATA_FOUND THEN
            l_flag_state := '&&TARGET_EDITION' || ':FALSE';
            INSERT INTO SYSMAN.MGMT_LCM_PROPERTIES_E (PROPERTY_NAME, PROPERTY_VALUE)
            VALUES ('EM_NE_SYNONYMS_CUTOVER_DONE', l_flag_state);
            COMMIT;

            l_org_flag_state := '';
            l_property_value := l_flag_state;
            MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', 'Creating flag EM_NE_SYNONYMS_CUTOVER_DONE for the first time and setting it to FALSE for &&TARGET_EDITION.');                        
    END;

    BEGIN
        IF l_property_value NOT LIKE '%' || '&&TARGET_EDITION' || '%' THEN
            UPDATE SYSMAN.MGMT_LCM_PROPERTIES_E
            SET PROPERTY_VALUE = PROPERTY_VALUE || ',' || '&&TARGET_EDITION' || ':FALSE'
            WHERE PROPERTY_NAME = 'EM_NE_SYNONYMS_CUTOVER_DONE';
            COMMIT;
            l_flag_state := l_flag_state || ',' || '&&TARGET_EDITION' || ':FALSE';
            l_property_value := l_flag_state;
            MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', 'Updating flag EM_NE_SYNONYMS_CUTOVER_DONE for &&TARGET_EDITION.');                        
        END IF;
        MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', 'Flag EM_NE_SYNONYMS_CUTOVER_DONE is currently set to ' || l_flag_state);                        
    END;

    --QA Failure FLAG
    BEGIN
        SELECT count(*)
            INTO l_force_failure
            FROM SYSMAN.MGMT_LCM_PROPERTIES_E
            WHERE PROPERTY_NAME = 'EM_NE_SYNONYMS_CUTOVER_FORCE_FAILURE'
            AND PROPERTY_VALUE = 'TRUE';
    EXCEPTION
        WHEN NO_DATA_FOUND THEN
            MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', 'Force failure flag EM_NE_SYNONYMS_CUTOVER_FORCE_FAILURE not set.');                        
    END;

    --Old Synonym wrong code cleanup
    BEGIN
        SELECT COUNT(*)
        INTO l_mgmt_admin_msg_synonym_exists
        FROM DBA_SYNONYMS
        WHERE SYNONYM_NAME = 'MGMT_ADMIN_MSG'
        AND OWNER = 'SYSMAN_ZDTUSER'; 

        IF l_mgmt_admin_msg_synonym_exists > 0 THEN
            EXECUTE IMMEDIATE 'DROP SYNONYM SYSMAN_ZDTUSER.MGMT_ADMIN_MSG FORCE';
            MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', 'Dropped synonym SYSMAN_ZDTUSER.MGMT_ADMIN_MSG');                    
        END IF;
    END;

    --Main cutover logic
    IF l_flag_state LIKE '%FALSE%' THEN
        BEGIN
        SELECT count(*) INTO l_final_ne_synonym_check FROM
        (SELECT *
            FROM DBA_SYNONYMS s
            JOIN DBA_OBJECTS o 
            ON s.owner=o.owner
            AND s.synonym_name=o.object_name
            AND o.object_type='SYNONYM'
            WHERE EDITION_NAME = '&&TARGET_EDITION'
            AND s.TABLE_OWNER='SYSMAN_TYPES'
            AND s.synonym_name not in (select synonym_name from SYSMAN.EM_NECUTOVER_SYNONYMS_E where EDITION_NAME = '&&TARGET_EDITION' AND OWNER = s.owner));
        
        SELECT count(*) INTO l_max_count
            FROM dba_synonyms s
            JOIN dba_objects o
            ON s.synonym_name = o.object_name
            WHERE s.owner = o.owner
            AND o.object_type = 'SYNONYM'
            AND s.table_owner = 'SYSMAN_TYPES';

        l_max_count := GREATEST(500, 3 * (l_max_count + 1));
        MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', 'l_max_count: '|| l_max_count || ' l_loop_counter: ' || l_loop_counter);

        WHILE ((l_final_ne_synonym_check != 0) AND (l_loop_counter < l_max_count)) LOOP 
            FOR rec IN ( SELECT s.owner, s.table_owner, s.table_name, s.synonym_name, o.edition_name
                                FROM dba_synonyms s
                                JOIN dba_objects o
                                ON s.synonym_name = o.object_name
                                WHERE s.owner = o.owner
                                AND o.object_type = 'SYNONYM'
                                AND s.table_owner = 'SYSMAN_TYPES'
                                AND o.edition_name = '&&TARGET_EDITION')
            LOOP
                BEGIN                                                
                    l_synonym_exists := 0;
                    SELECT COUNT(*) INTO l_synonym_exists
                    FROM DBA_SYNONYMS s
                    JOIN DBA_OBJECTS o 
                    ON s.owner = o.owner
                    AND s.synonym_name = o.object_name
                    AND o.object_type = 'SYNONYM'
                    WHERE EDITION_NAME IS NULL
                    AND UPPER(s.SYNONYM_NAME) = UPPER(rec.synonym_name)
                    AND UPPER(s.OWNER) = UPPER(rec.owner)
                    AND s.TABLE_OWNER = 'SYSMAN_TYPES';
                        
                        IF l_synonym_exists > 0 THEN
                            MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM', 'ADMIN_CUTOVER_SYNONYM_ID', rec.owner || '.' || rec.synonym_name || ' synonym is already non-editionable so no action taken.');                                            
                        ELSE
                            l_sql := 'DROP SYNONYM '||rec.owner||'.'||rec.synonym_name||' FORCE';
                            BEGIN
                                EXECUTE IMMEDIATE l_sql;
                                MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', 'Dropping synonym: '|| l_sql || ' in edition ' || rec.edition_name);                    
                            EXCEPTION
                                WHEN OTHERS THEN    
                                    config_sql_retry_ne(l_sql, 'Failed to drop synonym for ' || rec.synonym_name || ' in edition ' || rec.edition_name);		
                                    MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', 'Dropping synonym using config_sql_retry_ne procedure: '|| l_sql || ' in edition ' || rec.edition_name);                    
                            END;
                            
                            --QA Failure
                            IF l_force_failure = 1 THEN
                                l_sql := 'CREATE OR REPLACE SYNONYM '||rec.owner||'.'||rec.synonym_name
                                            ||' FOR '|| rec.table_owner||'.'||rec.table_name ;
                                EXECUTE IMMEDIATE l_sql; 
                                RAISE NO_DATA_FOUND;
                            END IF;

                            l_sql := 'CREATE NONEDITIONABLE SYNONYM '||rec.owner||'.'||rec.synonym_name||' FOR '|| rec.table_owner||'.'||rec.table_name ;
                            BEGIN
                                EXECUTE IMMEDIATE l_sql;
                                MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', 'Creating non editionable synonym: '|| l_sql || ' in edition ' || rec.edition_name);                    
                            EXCEPTION  
                                WHEN OTHERS THEN
                                    INSERT INTO SYSMAN.EM_NECUTOVER_SYNONYMS_E (OWNER, SYNONYM_NAME, TABLE_OWNER, TABLE_NAME, EDITION_NAME)
                                    VALUES (rec.owner, rec.synonym_name, rec.table_owner, rec.table_name, rec.edition_name);
                                    COMMIT; 
                                    MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', 'Inserting into table EM_NECUTOVER_SYNONYMS_E: ' || rec.owner || '.' || rec.synonym_name || ' FOR ' || rec.table_owner || '.' || rec.table_name || ' in edition ' || rec.edition_name );                     
                                    IF SQLCODE = -955 THEN                                          
                                        MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', 'Name is already used by an existing object exception hit so recreating synonym: '|| l_sql || ' in edition ' || rec.edition_name);                     
                                    ELSE
                                        l_error_message := 'Exception occurred while running: ' || l_sql || ' error ' || SQLCODE || ' - ' || SQLERRM;
                                        MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', l_error_message);                     
                                        RAISE;
                                    END IF;   
                            END;     
                            COMMIT;
                        END IF; 
                EXCEPTION
                    WHEN OTHERS THEN
                        l_error_message := 'Exception while dropping and creating synonym: ' || SQLCODE || ' - ' || SQLERRM;
                        MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', l_error_message);                     
                        RAISE;                   
                END;
            END LOOP; 
            l_loop_counter := l_loop_counter + 1;
            MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', 'loop count: ' || l_loop_counter ); 
            SELECT count(*) INTO l_final_ne_synonym_check FROM
                (SELECT *
                    FROM DBA_SYNONYMS s
                    JOIN DBA_OBJECTS o 
                    ON s.owner=o.owner
                    AND s.synonym_name=o.object_name
                    AND o.object_type='SYNONYM'
                    WHERE EDITION_NAME = '&&TARGET_EDITION'
                    AND s.TABLE_OWNER='SYSMAN_TYPES'
                    AND s.synonym_name not in (select synonym_name from SYSMAN.EM_NECUTOVER_SYNONYMS_E where EDITION_NAME = '&&TARGET_EDITION' AND OWNER = s.owner)); 
                    
        END LOOP; 
        MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', 'Drop and create synonym loop completed.' );                      
        END;       
    ELSE
        MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', 'EM_NE_SYNONYMS_CUTOVER_DONE Flag is TRUE. No action taken.');                    
    END IF;

    BEGIN 
        SELECT count(*) INTO l_final_ne_synonym_check FROM
            (SELECT *
                FROM DBA_SYNONYMS s
                JOIN DBA_OBJECTS o 
                ON s.owner=o.owner
                AND s.synonym_name=o.object_name
                AND o.object_type='SYNONYM'
                WHERE EDITION_NAME = '&&TARGET_EDITION'
                AND s.TABLE_OWNER='SYSMAN_TYPES'
                AND s.synonym_name not in (select synonym_name from SYSMAN.EM_NECUTOVER_SYNONYMS_E where EDITION_NAME = '&&TARGET_EDITION' AND OWNER = s.owner));       

        IF l_final_ne_synonym_check > 0 THEN
            MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', l_final_ne_synonym_check || ' synonyms are still editionable.' );  
           
            IF l_property_value LIKE '%' || '&&TARGET_EDITION' || '%' THEN
                UPDATE SYSMAN.MGMT_LCM_PROPERTIES_E
                SET PROPERTY_VALUE = 
                    CASE 
                        WHEN INSTR(PROPERTY_VALUE, '&TARGET_EDITION:TRUE') > 0 
                        THEN REPLACE(PROPERTY_VALUE, '&TARGET_EDITION:TRUE', '&TARGET_EDITION:FALSE')
                        WHEN INSTR(PROPERTY_VALUE, '&TARGET_EDITION:FALSE') > 0 
                        THEN REPLACE(PROPERTY_VALUE, '&TARGET_EDITION:FALSE', '&TARGET_EDITION:FALSE')
                        ELSE PROPERTY_VALUE
                    END
                WHERE PROPERTY_NAME = 'EM_NE_SYNONYMS_CUTOVER_DONE'
                AND PROPERTY_VALUE LIKE '&TARGET_EDITION%';
                COMMIT;
                MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', 'Updating flag EM_NE_SYNONYMS_CUTOVER_DONE for current edition to false.');                        
            ELSE 
                UPDATE SYSMAN.MGMT_LCM_PROPERTIES_E
                SET PROPERTY_VALUE = l_org_flag_state || ',' || '&&TARGET_EDITION' || ':FALSE'
                WHERE PROPERTY_NAME = 'EM_NE_SYNONYMS_CUTOVER_DONE';
                COMMIT;
                MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', 'Adding current edition entry of false to flag EM_NE_SYNONYMS_CUTOVER_DONE.');                        
            END IF;
            MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', 'Setting the flag EM_NE_SYNONYMS_CUTOVER_DONE to FALSE because exception occured.' );                               
            RAISE_APPLICATION_ERROR(-20001, 'Some synonyms are still editionable thus raising error.'); 
        
        ELSE        
            IF l_property_value LIKE '%' || '&&TARGET_EDITION' || '%' THEN
                UPDATE SYSMAN.MGMT_LCM_PROPERTIES_E
                SET PROPERTY_VALUE = 
                    CASE 
                        WHEN INSTR(PROPERTY_VALUE, '&TARGET_EDITION:FALSE') > 0 
                        THEN REPLACE(PROPERTY_VALUE, '&TARGET_EDITION:FALSE', '&TARGET_EDITION:TRUE')
                        WHEN INSTR(PROPERTY_VALUE, '&TARGET_EDITION:TRUE') > 0 
                        THEN REPLACE(PROPERTY_VALUE, '&TARGET_EDITION:TRUE', '&TARGET_EDITION:TRUE')
                        ELSE PROPERTY_VALUE
                    END
                WHERE PROPERTY_NAME = 'EM_NE_SYNONYMS_CUTOVER_DONE'
                AND PROPERTY_VALUE LIKE '%&TARGET_EDITION%';
                COMMIT;
                MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', 'Updating flag EM_NE_SYNONYMS_CUTOVER_DONE for current edition to true.');                        
            ELSE 
                UPDATE SYSMAN.MGMT_LCM_PROPERTIES_E
                SET PROPERTY_VALUE = l_org_flag_state || ',' || '&&TARGET_EDITION' || ':TRUE'
                WHERE PROPERTY_NAME = 'EM_NE_SYNONYMS_CUTOVER_DONE';
                COMMIT;   
                MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', 'Adding current edition entry of true to flag EM_NE_SYNONYMS_CUTOVER_DONE.');                        
            END IF; 
            MGMT_EMDEP_LOGGER.log_message(MGMT_EMDEP_LOGGER.G_LOG_LEVEL_INFO, 'ADMIN_CUTOVER_SYNONYM','ADMIN_CUTOVER_SYNONYM_ID', 'Cutover completed successfully, thus setting the flag EM_NE_SYNONYMS_CUTOVER_DONE to TRUE.' );                    
        END IF;
        
        SELECT PROPERTY_VALUE
        INTO l_property_value
        FROM SYSMAN.MGMT_LCM_PROPERTIES_E
        WHERE PROPERTY_NAME = 'EM_NE_SYNONYMS_CUTOVER_DONE';

        IF l_property_value LIKE ',%' THEN
            l_property_value := SUBSTR(l_property_value, 2); 
        END IF;
        
        UPDATE SYSMAN.MGMT_LCM_PROPERTIES_E
        SET PROPERTY_VALUE = l_property_value
        WHERE PROPERTY_NAME = 'EM_NE_SYNONYMS_CUTOVER_DONE';
        COMMIT;
    END;
COMMIT;    
END;
/ 

ALTER SESSION SET EDITION = &DEFAULT_EDITION;
ALTER SESSION SET CURRENT_SCHEMA = &DBADMIN_USER;
