Dear Friends
How can i create a duplicate copy of a Master-detail record and save in Oracle apex.
Currently i tried with Multiple method ,
1.Created a button as Duplicate record and in the process written process as dupliate, but even when i submitt button its gettng duplicate of header reocrds but not the detail records but even in header it duplicates the same no of records which are in details and in details not a single record is created,
Kindly suggest the complete process how to do it , in Oracle 12c I had created a Procedure but here in Apex i dont know how to do it currently i tried the following query . Please guide and suggest step by step
DECLARE
newMasterID NUMBER;
BEGIN
-- Duplicate master record
INSERT INTO TEST_H (COMPANY, ENTRY_DATE, AMOUNT, NOTE)
SELECT COMPANY, ENTRY_DATE, AMOUNT, NOTE
FROM TEST_H
WHERE ID = :P41_ID; -- Replace P41_ID with the actual item name of your master record ID
-- Get the new master record ID
SELECT MAX(ID) INTO newMasterID
FROM TEST_H;
-- Duplicate detail records
FOR detail_rec IN (SELECT SR_NO, LICNO, LICDATE, AMOUNT
FROM TEST_D
WHERE TEST_ID = :P41_ID) -- Replace P41_ID with the actual item name of your master record ID
LOOP
INSERT INTO TEST_D (TEST_ID, SR_NO, LICNO, LICDATE, AMOUNT)
VALUES (newMasterID, detail_rec.SR_NO, detail_rec.LICNO, detail_rec.LICDATE, detail_rec.AMOUNT);
END LOOP;
COMMIT;
-- Refresh the form to display the duplicated records
:P41_ID := newMasterID; -- Replace P41_ID with the actual item name of your master record ID
END;
sandy