Oracle APEX Scripting 101 - The Command Line Is Your Friend
Oracle APEX Scripting 101 - The Command Line Is Your Friend
Dietmar Aust
Opal-Consul/ng, Köln
www.opal-consul/ng.de
Dietmar Aust
► Blog: h\p://daust.blogspot.com/
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 3
Dietmar Aust
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 4
Agenda
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 5
Agenda
► Deployment
▪ APEX_APPLICATION_INSTALL
▪ APEX_INSTANCE_ADMIN
▪ BUILD_OPTIONS
▪ APEX_LANG
► sqlcl
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 6
Why Command Line Scrip/ng?
Why automate?
Quality Performance
• Manual procedures => did I
miss anything?
• Time pressure => I rather
sleep well
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 7
Warum Scrip/ng?
► Principles
▪ 80/20
▪ KISS
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 8
Exports and Backups
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 9
Exports and Backups
Anatomy of an export file
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 10
Exports and Backups
Anatomy of an export file
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 11
Exports and Backups
Anatomy of an export file
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 12
Exports and Backups
Export from the applica/on builder
► Minimal:
▪ Workspace-defini/on
▪ Groups, Users
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 13
Exports and Backups
Export from the applica/on builder
► The FULL workspace export now contains EVERYTHING (with the excep/on of
applica/ons, websheets and workspace sta/c files)
▪ --mail
▪ -- W O R K S P A C E
▪ --mail log
▪ -- G R O U P S
▪ --app models
▪ -- U S E R S
▪ --password history
▪ --Applica/on Builder Preferences
▪ --preferences
▪ --Click Count Logs
▪ --query builder
▪ --csv data loading
▪ --sql scripts
▪ --sql workshop history
► Why? Used for the Oracle Cloud to
move workspaces do a different ▪ Resqul service defini/ons, ...
instance transparent to the user.
► Export of the workspace sta/c files using APEXExport command line u/lity in
the apex/u/li/es directory (see the Readme.txt file there):
java oracle.apex.APEXExport -db localhost:1521:xe -user test
-password <pwdTest> -workspaceid 2614526486790575 -expFiles
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 14
Exports and Backups
Export from the applica/on builder
► Applica/on-Export
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 15
Exports and Backups
Export from the applica/on builder
► Applica/on-Export
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 16
Exports and Backups
APEXExport
► Requirements
▪ JDK 1.5
▪ Oracle JDBC library is found on the classpath, at least ojdbc5.jar
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 17
Exports and Backups
APEXExport
► Backup
▪ the whole APEX instance
▪ a single workspace
▪ one or more applica/ons
► Propagate applica/ons
▪ Export applica/ons, so that they can be imported into other systems like Q/A or
produc/on automa/cally
Demo
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 18
Exports and Backups
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 19
Exports and Backups
APEXSpli\er
► Requirements
▪ JDK 1.5
▪ Oracle JDBC library is found on the classpath, at least ojdbc5.jar
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 20
Exporte und Backups
APEXSpli\er
► Can see easily the differences (on a technical level) when coupled with version
control systems
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 21
Deployment
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 22
Deployment
APEX Production
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 23
Deployment
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 24
Deployment
Schema A Schema B
APEX Development /
Test and Integra7on APEX Produc7on
Environment
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 25
Deployment
► Advantages
▪ SQL scripts can be run unmodified on all systems (DEV, TEST, PROD)
− PARSING_SCHEMA
− Applica/on ID
− Workspace ID
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 26
Deployment
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 27
Deployment
Sample installa/on script
*) set NLS_LANG on the command line
set NLS_LANG=GERMAN_GERMANY.WE8MSWIN1252
*) run patch as user SHDB_JDA
@_patch_shdb_jda.sql
*) run patch as user SHDB_200
@_patch.sql
*) install APEX applications
set NLS_LANG=GERMAN_GERMANY.AL32UTF8
sqlplus shdb_200
DECLARE
l_workspace_id NUMBER;
BEGIN
l_workspace_id := APEX_UTIL.FIND_SECURITY_GROUP_ID ('WORKSPACE_NAME');
apex_application_install.set_workspace_id (l_workspace_id);
apex_application_install.set_application_id(104);
apex_application_install.set_schema('SHDB_200');
END;
/
@apex/f104_Spots_v15.2.0.0.sql
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 28
Deployment
APEX_APPLICATION_INSTALLATION
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 29
Deployment
APEX_APPLICATION_INSTALLATION
► Set new alias when the applica/on already exists in the target instance
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 30
Deployment
APEX_APPLICATION_INSTALLATION
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 31
Deployment
APEX_APPLICATION_INSTALLATION
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 32
Deployment
APEX_INSTANCE_ADMIN
Package APEX_INSTANCE_ADMIN
► Command line equivalents for all func/onali/es provided by the INTERNAL
workspace administra/on GUI
► Requirements?
GRANT APEX_ADMINISTRATOR_ROLE to <Oracle Schema>;
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 33
Deployment
APEX_INSTANCE_ADMIN
BEGIN
APEX_INSTANCE_ADMIN.ADD_WORKSPACE (
p_workspace_id => 8675309,
p_workspace => 'MY_WORKSPACE',
p_primary_schema => 'SCOTT',
p_additional_schemas => 'HR:OE' );
END;
BEGIN
APEX_INSTANCE_ADMIN.ADD_SCHEMA('MY_WORKSPACE','HR');
END
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 34
Deployment
APEX_INSTANCE_ADMIN
Script in directory
APEX-Install/apex/u/li/es
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 35
Deployment
Build Op/ons
Build Op/ons
► Used to enable / disable parts of an applica/on
► Can be applied to almost every APEX “object”: page, tab, list element, lov,
bu\on, process, dynamic ac/on, …
► Thus we can selec/vely enable / disable features at install /me or later on the
command line
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 37
Deployment
APEX_LANG (version 4.2.3 and later)
► apex_lang.create_language_mapping
/ update / delete
► apex_lang.seed_application
► apex_lang.update_translated_string
► apex_lang.publish_application
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 38
Deployment
APEX_LANG
► During the applica/on export typically all translated strings for all languages
are included – the shadow applica/ons for the different translated are NOT
created on the target system automa/cally.
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 39
Deployment
APEX_LANG
BEGIN
APEX_UTIL.set_security_group_id (
APEX_UTIL.find_security_group_id ('OPAL'));
apex_lang.publish_application (p_application_id => 109,
p_language => 'en');
END;
/
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 40
SQLcl
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 41
Command Line – SQLcl
► h\p://www.oracle.com/technetwork/developer-tools/sqlcl/overview/
index.html
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 42
Command Line – SQLcl
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 43
Command Line – SQLcl
The editor
► TAB-autocomplete
▪ Complete commands, table names, view names, etc.
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 44
Sqlcl scrip/ng
Demo
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 45
Sqlcl scrip/ng
► Gesng Started:
▪ h\ps://www.doag.org/formes/pubfiles/7535126/docs/Konferenz/2015/
vortraege/Oracle%20Datenbanken/2015-K-DB-Oded_Raz-
I_ve_seen_the_Future,_It_Is_Glorious__SQLcl_replace_SQLPlus-
Praesenta/on.pdf
▪ h\ps://www.youtube.com/watch?v=HApdy-o525A
▪ h\ps://www.doag.org/formes/pubfiles/7535126/docs/Konferenz/2015/
vortraege/Oracle%20Datenbanken/2015-K-DB-Oded_Raz-
I_ve_seen_the_Future,_It_Is_Glorious__SQLcl_replace_SQLPlus-
Praesenta/on.pdf
▪ h\p://www.oracle.com/technetwork/issue-archive/2015/15-sep/o55sql-
dev-2692807.html
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 46
Contact
Dietmar Aust
Opal-Consul/ng, Köln
www.opal-consul/ng.de
daust.blogspot.com
dietmar.aust@opal-consul/ng.de
Oracle APEX Scripting 101: The Command Line Is Your Friend 28.06.2016 Page 47