 |
|
ss
Oracle Tips by Burleson |
Working
with Multiple Select Lists
When a page is submitted, the value of a Multiple
Select List page item will become a list of values separated by
colons. For example, in Figure 10.25, the Blue, Green and Red values
have been chosen. The page item will be set to the value B:G:R since
those are the corresponding results from the LOV.
There are three ways to now process the value in
the page item.
1.
The string can be kept as a colon-delimited string and stored
in the database.
2.
The INSTR function can be used to process the information.
-- Search to see if Blue is part of
the string
if instr(:P1_MLIST,'B') > 0 then
-- process Blue
else
If instr(:P1_MLIST,'R') > 0 then
-- process Red
else
...
end if;
3.
The list can be processed by utilizing the HTML DB API function
called HTMLDB_UTIL.STRING_TO_TABLE. This function takes the result
string and turns it into a PL/SQL array. The array can be processed
in any manner. The following is an example of use:
declare
selected_items htmldb_application_global.vc_arr2;
begin
--
-- convert the colon separated string of values into
-- a pl/sql array
selected_items := htmldb_util.string_to_table( :P1_MLIST
);
--
-- loop over array to insert items into a table
for i in 1..selected_items.count
loop
insert into colors_table
values ( selected_items(i) );
end loop;
end;
The reverse of this PL/SQL code can be
performed in order to reassemble the value for the page item.
declare
selected_list htmldb_application_global.vc_arr2; i
integer := 1;
begin
for r in( select color
from color_table ) loop
selected_list(i) := r.class_id;
i := i + 1;
end loop;
:P1_MLIST :=
htmldb_util.table_to_string( selected_list,
':' );
end;
The above book excerpt is from:
Easy HTML-DB
Oracle Application Express
Create
Dynamic Web Pages with OAE
ISBN 0-9761573-1-4
Michael Cunningham & Kent Crotty
http://www.rampant-books.com/book_2005_2_html_db.htm
|