Checkboxes in report to insert or update a value, doesn't do both
920671Feb 28 2012 — edited Feb 29 2012I'm going crazy trying to solve this, hopefully someone can help me out. At the moment, I have a credit card table that will contain the information relating to a user-credit card pairing. Banks and such can submit credit cards to users, and the credit card table will be updated, with the column Approved_Flag being set to "N". Now, in another page, I have a report that displays any credit cards that a user may want, along with checkboxes. This report contains any bank submitted cards, or any cards that have been marked "General". Users can decide which ones they would like to keep, and then hit a submit button, which will update the credit card table. Existing records in the table would have the Approved column marked 'Y', new records from the so called "General" cards would be inserted.
The issue is that with the code I've written, it updates any existing records in the credit card table perfectly, but it will not insert any new information. The following is my code for the process that activates when the submit button is hit:
FOR i in 1..APEX_APPLICATION.G_F01.count
LOOP
MERGE INTO ls_credit_cards dest
USING( SELECT apex_application.g_f01(i) credit_card_id,
:F125_USER_ID created_by,
sysdate created_on,
:P54_CARDS card_id,
:P54_USER user_id,
'Y' approved_flag
FROM dual) src
ON( dest.credit_card_id = src.credit_card_id )
WHEN MATCHED
THEN
UPDATE SET dest.approved_flag = src.approved_flag
WHEN NOT MATCHED
THEN
INSERT( credit_card_id,
created_by,
created_on,
card_id,
user_id,
approved_flag )
VALUES( src.credit_card_id,
src.created_by,
src.created_on,
src.card_id,
src.user_id,
src.approved_flag );
END LOOP;
Through some testing, I've found out the the issue is any "General" credit cards will not have a credit card ID assigned to them. By hard coding it, I can get them to insert, but then existing records do not get updated. I've used this code to assign each checkbox in the table a credit_card_id (I think...) so I don't understand why this isn't working.
APEX_ITEM.CHECKBOX(1,credit_card_id) " ",
Could anyone shed some light on how I can do this? I would appreciate it IMMENSELY