
begin
	execute immediate 'alter table FSI_DGS_DATA_ORIGIN_AGG drop primary key';
end;
/	

declare
  v_batch_name varchar2(100) := 'DGS_DATA_ORIGIN_MIGRATION_LOB_';
begin
  begin
  
    select user into pkg_ki_mapper.v_schema_user from dual;
  
    SELECT n_lookup_value
      INTO pkg_ki_mapper.v_parallel_hint
      FROM fsi_dgs_configuration
     WHERE v_module_name = 'MAPPER'
       AND v_lookup_code = 'PARALLEL_HINT';
  
    select TO_NUMBER(N_LOOKUP_VALUE)
      into pkg_ki_mapper.v_dop
      from FSI_DGS_CONFIGURATION
     WHERE v_module_name = 'MAPPER'
       AND v_lookup_code = 'GATHER_STATS_PARALLEL_HINT';
  
  exception
    when others then
      pkg_ki_mapper.v_dop           := 2;
      pkg_ki_mapper.v_parallel_hint := '';
    
  end;
  for rec in (select distinct mp.n_mis_date_skey
                from fsi_dgs_data_origin_agg mp) loop
    v_batch_name := v_batch_name || tasks.nextval;
    pkg_ki_mapper.SESSION_CONFIGURATIONS(v_batch_name, rec.n_mis_date_skey);
    pkg_ki_mapper.sp_data_origin_agr_insert(v_batch_name,
                                            rec.n_mis_date_skey);
  end loop;
end;
/

begin

execute immediate  'alter table FSI_DGS_DATA_ORIGIN_AGG add constraint PK_DATA_ORIGIN_AGG primary key (
					V_REPORT_CD,
					V_SCHEDULE_NAME,
					V_CELL_ID,
					N_RUN_SKEY,
					N_MIS_DATE_SKEY,
					N_LOAD_RUN_ID,
					N_DATA_SOURCE_CD,
					N_ENTITY_SKEY,
					N_LOB_SKEY
					)';

end;
/