Anda di halaman 1dari 4

-- Template for Data Fix Scripts

SET SERVEROUTPUT ON;

set echo on;

select to_char(sysdate,'DD-MON-YYYY HH:MI:SS PM') from dual;

select * from global_name;

-- Select data marked for deletion or update and provide record count for
validation.
-- Should be provided for each DELETE or UPDATE statement. This is NOT needed for
INSERT statments.
-- Select count(*) statements are acceptable if you expect a lot of data to be
returned.
<insert SELECT statement>

-- Execute DELETE/UPDATE/INSERT statement(s)

DECLARE
l_table_owner VARCHAR2 (30) := 'EGO';
l_table_name VARCHAR2 (30) := 'MTL_SYSTEM_ITEMS_B';
g_prod_schema VARCHAR2 (30);
g_inst_status VARCHAR2 (1);
g_industry VARCHAR2 (1);
g_installed BOOLEAN;
l_eitl_row_count NUMBER := NULL;
l_ctx_index_count NUMBER := 0;
l_unq_index_count NUMBER := 0;
l_application_id NUMBER (10) := 401;
l_enabled_flag VARCHAR2 (1) := 'Y';
l_rows_processed NUMBER := 0;
l_rows_processed_sum NUMBER := 0;
l_count_missing NUMBER := 0;
l_lang VARCHAR2(10) := 'US';

CURSOR c(c_lcode VARCHAR2) IS


select /*+ ROWID(msib) INDEX(msitl) */
msib.inventory_item_id ,
msib.concatenated_segments SEGMENTS_COMB ,
msib.organization_id ,
msitl.language ,
msitl.source_lang ,
msib.item_catalog_group_id ,
msitl.creation_date ,
msitl.created_by ,
msitl.last_update_date ,
msitl.last_updated_by ,
msitl.last_update_login
FROM mtl_system_items_tl msitl,
mtl_system_items_kfv msib
WHERE msitl.inventory_item_id = msib.inventory_item_id
AND msitl.organization_id = msib.organization_id
AND msitl.language = c_lcode
AND NOT EXISTS
(SELECT *
FROM ego.ego_item_text_tl eit
WHERE 1 = 1
AND eit.item_id = msitl.inventory_item_id
AND eit.org_id = msitl.organization_id
AND eit.LANGUAGE = msitl.LANGUAGE );

CURSOR c_lang IS
select language_code
from FND_LANGUAGES
where installed_flag in ('I','B');

sql_stmt VARCHAR2 (32767);


BEGIN
DBMS_OUTPUT.enable(32000);
DBMS_OUTPUT.put_line ('Process Started');

l_eitl_row_count := 0;
g_installed := fnd_installation.get_app_info ('EGO', g_inst_status, g_industry,
g_prod_schema);

-- Unique index must exist


SELECT COUNT (1)
INTO l_unq_index_count
FROM all_indexes
WHERE owner = g_prod_schema AND index_name = 'EGO_ITEM_TEXT_TL_U1';

IF (l_unq_index_count = 0)
THEN
raise_application_error (-20001, 'Error: text table unique index does not exist.');
END IF;

SELECT COUNT(*)
INTO l_count_missing
FROM mtl_system_items_tl msitl, mtl_system_items_b msib
WHERE msitl.inventory_item_id = msib.inventory_item_id
AND msitl.organization_id = msib.organization_id
AND msitl.LANGUAGE = l_lang
AND NOT EXISTS
(SELECT *
FROM ego.ego_item_text_tl eit
WHERE eit.item_id = msitl.inventory_item_id
AND eit.org_id = msitl.organization_id
AND eit.LANGUAGE = msitl.LANGUAGE );

IF (l_count_missing = 0) THEN
DBMS_OUTPUT.put_line ('No missing record in table ego_item_text_tl, exit...');
RETURN;
END IF;

DBMS_OUTPUT.put_line ('There are ' || l_count_missing ||' missing records.');

FOR c_lang_rec IN c_lang LOOP

DBMS_OUTPUT.put_line ('Processing language ' || c_lang_rec.language_code);


FOR c_rec IN c(c_lang_rec.language_code) LOOP
--DBMS_OUTPUT.put_line ('Processing ' || c_rec.SEGMENTS_COMB);

BEGIN
INSERT INTO ego_item_text_tl
(id_type ,
item_id ,
item_code ,
org_id ,
language ,
source_lang ,
item_catalog_group_id ,
inventory_item_id ,
text ,
creation_date ,
created_by ,
last_update_date ,
last_updated_by ,
last_update_login)
values('$$INTERNAL$$' ,
c_rec.INVENTORY_ITEM_ID ,
c_rec.SEGMENTS_COMB ,
c_rec.ORGANIZATION_ID ,
c_rec.LANGUAGE ,
c_rec.SOURCE_LANG ,
c_rec.ITEM_CATALOG_GROUP_ID ,
c_rec.INVENTORY_ITEM_ID ,
'0' ,
c_rec.CREATION_DATE ,
c_rec.CREATED_BY ,
c_rec.LAST_UPDATE_DATE ,
c_rec.LAST_UPDATED_BY ,
c_rec.LAST_UPDATE_LOGIN );

-- DBMS_OUTPUT.put_line ('Inserted row Successfully for ' || c_rec.SEGMENTS_COMB );

EXCEPTION
-- Check for "ORA-00001: unique constraint violated"
WHEN DUP_VAL_ON_INDEX
THEN
l_eitl_row_count := 1;
DBMS_OUTPUT.put_line ('ORA-00001: unique constraint violated for ' ||
c_rec.SEGMENTS_COMB );
EXIT;
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('Exception ' || SQLERRM || c_rec.SEGMENTS_COMB );
RAISE;
END; -- execute sql_stmt

END LOOP;
END LOOP;

--
-- commit transaction here
--
COMMIT;
DBMS_OUTPUT.put_line ('Calling Sync ....');
EGO_ITEM_PUB.SYNC_IM_INDEX;

DBMS_OUTPUT.put_line ('Process Completed');

END;
/
-- SELECT statement to show data has been removed or updated. Should return 0 for
-- deletions and specified in a comment for updates.
-- Should be provided for each DELETE or UPDATE statement. This is NOT needed for
INSERT statments.
-- Select count(*) statements are acceptable if you expect a lot of data to be
returned.
<insert SELECT statement>

-- The commit; command should always be commented out.


-- The DBA executing this script will issue a commit or rollback depending on the
outcome of the script.
-- commit;

Anda mungkin juga menyukai