Oracle APEX - APEX COLLECTION

"APEX collections" is one of the most important features that come with Oracle APEX, and it can be used in many ways for different purposes, but in general, you can think of Apex collection as a temporary space to store complex data types — nonscalar — for instance, full row of data from a table or a view.

This data can be manipulated in any way and then stored in table(s). Each Apex Collection can can has 50 varchar2 attributes (c001 -> c0050), 5 number attributes (n001->n005), 5 date attributes (d001->d005), 1 CLOB attribute (clob001), and 1 BLOB attribute (blob001). Each collection must have a unique name. 

I will only show some basic steps. For a more detailed explanation please follow the official APEX documentation

Create an APEX_COLLECTION:

In this example I check if my collection exists and if not then I will create a new one and add some rows. 

begin
 if not apex_collection.collection_exists('DATA_COLLECTION') then 
  apex_collection.create_collection('DATA_COLLECTION');
  apex_collection.add_member(
    p_collection_name => 'DATA_COLLECTION',
    p_c001 =>            '1',
    p_c002 =>            'APEX & SQL: THE Reporting Solution',
    p_c003 =>            'Grundsätzlich soll mit der...',
    p_c004 =>            '2015',
    p_c005 =>            'https://apex.oracle.com/pls/apex/f?p=55360:1'
  );
  apex_collection.add_member(
    p_collection_name => 'DATA_COLLECTION',
    p_c001 =>            '2',
    p_c002 =>            'Plug-Ins maßgerecht verwenden',
    p_c003 =>            'Wann macht ein Plugin Sinn...',
    p_c004 =>            '2015',
    p_c005 =>            'https://apex.oracle.com/pls/apex/f?p=80307:1'
  );
 end if;
end;

Next is to select the data from inside an APEX report:

select 
    c001,
    c002,
    c003,
    c004,
    c005
  from apex_collections
  where collection_name = 'DATA_COLLECTION'

And finally I want to check if I get the same results inside my SQL Developer:

-- Set up APEX SESSION

declare
  v_ws_id number;
  v_app_id number := &app_id;
  v_session_id number := &session_id;
begin
  select workspace_id into v_ws_id from apex_workspaces;
  wwv_flow_api.set_security_group_id(v_ws_id);
  wwv_flow.g_flow_id := v_app_id;
  wwv_flow.g_instance := v_session_id;
end;
/

-- Execute SQL
select *
from apex_collections
where collection_name = 'DATA_COLLECTION';


Dynamic Column Attributes FORM using APEX_ITEM

Use the below SQL in Simple Report APEX Region. 

SELECT LEVEL AS item_no,
APEX_ITEM.TEXT(p_idx => 1, p_attributes => NULL) AS Name,
APEX_ITEM.text( p_idx=> 2 , p_value=> null , p_attributes=> 'class="number"') as Age,
APEX_ITEM.SELECT_LIST(  p_idx        =>3,
                        p_value       => 'MALE',
                        p_list_values => 'MALE;MALE,FEMALE;FEMALE'
--                        p_attributes  in varchar2 default null,
--                        p_show_null   in varchar2 default 'NO',
--                        p_null_value  in varchar2 default '%null%',
--                        p_null_text   in varchar2 default '%',
--                        p_item_id     in varchar2 default null,
--                        p_item_label  in varchar2 default null,
--                        p_show_extra  in varchar2 default 'YES'
                        ) Gender,
APEX_ITEM.TEXT(p_idx => 4, p_attributes => NULL) AS School
FROM dual
CONNECT BY LEVEL <= TO_NUMBER (:P9_HOW_MANY);

This will create form elements dynamically based on the SQL Query instead of creating individual items page by page.

Comments

Popular posts from this blog

Oracle BI Publisher Tags For-each grouping for Matrix report

SQL Scripts for Custom Table Creation in Oracle Application 12.2.x

Oracle Fusion Business Intelligence Roles