ApEx runtime installation

I found many blogs about installing ApEx in a runtime environment, but alway missing some in the scripts or having errors in it.

These scripts are test for a customer and I’m sure that this works:-)

To create a workspace:

Login to Oracle as sysdba and run this script to create a workspace:

First make sure that you database schemas create in the database; If not just create it with (create user MY_SCHEMA identified by some_password;)

ALTER SESSION SET CURRENT_SCHEMA = APEX_040200;
BEGIN
apex_instance_admin.add_workspace
( p_workspace_id => null,
p_workspace => ‘MY_WS’,
p_primary_schema => ‘MY_SCHEMA’,
p_additional_schemas => ‘MY_SCHEMA2′ );
END;

This scripts adds to schemas to my workspace, If you want to have only one schema, just  make sure that you have both p_primary_schema and p_additional_schemas the same.

spool install_my_application.log;

DECLARE

l_workspace_id NUMBER;
l_app_alias varchar2(100) :=’MYAPP_200′;
l_app_schema varchar2(100) :=’MY_SCHEMA’;
— an application number of an existing application in the workspace.
l_existing_app NUMBER := 200;
— the “new” application number, an existing number will be dropped first.
l_new_app NUMBER := 200;

BEGIN
— set workspace id
SELECT workspace_id
INTO l_workspace_id
FROM apex_workspaces
WHERE workspace = ‘MY_WS’;
FOR c IN

(SELECT app.application_id
FROM apex_applications app
WHERE app.application_id = l_existing_app
)
LOOP
apex_instance_admin.remove_application(l_existing_app);
END LOOP;
— generate offset for this application
apex_application_install.generate_offset;
— set application workspace
apex_application_install.set_workspace_id( l_workspace_id );
— set application ID
apex_application_install.set_application_id(l_new_app);

— force reset application schema
apex_application_install.set_schema(l_app_schema);
— Set the application alias
apex_application_install.set_application_alias(l_app_alias);

END;

/

@f200.sql;
@f200_img.sql;

spool off;

You can also create Dev and Admin users via command line

ALTER SESSION SET CURRENT_SCHEMA = APEX_050100;
DECLARE
l_workspace varchar2(100) :=’TS’;
l_app_schema varchar2(100) :=’TS’;
l_workspace_id number;

BEGIN

SELECT workspace_id
INTO l_workspace_id
FROM apex_workspaces
WHERE workspace = l_workspace;

apex_util.set_security_group_id (p_security_group_id => l_workspace_id);

APEX_UTIL.CREATE_USER(
p_user_name => ‘ADMIN’,
p_first_name => ‘First’,
p_last_name => ‘Last’,
p_description => ‘Description…’,
p_email_address => ‘admin@admin.com’,
p_web_password => ‘mypassword!’,
p_developer_privs => ‘ADMIN:CREATE:DATA_LOADER:EDIT:HELP:MONITOR:SQL’,
p_default_schema => l_app_schema,
p_change_password_on_first_use => ‘N’,
p_attribute_01 => ‘123 456 7890’);
END;

That is all.