Rick Sparks
Rick Sparks

Reputation: 11

Apex 4.2 - Selecting multiple items for 1 record in a table

I have a table with a column that contains multiple, one or no values per row.

Using Apex the only field I can think that can automatically define these values (which need to be dynamically populated as can change) is a shuttle.

Is there any way to change a column value to be a shuttle list? With the values on the right being entered into the column on the db as comma separated values (or anything really)?

For example my table: User varchar - just their name Role(s) varchar - none/one/many roles associated with that user separated

Thanks, Rick

Upvotes: 1

Views: 914

Answers (1)

Tony Andrews
Tony Andrews

Reputation: 132570

If you want the values stored in a single column like this:

ROLE1:ROLE2:ROLE3

then the shuttle does everything you need. Whatever values you have selected on the right hand side of the shuttle are concatenated together using colons as the item value when the page is saved. Similarly when a value like 'ROLE6:ROLE7' is loaded from the database, those 2 roles will appear on the right hand side of the shuttle.

If you wanted to break them out to store in separate database rows you could use the function apex_util.string_to_table:

declare
    l_tab apex_application_global.vc_arr2;
begin
    l_tab := apex_util.string_to_table(:p1_role_shuttle);
    for i in 1..l_tab.count loop
        -- l_tab(i) contains the i'th role selected.
    end loop;
end;

There is also apex_util.table_to_string to do the reverse.

Upvotes: 3

Related Questions