OracleAPEXScrip/ng101:TheCommandLineIsYourFriend
DietmarAustOpal-Consul/ng,Kölnwww.opal-consul/ng.de
► Dipl.-Inform.DietmarAust,FreelanceConsultant▪ Master'sDegreeinComputerScience(MSCS)
► BuildingOraclebasedWebApplica/onssince1997▪ Portal,Forms,Reports,OWAToolkit,nowAPEX!
► 1997-2000:ConsultantatOracleGermany
► Since09/2000:FreelanceConsultant,Since2006–APEXonly!
► Blog:h\p://daust.blogspot.com/
► RegularpresenteratOracleconferences(ODTUG,DOAG,OOW)
► AuthoroftheJasperReportsIntegra/ontoolkit▪ h\p://www.opal-consul/ng.de/tools
DietmarAust
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 3
DietmarAust
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 4
► 2015DatabaseDeveloperoftheyearintheORDScategory
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 5
Agenda
► ExportsandBackups▪ Anatomyofanexportfile▪ APEXExport,APEXExportSpli\er
► Deployment▪ APEX_APPLICATION_INSTALL▪ APEX_INSTANCE_ADMIN▪ BUILD_OPTIONS▪ APEX_LANG
► sqlcl
Agenda
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 6
Whyautomate?
WhyCommandLineScrip/ng?
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 7
Quality
• Manualprocedures=>didImissanything?
• Timepressure=>Irathersleepwell
Performance
► Principles▪ 80/20▪ KISS
WarumScrip/ng?
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 8
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 9
ExportsandBackups
► PureSQLtextfile,encodedasUTF-8
► Differentcomponentsseparatedbycomments
► evenBLOBSarehex-encodedastext
ExportsandBackupsAnatomyofanexportfile
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 10
► Everythinghappenswithinadatabasetransac/on▪ Firstdeleteapplica/on,theninstallagainfromscratch
► Incaseofasqlerror,rollbackhappensautoma/cally
► APEXismetadata-driven,thuseach"object"inAPEX(template,bu\on,region,etc.)hasitsownuniqueID
ExportsandBackupsAnatomyofanexportfile
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 11
► Inordertoavoidconflictsinthemedatatarepositoryduringexport/importAPEXworkswithnumericalrangesforeachapplica/onusingOFFSETs
► AnOFFSETisderivednumericallyfromtheapplica/on-id
► Eachapplica/onidisuniquewithintheAPEXinstance
ExportsandBackupsAnatomyofanexportfile
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 12
► Workspaceexporthastwoop/ons(asofAPEX5.0)
► Minimal:▪ Workspace-defini/on▪ Groups,Users
ExportsandBackupsExportfromtheapplica/onbuilder
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 13
► TheFULLworkspaceexportnowcontainsEVERYTHING(withtheexcep/onofapplica/ons,websheetsandworkspacesta/cfiles)▪ --WORKSPACE▪ --GROUPS▪ --USERS▪ --Applica/onBuilderPreferences▪ --ClickCountLogs▪ --csvdataloading
► Why?UsedfortheOracleCloudtomoveworkspacesdoadifferentinstancetransparenttotheuser.
► Exportoftheworkspacesta/cfilesusingAPEXExportcommandlineu/lityintheapex/u/li/esdirectory(seetheReadme.txtfilethere):
ExportsandBackupsExportfromtheapplica/onbuilder
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 14
▪ --mail▪ --maillog▪ --appmodels▪ --passwordhistory▪ --preferences▪ --querybuilder▪ --sqlscripts▪ --sqlworkshophistory▪ Resqulservicedefini/ons,...
�javaoracle.apex.APEXExport-dblocalhost:1521:xe-usertest-password<pwdTest>-workspaceid2614526486790575-expFiles
► Applica/on-Export
ExportsandBackupsExportfromtheapplica/onbuilder
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 15
► Applica/on-Export
ExportsandBackupsExportfromtheapplica/onbuilder
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 16
APEXExportClass–thecommandlinealterna/ve
► PartoftheAPEXdownload:
► Requirements▪ JDK1.5▪ OracleJDBClibraryisfoundontheclasspath,atleastojdbc5.jar
ExportsandBackupsAPEXExport
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 17
► TypicalUseCases
► Backup▪ thewholeAPEXinstance▪ asingleworkspace▪ oneormoreapplica/ons
► Propagateapplica/ons▪ Exportapplica/ons,sothattheycanbeimportedintoothersystemslikeQ/Aor
produc/onautoma/cally
ExportsandBackupsAPEXExport
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 18
Demo
► Wecanbuildeverythingbyourselves…or?▪ h\p://ischaicham.com/wiki/
Oracle_APEX_applica/on_and_workspace_backup_script▪ h\p://sve.to/2012/03/12/automa/cally-backup-oracle-apex-applica/ons-to-
subversion/
► OraOpenSource/APEXBackup▪ h\p://www.talkapex.com/2015/04/apex-backup-script.html▪ h\ps://github.com/OraOpenSource/apexbackup
ExportsandBackups
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 19
APEXSpli\erClass
► PartoftheAPEXdownload:
► Requirements▪ JDK1.5▪ OracleJDBClibraryisfoundontheclasspath,atleastojdbc5.jar
ExportsandBackupsAPEXSpli\er
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 20
► ExporthierarchicalwithsubdirectoriesorFLAT
► Canseeeasilythedifferences(onatechnicallevel)whencoupledwithversioncontrolsystems
ExporteundBackupsAPEXSpli\er
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 21
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 22
Deployment
Thisishowitshouldbe…
Deployment
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 23
APEX Development APEX Test
APEX Production
...thisiswhatittypicallylookslike...
Deployment
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 24
APEX Production APEX Development / Test and Integration Environment
...andunfortunatelythisisnotreallyararecase...
Deployment
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 25
APEXDevelopment/TestandIntegra7onEnvironment
SchemaA
APEXProduc7on
SchemaB
Prepara/onforthesimplestapproach
► Createiden/calworkspacesinallenvironments=>iden/calworkspaceID▪ Createthemusingexport/importoftheworkspace(assqlscript)▪ Createthemusingtheapex_instance_adminapi▪ Createthembycloningtheinstances
► Advantages▪ SQLscriptscanberununmodifiedonallsystems(DEV,TEST,PROD)
− PARSING_SCHEMA
− Applica/onID
− WorkspaceID
▪ Singlepageorcomponentexportworkswithoutproblems
Deployment
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 26
Whatcouldthesescriptslooklike?
Deployment
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 27
*)setNLS_LANGonthecommandlinesetNLS_LANG=GERMAN_GERMANY.WE8MSWIN1252*)runpatchasuserSHDB_JDA@_patch_shdb_jda.sql*)runpatchasuserSHDB_200@_patch.sql*)installAPEXapplicationssetNLS_LANG=GERMAN_GERMANY.AL32UTF8sqlplusshdb_200DECLAREl_workspace_idNUMBER;BEGINl_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
DeploymentSampleinstalla/onscript
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 28
Install–varia/onswithapex_applica/on_install
► Thebasisistheapplica/onexportfile,somehardcodedsesngscanbeoverriddenatinstall/me:
DeploymentAPEX_APPLICATION_INSTALLATION
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 29
Installa/on:differentworkspaceanddifferentapplica/onid
► AnewOFFSETmustbegeneratedwhenevertheapplica/onidchanges
► Setnewaliaswhentheapplica/onalreadyexistsinthetargetinstance
DeploymentAPEX_APPLICATION_INSTALLATION
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 30
DECLAREl_workspace_idNUMBER;BEGINl_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_application_alias('F'||apex_application_install.get_application_id);apex_application_install.generate_offset;END;/@f100.sql
Installa/onwithgeneratedapplica/onid
► AnewOFFSETmustbegeneratedwhenevertheapplica/onidchanges
DeploymentAPEX_APPLICATION_INSTALLATION
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 31
BEGINapex_application_install.generate_application_id;apex_application_install.generate_offset;END;/@f100.sql
Installa/onwithdifferentparsingschema
DeploymentAPEX_APPLICATION_INSTALLATION
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 32
BEGINapex_application_install.set_schema('SCHEMA_NEW');END;/@f100.sql
PackageAPEX_INSTANCE_ADMIN
► Commandlineequivalentsforallfunc/onali/esprovidedbytheINTERNALworkspaceadministra/onGUI
► EspeciallyimportantinanAPEXRUNTIMEONLYenvironmentsincethereisnoGUIavailable
► Requirements?
► Readandwriteinstancesesngs
► Manageworkspacesanduser
► Interac/vereports(managesavedreportsandsubscrip/ons)
DeploymentAPEX_INSTANCE_ADMIN
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 33
GRANTAPEX_ADMINISTRATOR_ROLEto<OracleSchema>;
► Createworkspaceusingascript
► Addworkspace–schemamapping
DeploymentAPEX_INSTANCE_ADMIN
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 34
BEGINAPEX_INSTANCE_ADMIN.ADD_WORKSPACE(p_workspace_id=>8675309,p_workspace=>'MY_WORKSPACE',p_primary_schema=>'SCOTT',p_additional_schemas=>'HR:OE');END;
BEGINAPEX_INSTANCE_ADMIN.ADD_SCHEMA('MY_WORKSPACE','HR');END
► Readandwriteinstancesesngs
► Displayallcurrentinstancesesngs:
ScriptindirectoryAPEX-Install/apex/u/li/es
DeploymentAPEX_INSTANCE_ADMIN
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 35
BuildOp/ons
► Usedtoenable/disablepartsofanapplica/on
► Booleanswitch:ONorOFF(APEX:IncludeorExclude)
► CanbeappliedtoalmosteveryAPEX“object”:page,tab,listelement,lov,bu\on,process,dynamicac/on,…
► Configurefeatures,whichyoumightnotwanttodeploytoproduc/on▪ All“objects”andcodeisalwayspartoftheexportedfile,itusjustnotenabledon
theproduc/onsystem▪ Thebuildop/onwillonlybetakenintoaccountatrun/me
► Wecanuseapl/sqlapitodeterminethecurrentstateandthusprogramagainstit
DeploymentBuildOp/ons
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 36 Demo
► Enable/disableabuildop/on:
► Thuswecanselec/velyenable/disablefeaturesatinstall/meorlateronthecommandline
DeploymentBuildOp/ons
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 37
► apex_lang.create_language_mapping/update/delete
► apex_lang.seed_application
► apex_lang.update_translated_string
► apex_lang.publish_application
DeploymentAPEX_LANG(version4.2.3andlater)
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 38
► Byusingpublish_applica/ona“shadowapplica/on”iscreated
► Duringtheapplica/onexporttypicallyalltranslatedstringsforalllanguagesareincluded–theshadowapplica/onsforthedifferenttranslatedareNOTcreatedonthetargetsystemautoma/cally.
► Why?Thebasicideawastobeabletoexport/importeachtranslatedapplica/onbyseparately.
DeploymentAPEX_LANG
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 39
► Publishanapplica/ononthenewsystemintothetargetlanguage
► ModifyingtextswithouttheregularXLIFF-procedure▪ apex_lang.seed_transla/ons▪ apex_lang.update_translated_stringforalltextsthathavechanged▪ apex_lang.publish_applica/on
DeploymentAPEX_LANG
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 40
BEGINAPEX_UTIL.set_security_group_id(APEX_UTIL.find_security_group_id('OPAL'));apex_lang.publish_application(p_application_id=>109,p_language=>'en');END;/
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 41
SQLcl
SQLcl–AJavabasedalterna/ve/replacementtoSQL*Plus
► DevelopedbytheSQLDeveloperTeam=>manyfeaturesavailable
► h\p://www.oracle.com/technetwork/developer-tools/sqlcl/overview/index.html
► Installa/onasazipfile,noinstallorsetupneccessary▪ 13MB▪ UsesJava,thusonlyasingleversionforWindows,LinuxandOSX▪ RequiresJava8run/meenvironment,notaJDK▪ Noaddi/onallicencerequired
CommandLine–SQLcl
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 42
► Currentlys/llearlyadopter(Version4.2.0.16.131.1023,13.05.2016)
► PlannedreleasetogetherwithOracleDatabase12cR2
► ConnecttoOracleDB:▪ EZConnect:
▪ IfORACLE_HOMEissetthenalso:− TNS,
− ThickOCIandeven
− LDAPconnec/ons
► Displayhelpusing▪ help▪ help<command>
CommandLine–SQLcl
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 43
► Edi/ngofstatementsintheSQLbuffer=>VERYcoolJ▪ ctrl-w,ctrl-snavigatestothebeginning/endofthebuffer▪ Cursorup/downchangeslines
► TAB-autocomplete▪ Completecommands,tablenames,viewnames,etc.
► Aliases=>ShortcutsforSQLorPL/SQL
► ExtractDDLwithdbms_metadata
► ExportAPEXapplica/ons
► ExportRESTapplica/ons
► Integra/onwithmul/pleJVMbasedscrip/nglanguages/JSR-223
CommandLine–SQLclTheeditor
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 44
Sqlclscrip/ng
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 45
Demo
► GesngStarted:▪ 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
► BlogvonKrisRice:h\p://krisrice.blogspot.de/search/label/sdsql
► Github–BeispieleausdemTeam▪ h\ps://github.com/oracle/oracle-db-tools/tree/master/sqlcl/examples▪ h\ps://github.com/oracle/oracle-db-tools/tree/master/sqlcl
Sqlclscrip/ng
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 46
Contact
28.06.2016 Oracle APEX Scripting 101: The Command Line Is Your Friend Page 47
DietmarAustOpal-Consul/ng,Kölnwww.opal-consul/ng.dedaust.blogspot.comdietmar.aust@opal-consul/ng.de