Я хочу извлечь некоторые записи из исходной таблицы, находящейся в одной базе данных, а затем вставить эти записи в удаленную таблицу через вызов удаленного пакета и снова после вставки записей в элемент управления удаленной таблицы должен прийти и удалить эти конкретные записи в исходной таблице.
"КОД"
- основная процедура
Create or replace Procedure P1
is
l_count NUMBER;
l_proc_status VARCHAR2 (100);
CURSOR c_core_data
IS
SELECT a.ROWID
FROM table_1 a
WHERE creation_date < SYSDATE - 10;
TYPE xx_rowid_type IS TABLE OF c_core_data%ROWTYPE
INDEX BY PLS_INTEGER;
xx_rowid_table xx_rowid_type;
BEGIN
BEGIN
SELECT COUNT (1)
INTO l_count
FROM table_1
WHERE creation_date < SYSDATE - 10;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_count := 0;
WHEN OTHERS
THEN
l_count := 0;
END;
IF l_count > 1
THEN
schema.table_2@dblink(); -- remote procedure call for archive LOB table
BEGIN
SELECT process_status
INTO l_proc_status
FROM schema.Status_table@dblink
a
WHERE a.table_name = 'table_1'
AND a.ROWID =
(SELECT MAX (b.ROWID)
FROM schema.Status_table@dblink
b
WHERE a.table_name = b.table_name);
EXCEPTION
WHEN OTHERS
THEN
RAISE ARCHIEVE_EXP;
END;
IF l_proc_status = 'FAILED'
THEN
l_proc_str := 'schema.table_2';
RAISE ARCHIEVE_EXP;
END IF;
END IF;
OPEN c_core_data;
LOOP
FETCH c_core_data BULK COLLECT INTO xx_rowid_table LIMIT 100;
EXIT WHEN xx_rowid_table.COUNT = 0;
FORALL idx IN xx_rowid_table.FIRST .. xx_rowid_table.LAST
DELETE FROM table_1 b
WHERE b.ROWID = xx_rowid_table (idx).ROWID;
COMMIT;
END LOOP;
CLOSE c_core_data;
COMMIT;
END;
- удаленная процедура
Create or replace Procedure schema.table_2
is
l_sql_errm VARCHAR2 (1000);
CURSOR c_x
IS
SELECT a.ROWID
FROM schema.table_1@dblink A
WHERE creation_date < SYSDATE - 10;
TYPE xx_c_type IS TABLE OF c_x%ROWTYPE
INDEX BY PLS_INTEGER;
xx_row_table xx_c_type;
CURSOR c_gtt
IS
SELECT a.ROWID
FROM table_1_GTT a;
BEGIN
OPEN c_x;
LOOP
FETCH c_x BULK COLLECT INTO xx_row_table LIMIT 1000;
EXIT WHEN xx_row_table.COUNT = 0;
FOR idx IN xx_row_table.FIRST .. xx_row_table.LAST
LOOP
INSERT INTO schema.table_1_GTT (
DERIVED_RESELLER_CCOID,
DERIVED_DISTI_CCOID)
SELECT DERIVED_RESELLER_CCOID,
DERIVED_DISTI_CCOID
FROM schema.table_1@dblink
a
WHERE a.ROWID = xx_row_table (idx).ROWID;
END LOOP;
FOR idx IN c_gtt
LOOP
INSERT INTO schema.table_2(
DERIVED_RESELLER_CCOID,
DERIVED_DISTI_CCOID,
PURGE_DATE)
SELECT DERIVED_RESELLER_CCOID,
DERIVED_DISTI_CCOID,
SYSDATE
FROM schema.table_1_GTT a
WHERE a.ROWID = idx.ROWID;
END LOOP;
COMMIT;
END LOOP;
CLOSE c_x;
COMMIT;
INSERT INTO Status_table
VALUES ('table_1',
'COMPLETE',
SYSDATE,
'Success');
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
l_sql_errm := SUBSTR (SQLERRM, 1, 1000);
INSERT INTO Status_table
VALUES ('table_1',
'FAILED',
SYSDATE,
l_sql_errm);
COMMIT;
END;