/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2015 Applaud Solutions UK Ltd                |
 |                             All rights reserved                            |
 *===========================================================================*/

SET VERIFY OFF
SET FEEDBACK OFF
SET SCAN OFF
WHENEVER OSERROR  EXIT FAILURE ROLLBACK
WHENEVER SQLERROR EXIT FAILURE ROLLBACK

DECLARE

  --
  -- Local constants and variables
  --
  l_sql varchar2(32000);

BEGIN

  --
  -- Register Query Assignments By Saved Search
  --
  l_sql :=
'        SELECT /*+ cardinality(rslts 10)*/
               rslts.*
        FROM   TABLE(xxas_per_search_pkg.people_tbl
                      (null
                      ,(SELECT xxas_saved_search_pkg.xml_to_obj(ss.search_parameters)
                        FROM   xxas_saved_searches_v ss
                        WHERE  ss.saved_search_id = :pSavedSearchId
                        AND    xxas_com_sec_pkg.test_instance
                                (''XXAS_DATA_SAVED_SEARCH_VIEW'', :pSavedSearchId) = ''Y'')
                      )) rslts ';

  xxas_com_sr_pkg.seed_query_service
    (p_service_name      => 'QueryAssignmentsBySavedSearch'
    ,p_securing_function => 'XXAS_SRV_Q_ASG_PERM'
    ,p_sql               => l_sql
    ,p_parameters        => xxas_com_sr_param_varray
                              (xxas_com_sr_param_type('pSavedSearchId', xxas_com_sr_pkg.g_NUMBER))
    ,p_page_size         => 25);

END;
/
COMMIT;
EXIT;
