The following lines contain the word 'select', 'insert', 'update' or 'delete':
* which information is deleted from the msd_cs_data table.
* Therfore, each header needs to be checked if a row
* exists in the msd_cs_data table that refers to it.
*
* 2. When no date is specified the data from msd_cs_data_headers
* can immediately be deleted.
*/
/* If given the name of a stream this provides the definition id.
* This is useful when on the UI, there is no option to select
* the custom stream, but represented in a hard-coded label.
*/
CURSOR get_cs_definition_id(p_cs_name in VARCHAR2) IS
SELECT cs_definition_id
FROM msd_cs_definitions
WHERE name = p_cs_name;
SELECT system_flag
FROM msd_cs_definitions
WHERE cs_definition_id = p_cs_iden;
procedure delete_cs_data ( p_instance_id IN varchar2,
p_cs_definition_id IN number,
p_cs_designator IN varchar2,
p_from_date IN date,
p_to_date IN date ) IS
TYPE cs_data_id_tab is table of msd_cs_data.cs_data_id%TYPE;
select cs_data_id
from msd_cs_data
where cs_definition_id in (select cs_definition_id
from msd_cs_definitions
where cs_definition_id = nvl(p_cs_definition_id , cs_definition_id)
and ((p_cs_definition_id is not null) or
(system_flag = 'C')))
and nvl(cs_name, '#$#$^&&&!!!!!!$%$%$%$%090@@') = nvl(p_cs_designator, nvl(cs_name, '#$#$^&&&!!!!!!$%$%$%$%090@@'))
and nvl(attribute_43, '0001/01/01') between nvl(to_char(p_from_date, 'YYYY/MM/DD'), '0001/01/01')
and nvl(to_char(p_to_date, 'YYYY/MM/DD'), '4317/12/31')
and nvl(attribute_1, '-999') = nvl(p_instance_id, nvl(attribute_1, '-999'));
C_NUM_DELETE_ROWS number := 1000;
fetch get_cs_data bulk collect into t_cs_data_id LIMIT C_NUM_DELETE_ROWS;
DELETE FROM msd_cs_data
WHERE cs_data_id = t_cs_data_id(i);
DELETE FROM msd_cs_data_ds
WHERE cs_data_id = t_cs_data_id(i);
end delete_cs_data;
procedure delete_cs_headers (p_instance_id IN NUMBER,
p_cs_def_id IN NUMBER,
p_cs_name IN VARCHAR2) IS
begin
delete from msd_cs_data_headers
where instance = nvl(p_instance_id, instance)
and cs_definition_id = nvl(p_cs_def_id, cs_definition_id)
and cs_name = nvl(p_cs_name, cs_name);
end delete_cs_headers;
select 1
from msd_cs_data
where attribute_1 = p_instance_id
and cs_definition_id = p_cs_id
and cs_name = p_cs_name
and rownum = x_num_rows;
select *
from msd_cs_data_headers
where instance = nvl(p_instance_id, instance)
and cs_definition_id = nvl(p_cs_def_id, cs_definition_id)
and cs_name = nvl(p_cs_name, cs_name)
and exists ( select 1
from msd_cs_definitions csd
where csd.cs_definition_id = msd_cs_data_headers.cs_definition_id
and csd.system_flag = 'C' );
delete_cs_headers(cs_rec.instance, cs_rec.cs_definition_id, cs_rec.cs_name);
/* This procedure is called after data is deleted from msd_cs_data.
* It will determine whether dates are defined and determine
* whether headers need to check for children in msd_cs_data
*/
procedure purge_cs_data_headers(p_instance_id IN NUMBER,
p_from_date IN VARCHAR2,
p_to_date IN VARCHAR2,
p_cs_def_id IN NUMBER,
p_cs_name IN VARCHAR2) IS
begin
/* Date is included so the msd_cs_data needs to be checked for rows
* that are deleted.
*/
if (p_from_date is not null) or (p_to_date is not null) then
/* Deletes data in headers checking date-filtered deletes in msd_cs_data */
check_cs_headers (p_instance_id, p_cs_def_id, p_cs_name);
/* Deletes directly from headers since no date filtering done. */
delete from msd_cs_data_headers
where instance = nvl(p_instance_id, instance)
and cs_definition_id = nvl(p_cs_def_id, cs_definition_id)
and cs_name = nvl(p_cs_name, cs_name)
and exists ( select 1
from msd_cs_definitions csd
where csd.cs_definition_id = msd_cs_data_headers.cs_definition_id
and csd.system_flag = 'C' );
select 1
from msd_mfg_forecast
where instance = p_instance_id
and forecast_designator = p_cs_name
and rownum = x_num_rows;
select *
from msd_cs_data_headers
where instance = nvl(p_instance_id, instance)
and cs_definition_id = nvl(p_cs_def_id, cs_definition_id)
and cs_name = nvl(p_cs_name, cs_name);
delete_cs_headers(cs_rec.instance, cs_rec.cs_definition_id, cs_rec.cs_name);
/* This procedure is called after data is deleted from msd_mfg_forecast.
* It will determine whether dates are defined and determine
* whether headers need to check for children in msd_mfg_forecast
*/
procedure purge_mfg_data_headers(p_instance_id IN NUMBER,
p_cs_def_id IN NUMBER,
p_l_date IN NUMBER,
p_cs_name IN VARCHAR2) IS
begin
/* Date is included so the msd_cs_data needs to be checked for rows
* that are deleted.
*/
if (p_l_date <> 0) then
/* Deletes data in headers checking date-filtered deletes in msd_cs_data */
check_mfg_headers (p_instance_id, p_cs_def_id, p_cs_name);
/* Deletes directly from headers since no date filtering done. */
delete_cs_headers(p_instance_id, p_cs_def_id, p_cs_name);
select 1
from msd_cs_data
where attribute_1 = p_instance_id
and cs_definition_id = p_cs_id
and cs_name = p_cs_name
and rownum = x_num_rows;
select *
from msd_cs_data_headers
where instance = nvl(p_instance_id, instance)
and cs_definition_id = p_cs_def_id
and cs_name = nvl(p_cs_name, cs_name);
delete_cs_headers(cs_rec.instance, cs_rec.cs_definition_id, cs_rec.cs_name);
/* This procedure is called after data is deleted from msd_cs_data.
* It will determine whether dates are defined and determine
* whether headers need to check for children in msd_cs_data
*/
procedure purge_int_data_headers(p_instance_id IN NUMBER,
p_from_date IN VARCHAR2,
p_to_date IN VARCHAR2,
p_cs_def_id IN NUMBER,
p_cs_name IN VARCHAR2) IS
begin
/* Date is included so the msd_cs_data needs to be checked for rows
* that are deleted.
*/
if (p_from_date is not null) or (p_to_date is not null) then
/* Deletes data in headers checking date-filtered deletes in msd_cs_data */
check_int_headers (p_instance_id, p_cs_def_id, p_cs_name);
/* Deletes directly from headers since no date filtering done. */
delete from msd_cs_data_headers
where instance = nvl(p_instance_id, instance)
and cs_definition_id = p_cs_def_id
and cs_name = nvl(p_cs_name, cs_name);
l_delete_from varchar2(500);
b_delete_denorm boolean := false;
l_delete_from := 'delete from ' || MSD_COMMON_UTILITIES.SHIPMENT_FACT_TABLE;
l_final_str := l_delete_from || l_where;
l_delete_from := 'delete from ' || MSD_COMMON_UTILITIES.BOOKING_FACT_TABLE;
l_final_str := l_delete_from || l_where;
l_delete_from := 'delete from ' || MSD_COMMON_UTILITIES.MFG_FCST_FACT_TABLE;
l_final_str := l_delete_from || l_where;
delete_cs_data ( p_instance_id,
x_cs_id,
null,
x_from_date,
x_to_date );
delete_cs_data ( p_instance_id,
x_cs_id,
null,
x_from_date,
x_to_date );
delete_cs_data ( p_instance_id,
x_cs_id,
null,
x_from_date,
x_to_date );
/** Delete Custom Data **/
if p_cs_data_yes_no = MSD_COMMON_UTILITIES.MSD_YES_FLAG then
if (p_cs_definition_id is not null) then
open get_cs_system_flag(p_cs_definition_id);
/* Seeded custom stream can only be deleted one at a time.
* Therefore the user must have specified the id of the
* stream.
*/
if(p_cs_definition_id is not null) then
delete_cs_data ( p_instance_id,
p_cs_definition_id,
p_cs_designator,
x_from_date,
x_to_date );
delete_cs_data ( p_instance_id,
p_cs_definition_id,
p_cs_designator,
x_from_date,
x_to_date );
/** Delete Currency data **/
if (p_curr_yes_no = MSD_COMMON_UTILITIES.MSD_YES_FLAG) then
l_delete_from := 'delete from ' || MSD_COMMON_UTILITIES.CURRENCY_FACT_TABLE;
l_final_str := l_delete_from;
l_delete_from := 'delete from ' || MSD_COMMON_UTILITIES.UOM_FACT_TABLE;
l_final_str := l_delete_from || l_where;
l_delete_from := 'delete from ' || MSD_COMMON_UTILITIES.TIME_FACT_TABLE;
l_final_str := l_delete_from || l_where;
l_final_str := l_delete_from || l_where;
l_delete_from := 'delete from ' || MSD_COMMON_UTILITIES.PRICING_FACT_TABLE;
l_final_str := l_delete_from || l_where;
SELECt nvl(max(revision), -999) into l_latest_revision
from msd_dp_scenario_revisions
where demand_plan_id = p_demand_plan_id and
scenario_id = p_scenario_id;
b_delete_denorm := TRUE;
b_delete_denorm := FALSE;
l_delete_from := 'delete from ' || MSD_COMMON_UTILITIES.SCENARIO_ENTRIES_TABLE;
l_final_str := l_delete_from || l_where;
l_delete_from := 'delete from msd_dp_scenario_revisions';
l_final_str := l_delete_from || l_where;
l_delete_from := 'delete from msd_dp_planning_percentages';
l_final_str := l_delete_from || l_where;
b_delete_denorm = TRUE ) THEN
l_delete_from := 'delete from msd_dp_scn_entries_denorm ';
l_final_str := l_delete_from || l_where;
l_delete_from := 'delete from msd_dp_planning_pct_denorm ';
l_final_str := l_delete_from || l_where;
l_delete_from := 'delete from ' || MSD_COMMON_UTILITIES.LEVEL_VALUES_FACT_TABLE;
l_final_str := l_delete_from || l_where;
l_delete_from := 'delete from ' || MSD_COMMON_UTILITIES.LEVEL_ASSOC_FACT_TABLE;
l_final_str := l_delete_from || l_where;
l_delete_from := 'delete from ' || MSD_COMMON_UTILITIES.ITEM_INFO_FACT_TABLE;
l_final_str := l_delete_from || l_where;
l_delete_from := 'delete from ' || MSD_COMMON_UTILITIES.MSD_LOCAL_ID_SETUP_TABLE;
l_final_str := l_delete_from || l_where;
l_delete_from := 'delete from ' || MSD_COMMON_UTILITIES.LEVEL_ORG_ASSCNS_FACT_TABLE;
l_final_str := l_delete_from || l_where;
l_delete_from := 'delete from ' || MSD_COMMON_UTILITIES.ITEM_RELATIONSHIPS_FACT_TABLE;
l_final_str := l_delete_from || l_where;
delete from msd_level_values_ds;
delete from msd_dp_parameters_ds;
delete from msd_cs_data_ds;
update msd_demand_plans
set build_stripe_level_pk = null,
build_stripe_stream_name = null,
build_stripe_stream_desig = null,
build_stripe_stream_ref_num = null;
SELECT MIN(mdp.scn_build_refresh_num) ref_num,
mcd.cs_definition_id csid,
mcd.name csname
FROM msd_dp_parameters mdp,
msd_cs_definitions mcd
WHERE mcd.name = mdp.parameter_type
GROUP BY mcd.cs_definition_id,
mcd.name
ORDER BY mcd.cs_definition_id;
SELECT COUNT(*) deleted_rec,
cs_definition_id csid,
last_refresh_num l_ref_num,
action_code
FROM msd_cs_data
GROUP BY cs_definition_id,
last_refresh_num,
action_code HAVING action_code = 'D'
AND cs_definition_id = cs_def_id
ORDER BY last_refresh_num;
deleted NUMBER;
deleted := 0;
l_sql_stmt := ' DELETE FROM MSD_CS_DATA' || ' WHERE ACTION_CODE = ' || '''D''' || ' and LAST_REFRESH_NUM = ' || set_rec.l_ref_num || ' and cs_definition_id = ' || rec.csid;
deleted := deleted + set_rec.deleted_rec;
IF deleted > 0 THEN
fnd_file.PUT_LINE(fnd_file.LOG, to_char(deleted) || ' unused records purged for the custom stream - ' || rec.csname);