Monday, 26 October 2020

Oracle APEX selected components export from API (APEX_EXPORT)

 Oracle APEX 20.1 introduced new functionality for application components export. Function APEX_EXPORT.get_application got a new parameter named P_COMPONENTS.

So, with this parameter it is possible to make a list of components for which a scripts will be returned. No need to export and split full application.


But beware!

P_SPLIT parameter (boolean value) is still functional and it has a great influence on function result!


If value of P_SPLIT parameter is FALSE, function will return one script for all components from P_COMPONENTS parameter.


If value is TRUE it will return multiple scripts. 

For every component 2 scripts will be created:

  • delete component script
  • create component script
Plus, additional scripts will be generated:
  • set environment (as first script in collection)
  • end environment (as second last script in collection)
  • main install script which executes all generated scripts (as last script in collection)

So, do not make a mistake like me - to set a P_SPLIT parameter to TRUE and expect one script per component to be generated (for example 3 scripts for 3 pages). There are only two scenarios - one script for everything OR multiple scripts (environment, delete components, create components, finish install, main install script).
Example:

DECLARE
    l_files apex_t_export_files;

BEGIN
    --get files
    l_files := apex_export.get_application(
        p_application_id => 400,
        p_split => true,
        p_components => apex_t_varchar2('PAGE:3000')
    );

    FOR t IN 1 .. l_files.count LOOP
        dbms_output.put_line(l_files(t).name);
    END LOOP;
    
END;

prints

f400/application/set_environment.sql
f400/application/pages/delete_03000.sql
f400/application/pages/page_03000.sql
f400/application/end_environment.sql
f400/install_page.sql

With FALSE value it returns only one script named f400.sql

No comments:

Post a Comment