| automate inserts from one schema to another [message #572955] |
Tue, 18 December 2012 23:15  |
|
|
We have two databases one localdb with user rakdb and another one remotely remotedb with user rakdb .We need to be in sync with data in one table called om_item, where the users are inserting data on daily basis and the user sends us the insert script everday to run it on local databse to insert the new records in local database.I managed to create a file which records all the inserts into one text file in one directory.Can we have a scheduler to pick this text file from the specified folder and send mail using utl_mail.
CREATE TABLE ITEM (IT_CODE VARCHAR2(12),IT_NAME VARCHAR2(20));
INSERT INTO ITEM VALUES ('A','AAA');
CREATE OR REPLACE DIRECTORY MY_DIR AS 'C:\TEMP';
CREATE OR REPLACE PROCEDURE it_status
IS
v_filehandle UTL_FILE.FILE_TYPE;
CURSOR itc
IS
SELECT 'INSERT INTO ITEM (IT_CODE, ITEM_NAME) VALUES ('''
|| IT_CODE || ''',''' || IT_NAME || ''');'
AS insert_statement
FROM item
ORDER BY it_code;
BEGIN
-- v_filehandle := UTL_FILE.FOPEN ('MY_DIR', 'AAAA.TXT', 'W');
v_filehandle :=
UTL_FILE.fopen
('MY_DIR',
'AAAA_' || TO_CHAR (SYSDATE, 'MMDDYYYY_HHAM') || '.TXT',
'w');
FOR v_it_rec IN itc
LOOP
UTL_FILE.PUT_LINE (v_filehandle, v_it_rec.insert_statement);
END LOOP;
UTL_FILE.PUT_LINE (v_filehandle, 'COMMIT;');
UTL_FILE.FCLOSE (v_filehandle);
END it_status;
/
Procedure created.
EXEC it_status
HOST TYPE c:\temp\aaaa.txt
INSERT INTO ITEM (IT_CODE, ITEM_NAME) VALUES ('A','AAA');
COMMIT;
|
|
|
|
|
|
|
|
|
|
|
|