Neurotic
Neurotic

Reputation: 210

Saving Checkbox data in a DB column

I created an item P1_checkbox in Oracle APEX, using LOV(select ename, empno from emp WHERE ename LIKE 's%';) which gives multiple checkboxes.
When I check the boxes, I want to INSERT the checked boxes data into another table "emp_selected".

Then, when I login into the application again, the application now should have the checkboxes ticked(checked) based on the data inserted into the table "emp_selected" along with unchecked boxes from table "emp" and when I uncheck some of pre-selected checkboxes and check the new checkboxes, it should be updated accordingly in "emp_selected".

My Oracle APEX version is 4.2.

Upvotes: 2

Views: 4275

Answers (2)

Tom
Tom

Reputation: 7028

An apex checkbox with multiple checkboxes will save its state as all selected values concatenated to eachother with a colon, eg One:Two:Three.
So you will have to seperate those values, loop over them, and save them.
And you will need to configure your checkbox source correctly.
See the sample page I set up (apex_demo/demo)

All my setup is on that page too. For the sake of the example I'm using an apex collection to simulate a table which stores the values. The principle is the exact same - you'll simple need to adapt to your table with your selections.

Checkboxes LOV SQL:

select ename, empno from emp

Checkboxes Source settings:

Source: Always - SQL Query return colon seperated value

select c001
from apex_collections
where collection_name = 'CHECKBOX_EXAMPLE'

This will take all the values selected and concatenate them to eachother with a colon. And the checkbox will take those values and mark them as being selected.

An after submit process:

DECLARE
    l_vc_arr2    APEX_APPLICATION_GLOBAL.VC_ARR2;
BEGIN
  apex_collection.create_or_truncate_collection('CHECKBOX_EXAMPLE');
    l_vc_arr2 := APEX_UTIL.STRING_TO_TABLE(:P37_CHECKBOXES);
    FOR z IN 1..l_vc_arr2.count LOOP
        apex_debug.message(l_vc_arr2(z));
        apex_collection.add_member(p_collection_name => 'CHECKBOX_EXAMPLE', p_c001 => l_vc_arr2(z));
    END LOOP;
END;

Upvotes: 2

Amol
Amol

Reputation: 428

If you want to insert data on specific check event then you can use Ajax Call back with Run on demand process. which will get call from JavaScript code. You can refer this blog : http://warp11.nl/2011/04/execute-page-process-with-ajax-callback/

Upvotes: 0

Related Questions