Oracle Apex - (Security Group|Workspace Id) (Apex Context)

Card Puncher Data Processing


The security group id is the workspace id. Setting the security group id specify the workspace. It is especially useful when:

  • you want to use an APEX function outside Apex (ie in the database) (Thanks to in/basdeklerk)
  • a schema is associated with more than one workspace




for c1 in (
   select workspace_id
     from apex_applications
    where application_id = p_app_id )
   apex_util.set_security_group_id(p_security_group_id => c1.workspace_id);
end loop;
create or replace procedure new_tasks
    l_workspace_id      number;
    l_subject           varchar2(2000);
    l_body              clob;
    l_body_html         clob;
    l_workspace_id := apex_util.find_security_group_id (p_workspace => 'PROJECTS');
    apex_util.set_security_group_id (p_security_group_id => l_workspace_id);
    l_body := ' ';
    l_subject := 'You have new tasks';
    for c1 in (select distinct(p.email_address) email_address, p.user_id
                 from teamsp_user_profile p, teamsp_tasks t
                where p.user_id = t.assigned_to_user_id
                  and t.created_on > sysdate - 1
                  and p.email_address is not null ) loop
        l_body_html := '<p />The following tasks have been added.';
        for c2 in (select task_name, due_date
                     from teamsp_tasks
                    where assigned_to_user_id = c1.user_id
                      and created_on > sysdate - 1 ) loop
            l_body_html := l_body_html || '<p />Task: '||c2.task_name||', due '||c2.due_date;
        end loop;
    apex_mail.send (
            p_to        => c1.email_address,
            p_from      => c1.email_address,
            p_body      => l_body,
            p_body_html => l_body_html,
            p_subj      => l_subject );
    end loop;


ORA-20001: This procedure must be invoked from within an application session.

You are trying to call an APEX function (below MAIL) not from the APEX application but from the database. You need to set the security group.

ORA-20001: This procedure must be invoked from within an application session.
ORA-06512: at "APEX_040100.WWV_FLOW_MAIL", line 333
ORA-06512: at "APEX_040100.WWV_FLOW_MAIL", line 371
ORA-06512: at "APEX_040100.WWV_FLOW_MAIL", line 413

Documentation / Reference

Discover More
Card Puncher Data Processing
Oracle Apex - Mail

Mail in Apex can be sen with the package. API The most efficient approach to sending email is to create a background job (using the DBMS_JOB or DBMS_SCHEDULER package) to periodically send all mail...
Apex Find Workspace
Oracle Apex - Workspace

A workspace is a virtual private database allowing multiple users to work within the same Oracle Application Express installation while keeping their objects, data and applications private. Each workspace...

Share this page:
Follow us:
Task Runner