I want to put the value of checked name from a checkbox in oracle apex into a table, but unable to do that.
I tried taking help from google but the steps mentioned didn't work too.
Could you please advise how to do that if I have taken a blank form and then added a checkbox to it, also I fetched the checkbox value from LOV.
1
votes
Can you show us what you already tried?
- Dominik
Please provide more information: which items do you have, what did you do, which kinds of processes, your code, etc. All what is needed to reproduce error.
- Dmitriy
I have added a checkbox with a name: 'P12_NEW'. This checkbox contains a list of users. There is one textbox on the top to enter the amount manually. I want that amount to appear in front of each user which I mark as checked "in a table named:'usr_amt' after I click save button".
- Anshul Ayushya
1 Answers
2
votes
As I understand, you are using a List of Values as a source of your checkboxes. Let's say you have following values there:
return value display value
----------------------------
123 andAND
456 Dibya
789 Anshul
321 aafirst
555 Anuj
When you select several values, APEX puts their return values into a string and separate them with :
. So for the case in your screenshot the value in item P12_NEW
will be 123:555
. To split this values you can use the following query:
select regexp_substr(:P12_NEW, '[^:]+', 1, level) values
from dual
connect by regexp_substr(:P12_NEW, '[^:]+', 1, level) is not null
The result will be:
values
------
123
555
Next, you need to put these values into table usr_amt
(let's say with columns user_id
and amount
, and the amount is entered into item P12_AMOUNT
):
merge into usr_amt t
using (select regexp_substr(:P12_NEW, '[^:]+', 1, level) user_id
from dual
connect by regexp_substr(:P12_NEW, '[^:]+', 1, level) is not null
) n on (n.user_id = t.user_id)
when matched then update
set t.amount = :P12_AMOUNT
when not matched then insert (user_id, amount)
values (n.user_id, :P12_AMOUNT)
This query will search for the each user_id
selected in the table, and if the user presents there, updates the corresponding value to the value of item :P12_AMOUNT
, if not present - inserts a row with user_id
and the value.