I don't remember when I was so excited about the new APEX feature as at the moment when I've discovered that there's a new parameter in procedure apex_export.get_application called p_components that enables component export. I know, it's small, but it opens a big playground.
Maybe the reason for this excitement is that for some time now, I'm working on an APEX app for creating patches of database object and APEX components and the only missing piece was API for component export. I had that working before APEX 19.2, but I had to use an internal export procedure which is not so convenient.
The only thing that you could do with the apex_export API before 19.2 was to export a whole application or all components in some predefined structure.
From APEX 19.2 you can export any component that you want through the API. So, how can you do that...
... is pretty straight forward. Just select component from a new dictionary APEX_APPL_EXPORT_COMPS. The columns that you need for component export are TYPE_NAME and ID, for example:
Then you should combine them in the array in form TYPE_NAME:ID (currently there's a bug in 19.2 docs, where you can find that the array values should be formed as TYPE:NAME):
The output of the get_application procedure is a table of apex_t_export_file (with name and contents columns). Name column will always have same value (in format f{APP_ID}_components.sql, for example, f100_components.sql) and the contents column will have export code (as a CLOB). No matter how many components do you add to the array you'll always get only one file/element as an output. The only time when you can get more files is if you set p_split parameter to true.
After that, you can spool code into SQL file as shown in the example in the documentation or play with it in so many different ways. For example, one of the ways is to create an application to manage your APEX component exports (with nice filenames), as shown here https://apex.oracle.com/pls/apex/f?p=apexbyg:62.
More about that in the next blog post.
Tested in APEX 19.2.0.00.18.
Enjoy!
Maybe the reason for this excitement is that for some time now, I'm working on an APEX app for creating patches of database object and APEX components and the only missing piece was API for component export. I had that working before APEX 19.2, but I had to use an internal export procedure which is not so convenient.
The only thing that you could do with the apex_export API before 19.2 was to export a whole application or all components in some predefined structure.
From APEX 19.2 you can export any component that you want through the API. So, how can you do that...
The Code...
... is pretty straight forward. Just select component from a new dictionary APEX_APPL_EXPORT_COMPS. The columns that you need for component export are TYPE_NAME and ID, for example:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sql> select type_name, id, name from apex_appl_export_comps where application_id = 100; | |
TYPE_NAME ID NAME | |
______________________ ___________________ _____________________________________ | |
PAGE 1 1. Home | |
PAGE 9999 9999. Login Page | |
PAGE 0 0. Global Page - Desktop | |
AUTHENTICATION 1705946737884396 Application Express Authentication | |
BREADCRUMB_ENTRY 1706465552884421 Breadcrumb: Home (1) | |
BREADCRUMB_TEMPLATE 1822209678886357 Breadcrumb | |
CALENDAR_TEMPLATE 1822374152886375 Calendar | |
BUTTON_TEMPLATE 1820158589886323 Icon | |
BUTTON_TEMPLATE 1820835683886341 Text | |
BUTTON_TEMPLATE 1820970941886342 Text with Icon | |
REGION_TEMPLATE 1729022563885012 Alert | |
REGION_TEMPLATE 1732711541885199 Blank with Attributes | |
REGION_TEMPLATE 1732974873885207 Blank with Attributes (No Grid) | |
REGION_TEMPLATE 1733719243885219 Buttons Container |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare | |
v_files apex_t_export_files; | |
v_components apex_t_varchar2 := apex_t_varchar2(); | |
begin | |
v_components.extend(2); | |
v_components(1) := 'PAGE:0'; | |
v_components(2) := 'AUTHENTICATION:1705946737884396'; | |
v_files := apex_export.get_application(p_application_id => 100 | |
, p_components => v_components); | |
-- if you don't set p_split => true, there will be always ony one file as output | |
dbms_output.put_line(v_files(1).name); | |
dbms_output.put_line(v_files(1).contents); | |
end; | |
/ |
After that, you can spool code into SQL file as shown in the example in the documentation or play with it in so many different ways. For example, one of the ways is to create an application to manage your APEX component exports (with nice filenames), as shown here https://apex.oracle.com/pls/apex/f?p=apexbyg:62.
More about that in the next blog post.
Tested in APEX 19.2.0.00.18.
Enjoy!
Hi Marko,
ReplyDeleteThank you for all the work you do for the community!!!
There is a little typo on line 14. It should be: dbms_output.put_line(v_files(1).contents);
Kind regards,
Geert.
Thanks! It's fixed now.
Delete