28. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 7/14/2017 12:26:22 AM Eastern Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

28.1 Files compared

# Location File Last Modified
1 OSCIF_ADR_v3.18_build 4.zip\DDL\PSIM procedure.sql Fri Mar 4 13:21:28 2016 UTC
2 OSCIF_ADR_v3.18_build 4.zip\DDL\PSIM procedure.sql Fri Jul 14 03:46:39 2017 UTC

28.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 3 2232
Changed 2 6
Inserted 0 0
Removed 0 0

28.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

28.4 Active regular expressions

No regular expressions were active.

28.5 Comparison detail

  1   DROP PROCE DURE PSIM. PS_MSG_LOG _CLEANUP_S P;
  2  
  3   CREATE OR  REPLACE PR OCEDURE PS IM.PS_MSG_ LOG_CLEANU P_SP
  4     (p_rows_ delete_in_ batch IN I NTEGER DEF AULT 100,
  5      p_days_ retain       IN INTEG ER DEFAULT  365) IS
  6   -- ####### ########## ########## ########## ########## ########## ########## ########
  7   -- #  Desc ription: C CR 1526 -  Retain 1 y ear data o f PS_MSG_L OG
  8   -- #
  9   -- #
  10   -- #   Usa ge:             Calle d by run_w rapper.sql
  11   -- #   Inp ut Paramet ers:
  12   -- #     1 ) None
  13   -- #   Out put:
  14   -- #     1 ) Terminal
  15   -- #   Int ernal Scri pt Paramet ers:
  16   -- #     1 ) None
  17   -- #
  18   -- #
  19   -- ####### ########## ########## ########## ########## ########## ########## ########
  20   -- # Chang e History
  21   -- #
  22   -- # DATE        User  Name          DESCRI PTION
  23   -- # ----- ----- ---- ---------- --- ------ ---------- ---------- ---------- -------
  24   -- # 11/10 /2012  PII           Created sc ript.    This is a  release en hancement
  25   -- # 01/09 /2013  PI i
        Modify to  close/open  cursor to  avoid ora  1555.
  26   -- #                               Added DB MS_APPLICA TION_INFO  for debugg ing
  27   -- # 02/22 /2015  PII         Removed pa rallelism  DOP.    Added para llel_insta nce_group
  28   -- #                               to restr ict the pr ocess run  on the las t node
  29   -- ####### ########## ########## ########## ########## ########## ########## ########
  30  
  31  
  32   ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------
  33   -- Begin C cr depende nt data in put area
  34   ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------
  35   CC_PSIM_OW NER     CO NSTANT VAR CHAR2(4) : = 'PSIM';
  36   CC_TAB_NAM E       CO NSTANT VAR CHAR2(14): = 'PS_MESS AGE_LOG';
  37   CC_CONS_NA ME      CO NSTANT VAR CHAR2(16): = 'MSGLOG_ MSGLOG_FK' ;
  38   CC_MAX_ROW S_DEL   CO NSTANT NUM BER(12)  : =  1000000 000;  -- A ssuming 10 0 mil is b ig enough  to retain  1 yr data
  39  
  40  
  41   VC_process _name   VA RCHAR2(60)  := 'DELET E PS MSG L OG';
  42   VN_days_re tain    PL S_INTEGER   := p_days _retain;
  43   VC_msg_ste p       VA RCHAR2(200 );
  44  
  45   VC_total_c ount    NU MBER := 0;
  46   VC_count           NU MBER := 0;
  47   VN_paralle l_inst_grp        VAR CHAR2(60)  := NULL;
  48   VN_job_cou nt      NU MBER := 0;
  49  
  50   VC_tmp           NUMB ER := 0;
  51  
  52   VN_batch_r ows     PL S_INTEGER  := p_rows_ delete_in_ batch;
  53   VC_SQLSTMT _DDL    VA RCHAR2(300 ) := NULL;
  54   VD_log_dat e       DA TE;
  55   VD_beg_run _date   DA TE;
  56   VC_error_m sg      VA RCHAR2(200 0);
  57   VN_EXCEPTI ON_CNT  PL S_INTEGER;
  58  
  59   dml_errors         EX CEPTION;
  60   NULL_PARAL LEL_INSTAN CE_GRP_E   EXCEPTION;
  61  
  62   PRAGMA EXC EPTION_INI T(dml_erro rs, -24381 );
  63  
  64  
  65    time_a      INTEGER;
  66    time_b      INTEGER;
  67    time_c      INTEGER;
  68  
  69    vc_mod_na me VARCHAR 2(100);
  70    vc_act_na me VARCHAR 2(100);
  71  
  72   TYPE varra yMsgLogID     IS TABL E OF PSIM. PS_MESSAGE _LOG.PS_ME SSAGE_LOG_ ID%TYPE;
  73  
  74     TABLE_Ms gLogID          varra yMsgLogID;
  75  
  76    CURSOR Mo d_cons_C I S
  77      SELECT  delete_rul e
  78      FROM    all_CONSTR AINTS
  79      WHERE C ONSTRAINT_ NAME= CC_C ONS_NAME
  80      AND own er = CC_PS IM_OWNER;
  81  
  82    CURSOR Ge tMsgLogID_ C IS
  83      SELECT  PS_MESSAGE _LOG_ID
  84      FROM PS IM.PS_MESS AGE_LOG
  85      WHERE T RUNC(RECOR D_CREATED_ DATE) < TR UNC(SYSDAT E) - VN_da ys_retain
  86      AND row num <= VN_ batch_rows ;
  87  
  88   BEGIN
  89  
  90       DBMS_A PPLICATION _INFO.SET_ MODULE(vc_ mod_name,  vc_act_nam e);
  91  
  92  
  93       DBMS_O UTPUT.PUT_ LINE(CHR(1 0));
  94       VC_msg _step := ' Get parall el_instanc e_group id ';
  95  
  96  
  97       EXECUT E IMMEDIAT E 'alter s ession for ce paralle l query pa rallel 1';
  98       EXECUT E IMMEDIAT E 'alter s ession for ce paralle l dml para llel 1';
  99  
  100       EXECUT E IMMEDIAT E 'ALTER S ESSION SET  db_file_m ultiblock_ read_count =128';
  101  
  102       vc_mod _name := V C_process_ name;
  103       vc_act _name := ' Initial';
  104  
  105  
  106  
  107       ADRMGT .Job_Proce ss_Log_Sp( PC_job_nam e => SUBST R(VC_proce ss_name,1, 60),
  108                   PD_jo b_log_date  => SYSDAT E,
  109                   PC_jo b_status = > 'INFORMA TION - Pro cess Initi ation - DO P '||VC_co unt,
  110                   PC_jo b_log_mess age => 'In itiating ' ||VC_proce ss_name,
  111                   PD_da te1 => VD_ beg_run_da te,
  112                   PC_te xt1 => 'Ba tch rows:  '||VN_batc h_rows|| '  Retention : '||p_day s_retain ) ;
  113  
  114  
  115       -- === ========== ========== ========== ========== ========== ========== ========
  116       --
  117       -- Che ck job is  currently  running or  not.  If  yes, no ne ed to star t again.
  118       --
  119       -- === ========== ========== ========== ========== ========== ========== ========
  120       VN_job _count:= 0 ;
  121       VC_cou nt := 0;
  122  
  123       VC_msg _step := ' Checking j ob activel y running. ';
  124  
  125       SELECT  COUNT(1)
  126         INTO    VN_job_ count
  127         FROM    SYS.DBA _JOBS_RUNN ING R,
  128                 SYS.DBA _JOBS J
  129         WHER E  J.JOB =  R.JOB
  130         AND     UPPER(J .WHAT) LIK E 'PSIM.PS _MSG_LOG_C LEANUP_SP% ';
  131  
  132         IF V N_job_coun t > 1 THEN
  133  
  134           VD _log_date  := SYSDATE ;
  135  
  136           AD RMGT.Job_P rocess_Log _Sp(PC_job _name => S UBSTR(VC_p rocess_nam e,1,60),
  137                                        PD_job _log_date  => VD_log_ date,
  138                                        PC_job _status =>  'INFORMAT ION  - Job  currently  running',
  139                                        PC_job _log_messa ge => 'Cur rently '|| VC_process _name||' j ob is runn ing => Exi ting SP.',
  140                                        PD_dat e1 => VD_b eg_run_dat e,
  141                                        PC_tex t1 => 'Job  aborted b ecause it  is current ly running .'||VN_job _count);
  142  
  143           RA ISE_APPLIC ATION_ERRO R(-20200,' The job is  currently  still run ning.');
  144  
  145  
  146       END IF ;
  147  
  148  
  149       -- === ========== ========== ========== ========== ========== ========== ========== ========== =====
  150       --
  151       -- The  WHILE-LOO P loops th ru until a ll rows de leted  tha t satifies  CC_MAX_RO WS_DEL
  152       -- con ditions.   CC_MAX_ROW S_DEL is t o provide  numbe of r ows to be  deleted.
  153       --
  154       -- === ========== ========== ========== ========== ========== ========== ========== ========== ====
  155  
  156       VC_msg _step := ' Begin whil e-loop of  '||CC_MAX_ ROWS_DEL;
  157  
  158       ADRMGT .Job_Proce ss_Log_Sp( PC_job_nam e => SUBST R(VC_proce ss_name,1, 60),
  159                   PD_jo b_log_date  => SYSDAT E,
  160                   PC_jo b_status = > 'INFORMA TION - WHI LE-LOOP St arted',
  161                   PC_jo b_log_mess age => VC_ msg_step,
  162                   PD_da te1 => SYS DATE);
  163  
  164  
  165       time_a  := dbms_u tility.get _time;
  166  
  167       ------ ---------- ---------- ---------- ---------- ---------- ----
  168       -- Thi s allows f or-loop to  be open-c lose to av oid ORA 15 55.
  169       ------ ---------- ---------- ---------- ---------- ---------- ----
  170  
  171       WHILE  VC_total_c ount <= CC _MAX_ROWS_ DEL LOOP
  172  
  173           DB MS_APPLICA TION_INFO. SET_ACTION (Action_na me => 'Pro cessing Da te: ' || d bms_utilit y.get_time );
  174  
  175           VC _msg_step  := 'Begin  bulk-delet e of '||VN _batch_row s;
  176  
  177  
  178          --- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---
  179          --  The cursor  will open , fetch an d close  e very xx ro ws which i s limited  by
  180          --  rownum of  the cursor .  This is  all to av oid  to av oid ORA155 5
  181          --- ---------- ---------- ---------- ---------- ---------- =--------- ---------- ----
  182  
  183          OPE N GetMsgLo gID_C;
  184  
  185          VC_ msg_step : = 'Begin B ulk-Collec tion Fetch .';
  186  
  187          FET CH GetMsgL ogID_C BUL K COLLECT  INTO TABLE _MsgLogID  LIMIT VN_b atch_rows;
  188  
  189  
  190          --  ========== ========== ========== ========
  191          --  Exit loop  if there i s no rows  found
  192          --  ========== ========== ========== ========
  193          --
  194          IF  TABLE_MsgL ogID.COUNT  = 0 THEN
  195  
  196               VC_msg_st ep := 'No  more rows  found in t he collect ion.';
  197  
  198               ADRMGT.Jo b_Process_ Log_Sp(PC_ job_name = > SUBSTR(V C_process_ name,1,60) ,
  199                   PD_jo b_log_date  => SYSDAT E,
  200                   PC_jo b_status = > 'INFORMA TION - WHI LE-LOOP En ded (Total  deleted ' ||VC_total _count||') ',
  201                   PC_jo b_log_mess age => VC_ msg_step,
  202                   PD_da te1 => SYS DATE);
  203  
  204               EXIT;
  205  
  206          ELS E
  207  
  208  
  209               VC_msg_st ep := 'Beg in for-all  batch del etion';
  210  
  211               FORALL I  IN TABLE_M sgLogID.FI RST..TABLE _MsgLogID. LAST SAVE  EXCEPTIONS
  212  
  213               DELETE PS _MESSAGE_L OG WHERE P S_MESSAGE_ LOG_ID = T ABLE_MsgLo gID(I);
  214  
  215               VC_count  := SQL%ROW COUNT;
  216  
  217               commit;
  218  
  219  
  220          END  IF;
  221  
  222          CLO SE GetMsgL ogID_C;
  223  
  224  
  225          --  ========== ========== ========== ========== ========== ========== ========== =
  226          --
  227          --  Log info t o the log  table.
  228          --
  229          --  ========== ========== ========== ========== ========== ========== ========== =
  230  
  231          tim e_c := dbm s_utility. get_time;
  232  
  233          VC_ msg_step : = 'While-l oop: loggi ng del row counts';
  234  
  235          VC_ total_coun t := VC_to tal_count  + VC_count ;
  236  
  237  
  238          DBM S_APPLICAT ION_INFO.S ET_CLIENT_ INFO('PS_M SG_LOG: De leted: '
  239                                ||  TO_CHAR(VC _count,'99 9,999,990' )
  240                                ||'  Total:'|| TO_CHAR(VC _total_cou nt,'999,99 9,999,990' ) );
  241  
  242  
  243       END LO OP;  -- WH ILE LOOP
  244  
  245  
  246       -- === ========== ========== ========== =
  247       -- === ========== ========== ========== =
  248       --
  249       -- Log ging resul ts to the  log table
  250       --
  251       -- === ========== ========== ========== =
  252       -- === ========== ========== ========== =
  253  
  254       VC_msg _step := ' After Whil e-loop';
  255  
  256       IF VC_ total_coun t > 0 THEN
  257  
  258            A DRMGT.Job_ Process_Lo g_Sp(PC_jo b_name =>  SUBSTR(VC_ process_na me,1,60),
  259                           PD_job_l og_date =>  SYSDATE,
  260                          PC_job_st atus => 'I NFORMATION  - Bulk De letion Com pleted',
  261                           PC_job_l og_message  => 'Total  rows dele ted: '||VC _total_cou nt||
  262                                  ' . Time too k '||NVL(T O_CHAR((ti me_c - tim e_a)/100), 0)|| ' sec onds',
  263                           PD_date1  => SYSDAT E,
  264                           PC_text1  => 'Proce ssed in ba tch of '|| VN_batch_r ows||
  265                               ' -  Days reten tions of ' ||p_days_r etain);
  266  
  267       ELSE
  268  
  269            A DRMGT.Job_ Process_Lo g_Sp(PC_jo b_name =>  SUBSTR(VC_ process_na me,1,60),
  270                               PD_j ob_log_dat e => SYSDA TE,
  271                              PC_jo b_status = > 'INFORMA TION - Bul k Deletion  Completed ',
  272                               PC_j ob_log_mes sage => 'N o rows fou nd to be d eleted. Ti me took '
  273                                      ||NVL(TO _CHAR((tim e_c - time _a)/100),0 )|| ' seco nds',
  274                               PD_d ate1 => SY SDATE,
  275                               PC_t ext1 => 'P rocessed i n batch of  '||VN_bat ch_rows||
  276                               ' -  Days reten tions of ' ||p_days_r etain);
  277       END IF ;
  278  
  279  
  280       DBMS_A PPLICATION _INFO.SET_ ACTION(Act ion_name = > NULL);
  281  
  282       DBMS_A PPLICATION _INFO.SET_ CLIENT_INF O('DELETE  MSG LOG -  COMPLETED:  DELETED ' ||TO_CHAR( VC_total_c ount,'999, 999,999,99 0'));
  283  
  284  
  285  
  286   EXCEPTION
  287  
  288      WHEN dm l_errors T HEN
  289  
  290  
  291         VN_E XCEPTION_C NT := SQL% BULK_EXCEP TIONS.COUN T;
  292  
  293         FOR  I IN 1 ..  VN_EXCEPTI ON_CNT LOO P
  294              VC_error_m sg :=
  295                'Error '  || I ||   ' During e xecution '  ||SQL%BUL K_EXCEPTIO NS(I).ERRO R_INDEX ||
  296                ' for '  || TABLE_M sgLogID(I)  ||' produ ced error  ' ||
  297                SQL%BULK _EXCEPTION S(I).ERROR _CODE;
  298  
  299              ADRMGT.Job _Process_E rr_Sp(PC_j ob_name =>  SUBSTR(VC _process_n ame,1,60),
  300                                     PD_job_er ror_date   => VD_log_ date,
  301                                     PC_job_er ror_code = > SUBSTR(S QL%BULK_EX CEPTIONS(I ).ERROR_CO DE,1,60),
  302                                     PC_job_er ror_messag e => VC_ms g_step||'  - '||SUBST R(VC_error _msg,1,200 0),
  303                                     PD_date1  => VD_beg_ run_date,
  304                                     PC_text1  => 'Failed  during DM L process.  Process i n batch of  '||VN_bat ch_rows||
  305                                      ' - Days  retention s of '||p_ days_retai n);
  306        END L OOP;
  307  
  308      WHEN OT HERS THEN
  309  
  310         ADRM GT.Job_Pro cess_Err_S p(PC_job_n ame => SUB STR(VC_pro cess_name, 1,60),
  311                                      PD_job_e rror_date   => VD_log _date,
  312                                     PC_job_er ror_messag e => VC_ms g_step||SU BSTR(' - U nknown err or while d eleting fr om PS_MESS AGE_LOG ro w.'
  313                                                                         || SQL ERRM,1,200 0),
  314                                      PD_date1  => VD_beg _run_date,
  315                                      PC_text1  => 'Faile d due to u nkown erro r. Process  in batch  of '||VN_b atch_rows| |
  316                                      ' - Days  retention s of '||p_ days_retai n);
  317  
  318   END;
  319   /
  320  
  321   CREATE OR  REPLACE PU BLIC SYNON YM PS_MSG_ LOG_CLEANU P_SP FOR P SIM.PS_MSG _LOG_CLEAN UP_SP;
  322   DROP PROCE DURE PSIM. INS_PROCES S_LOG_SP;
  323  
  324   CREATE OR  REPLACE PR OCEDURE PS IM.Ins_Pro cess_log_S P
  325                                               (
  326                                p_P rocess_Nam e                IN a dr_process _log.proce ss_name%ty pe
  327                             ,  p_P rocess_Sta rt_Date          IN a dr_process _log.proce ss_start_d ate%type
  328                             ,  p_P rocess_End _Date            IN a dr_process _log.proce ss_end_dat e%type
  329                             ,  p_P rocess_Sta tus_Code         IN a dr_process _log.proce ss_status_ code%type
  330                             ,  p_I ns_Kount                    IN a dr_process _log.proce ssed_count %type
  331                             ,  p_E rr_Kount                    IN a dr_process _log.error _count%typ e
  332                                               )
  333   IS
  334     PRAGMA A UTONOMOUS_ TRANSACTIO N;
  335   BEGIN                              -- Proce dure Begin
  336              INSERT INT O ADR_PROC ESS_LOG
  337                             (
  338                       A DR_PROCESS _LOG_ID
  339                             ,  PRO CESS_NAME
  340                             ,  PRO CESS_START _DATE
  341                             ,  PRO CESS_END_D ATE
  342                             ,  PRO CESS_STATU S_CODE
  343                    ,  P ROCESSED_C OUNT
  344                    ,  E RROR_COUNT
  345                    )
  346           VA LUES
  347   (
  348      rpt_psi m_s.nextva l
  349   ,  p_Proce ss_Name
  350   ,  p_Proce ss_Start_D ate
  351   ,  p_Proce ss_End_Dat e
  352   ,  p_Proce ss_Status_ Code
  353   ,  p_Ins_K ount
  354   ,  p_Err_K ount
  355                             ) ;
  356       COMMIT ;
  357     EXCEPTIO N
  358       WHEN O THERS THEN
  359         ROLL BACK;
  360   END Ins_Pr ocess_Log_ SP ;
  361   /
  362  
  363   GRANT EXEC UTE ON PSI M.INS_PROC ESS_LOG_SP  TO PSIM_R ;
  364  
  365   GRANT EXEC UTE ON PSI M.INS_PROC ESS_LOG_SP  TO PSIM_R W;
  366   DROP PROCE DURE PSIM. INS_ERROR_ MESSAGES_S P;
  367  
  368   CREATE OR  REPLACE PR OCEDURE PS IM.Ins_Err or_Message s_SP
  369                                               (
  370                                p_P rocess_Nam e                IN a dr_error_m essages.pr ocess_name %type
  371                             ,  p_p rimary_key _value           IN a dr_error_m essages.pr imary_key_ value%type
  372                             ,  p_e rror_code                   IN a dr_error_m essages.er ror_code%t ype
  373                             ,  p_e rror_messa ge_text          IN a dr_error_m essages.er ror_messag e_text%typ e
  374                             ,  p_e rror_descr iption           IN a dr_error_m essages.er ror_descri ption%type
  375                                               )
  376   IS
  377     PRAGMA A UTONOMOUS_ TRANSACTIO N;
  378   BEGIN                              -- Proce dure Begin
  379  
  380                    INSE RT INTO AD R_ERROR_ME SSAGES
  381           (
  382               ADR_ERROR _MESSAGE_I D
  383           ,   PROCESS_N AME
  384           ,   PRIMARY_K EY_VALUE
  385           ,   ERROR_COD E
  386           ,   ERROR_DAT E
  387           ,   ERROR_MES SAGE_TEXT
  388           ,   ERROR_DES CRIPTION
  389           )
  390   VALUES
  391           (
  392               rpt_psim_ s.nextval
  393           ,   p_Process _Name
  394           ,   p_primary _key_value
  395           ,   p_error_c ode
  396           ,   sysdate
  397           ,   p_error_m essage_tex t
  398           ,   p_error_d escription
  399                             ) ;
  400  
  401       COMMIT ;
  402     EXCEPTIO N
  403       WHEN O THERS THEN
  404         ROLL BACK;
  405   END Ins_Er ror_Messag es_SP ;
  406   /
  407  
  408   GRANT EXEC UTE ON PSI M.INS_ERRO R_MESSAGES _SP TO PSI M_R;
  409  
  410   GRANT EXEC UTE ON PSI M.INS_ERRO R_MESSAGES _SP TO PSI M_RW;
  411   DROP PROCE DURE PSIM. INITLOAD_P SIM_TRAITS _SP;
  412  
  413   CREATE OR  REPLACE PR OCEDURE PS IM.InitLoa d_PSIM_Tra its_SP(p_S OI           NUMBER,
  414                                      p_Status _Ind    VA RCHAR2,
  415                                      p_Active _Flag   VA RCHAR2,
  416                                      p_Name_T ype     VA RCHAR2,
  417                                      p_From_V PID     NU MBER,
  418                                      p_To_VPI D       NU MBER
  419                             )
  420           IS
  421   --
  422   --      Da te Repaire d            Author                    Desc ription
  423   --      07 /3/2007                 Chris Wo odyard           adde d PK excep tion handl ing
  424   --      07 /22/2008                Chris Wo odyard           adde d initiali zation of  local vari ables
  425   --
  426   --
  427   --
  428           BE GIN                     -- Proce dure Main  Begin
  429           DE CLARE
  430  
  431           --  Local var iable decl arations
  432  
  433                    v_Pr imary_VPID _Id                NU MBER(20)       ;
  434                    v_Pr imary_VPID _Value             VA RCHAR2 (29 )   ;
  435                    v_Pr imary_Key_ Value              VA RCHAR2(40)     ;
  436                    v_Pe rson_Trait _id                NU MBER(20)       ;
  437                    v_Da te_of_Birt h                  VA RCHAR2(8)      ;
  438                    v_Ge nder_Code                     VA RCHAR2(4)      ;
  439                    v_La st_Name                       VA RCHAR2(35)     ;
  440                    v_Fi rst_Name                      VA RCHAR2(25)     ;
  441                    v_Mi ddle_Name                     VA RCHAR2(25)     ;
  442                    v_Pr efix                          VA RCHAR2(10)     ;
  443                    v_Su ffix                          VA RCHAR2(10)     ;
  444                    v_SS N_Value                       VA RCHAR2(20)     ;
  445                    v_SS N_Type_Tex t                  VA RCHAR2(32)     ;
  446                    v_PS eudo_SSN_R eason_Text         VA RCHAR2(50)     ;
  447                    v_VR FN_Status_ Text               VA RCHAR2(70)     ;
  448                    v_Pr ocess_Name                    VA RCHAR2(25)     ;
  449                    v_Pr ocess_Star t_Date             DA TE             ;
  450                    v_Pr ocess_End_ Date               DA TE             ;
  451                    v_Pr ocess_Stat us_Code            VA RCHAR2(20)     ;
  452                    v_ss n_type_cod e                  VA RCHAR2(30)     ;
  453                    v_ps eudossnrea son_code           VA RCHAR2(1)      ;
  454                    v_ss nverificat ionstatus_ code    VA RCHAR2(10)     ;
  455                    v_ss a_sent_dat e                  DA TE             ;
  456                    v_ss a_received _Date              DA TE             ;
  457                    v_ss a_verified _date              DA TE             ;
  458                    v_er r_code                        VA RCHAR2(50)     ;
  459                    v_er r_msg_text                    VA RCHAR2(250 )   ;
  460                    v_er r_descr                       VA RCHAR2(200 0)  ;
  461                    v_In s_Kount                       NU MBER(10)       ;
  462                    v_Er r_Kount                       NU MBER(10)       ;
  463                    v_Co mmit_Kount                    NU MBER(10)       ;
  464                    v_ss averifcode _code              ch ar(1)          ;
  465                    pk_v iol_flag                      VA RCHAR2(1)      ;
  466                    pk_v iolation                      EX CEPTION        ;
  467  
  468                    PRAG MA EXCEPTI ON_INIT(pk _violation ,-1);
  469  
  470  
  471           --  Cursor to  extract a ll valid V PIDs based  on System  of Intere st and Sta tus Indica tor criter ia  --
  472  
  473  
  474                    CURS OR c_ps_vp id_recs is
  475                    SELE CT
  476                             ps_vpi d.ps_perso nvpid_id,
  477                             ps_vpi d.VPID_VAL UE,
  478                             ps_vpi d.id_state _ind,
  479                             ps_vpi d.identity _transacti on_type,
  480                             ps_pc. persontrai t_id
  481                      FR OM
  482                             PS_Per son_VPID p s_vpid,
  483                             PS_Per son_Correl ation PS_P C
  484                     WHE RE  ps_vpi d.ps_perso nvpid_id =  ps_pc.per son_vpid_i d
  485                       A ND  ps_pc. system_of_ interest_t ype_id = p _SOI
  486                       A ND  ps_pc. status_ind  = p_Statu s_Ind
  487                       A ND  ps_vpi d.ps_perso nvpid_id b etween p_F rom_VPID a nd p_To_VP ID ;
  488  
  489                    v_ps _vpid_recs   c_ps_vpi d_recs%row type ;
  490  
  491                    BEGI N   -- Pro cedure Bod y Begin
  492  
  493                    -- L ocal varia bles value  assignmen ts
  494  
  495                      v_ Ins_Kount             := 0    ;
  496                      v_ Err_Kount             := 0    ;
  497                      v_ Commit_Kou nt         := 0    ;
  498                      v_ Process_Na me         := 'INIT_L OAD_PSIM_T RAITS'       ;
  499                      v_ Process_St art_Date   := sysdate                         ;
  500                      v_ Process_St atus_Code  := 'SUCCES S'                      ;
  501  
  502                      OP EN c_ps_vp id_recs;           --   Outer Lo op for c_p s_vpid_rec s (Step 1  Design)
  503  
  504                      LO OP
  505                         v_Person_T rait_Id :=  NULL;
  506                         v_Date_of_ Birth := N ULL;
  507                         v_Gender_C ode := NUL L;
  508                         v_Last_Nam e := NULL;
  509                         v_Middle_N ame := NUL L;
  510                         v_First_Na me := NULL ;
  511                         v_Prefix : = NULL;
  512                         v_Suffix : = NULL;
  513                         v_SSN_Valu e := NULL;
  514                         v_ssn_type _code := N ULL;
  515                         v_pseudoss nreason_co de := NULL ;
  516                         v_ssnverif icationsta tus_code : = NULL;
  517                         v_ssa_sent _date := N ULL;
  518                         v_ssa_rece ived_date  := NULL;
  519                         v_ssa_veri fied_date  := NULL;
  520                         v_ssaverif code_code  := NULL;
  521  
  522  
  523                      FE TCH c_ps_v pid_recs I NTO v_ps_v pid_recs ;
  524                             EXIT W HEN c_ps_v pid_recs%N OTFOUND;
  525  
  526   ------  St ep 2 Desig n: Fetch T rait Ident ifiers inf ormation b ased on Pr imary Trai t Ids for  each veter an VPID de rived in s tep 1
  527  
  528  
  529                             BEGIN             -- Begin P erson Trai t PL/SQL B lock
  530  
  531  
  532                               SELE CT
  533                                      pt.ps_pe rson_trait _id,
  534                                      pth.birt h_date_tex t,
  535                                      gndr.cod e
  536                                 IN TO
  537                                      v_Person _Trait_Id,
  538                                      v_Date_o f_Birth,
  539                                      v_Gender _Code
  540                                 FR OM
  541                                      ps_perso n_trait pt ,
  542                                      ps_perso n_trait_hi story pth,
  543                                      std_gend er gndr
  544                                WHE RE
  545                                        pt.ps_ person_tra it_Id = v_ ps_vpid_re cs.persont rait_id
  546                                  A ND  (( pth .owner_id  = pt.ps_pe rson_trait _id )
  547                                  A ND  (pth.i s_active_f lag = p_Ac tive_Flag  ))
  548                                  A ND  gndr.i d = pth.ge nder_id ;
  549  
  550                             EXCEPT ION                --  Begin Per son Trait  Exception
  551                               WHEN  NO_DATA_F OUND THEN
  552                                      BEGIN
  553                                               v_err_code       := S QLCODE ;
  554                                               v_err_msg_ text  := s ubstr(SQLE RRM,1,64)  ;
  555                                               v_err_desc r     := ' PS_Person  Trait Data  not avail able for t he followi ng VPID/Pe rson Trait  Id: ' ||  to_char(v_ ps_vpid_re cs.ps_pers onvpid_id)  || '/' ||  to_char(v _person_tr ait_id);
  556  
  557                                               v_Primary_ Key_Value  := to_char ( v_person _trait_id)  ;
  558  
  559                    -- C all to Ins ert record  into Erro r Messages  table
  560  
  561                                               Ins_Error_ Messages_S P(
  562                                                       v_ Process_Na me,
  563                                                       v_ Primary_Ke y_Value,
  564                                                       v_ err_code,
  565                                                       v_ err_msg_te xt,
  566                                                       v_ err_descr
  567                                                       )  ;
  568                                               v_Err_Koun t  :=  v_E rr_Kount +  1 ;
  569  
  570                                      END ;    -- End Per son Trait  Exception
  571  
  572                               WHEN  TOO_MANY_ ROWS THEN
  573                                      BEGIN
  574                                               v_err_code       := S QLCODE ;
  575                                               v_err_msg_ text  := s ubstr(SQLE RRM,1,64)  ;
  576                                               v_err_desc r     := ' PS_Person  Trait Data  (Too Many  Rows) for  the follo wing VPID/ Person Tra it Id: ' | | to_char( v_ps_vpid_ recs.ps_pe rsonvpid_i d) || '/'  || to_char (v_person_ trait_id);
  577  
  578                                               v_Primary_ Key_Value  := to_char ( v_person _trait_id)  ;
  579  
  580                             -- Cal l to Inser t record i nto Error  Messages t able
  581  
  582                                               Ins_Error_ Messages_S P(
  583                                                       v_ Process_Na me,
  584                                                       v_ Primary_Ke y_Value,
  585                                                       v_ err_code,
  586                                                       v_ err_msg_te xt,
  587                                                       v_ err_descr
  588                                                       )  ;
  589                                               v_Err_Koun t  :=  v_E rr_Kount +  1 ;
  590  
  591                                      END ;    -- End Per son Trait  Exception
  592  
  593                             END ;    -- End P erson Trai t PL/SQL B lock
  594  
  595   -----   St ep 3: Fetc h name inf ormation b ased on Pe rson Trait  Id for ea ch veteran  Primary T rait Ident ifier deri ved in ste p 2
  596  
  597  
  598                             BEGIN             -- Begin P erson Name  PL/SQL Bl ock
  599  
  600  
  601                               SELE CT
  602                                      pnh.Last _Name,
  603                                      pnh.Midd le_Name,
  604                                      pnh.Firs t_Name,
  605                                      pnh.Pref ix,
  606                                      pnh.Suff ix
  607                                 IN TO
  608                                      v_Last_N ame,
  609                                      v_Middle _Name,
  610                                      v_First_ Name,
  611                                      v_Prefix ,
  612                                      v_Suffix
  613                                 FR OM
  614                                      PS_Perso n_Name pn,
  615                                      PS_Perso n_Name_His tory pnh
  616                                WHE RE
  617                                        pn.Per son_Trait_ Id    =  v _Person_Tr ait_Id
  618                                  A ND  (( pnh .owner_Id        = pn .PS_Person _Name_Id )
  619                                  A ND  (pnh.i s_active_F lag   = p_ Active_Fla g )
  620                                  A ND  (pnh.N ame_type_I d     = p_ Name_Type  )) ;
  621  
  622                             EXCEPT ION                --  Begin Per son Name E xception
  623                               WHEN  NO_DATA_F OUND THEN
  624                                      BEGIN
  625                                               v_err_code       := S QLCODE ;
  626                                               v_err_msg_ text  := s ubstr(SQLE RRM,1,64)  ;
  627                                               v_err_desc r     := ' PS_Person  Name Data  not availa ble for th e followin g VPID/Per son Trait  Id: ' || t o_char( v_ ps_vpid_re cs.ps_pers onvpid_id)  || '/' ||  to_char(v _person_tr ait_id);
  628  
  629                                               v_Primary_ Key_Value      := to_ char( v_pe rson_trait _id) ;
  630  
  631                                      -- Call  to Insert  record int o Error Me ssages tab le
  632  
  633                                               Ins_Error_ Messages_S P(
  634                                                       v_ Process_Na me,
  635                                                       v_ Primary_Ke y_Value,
  636                                                       v_ err_code,
  637                                                       v_ err_msg_te xt,
  638                                                       v_ err_descr
  639                                                       )  ;
  640                                               v_Err_Koun t  :=  v_E rr_Kount +  1 ;
  641  
  642                                      END ;    -- End Per son Name E xception
  643  
  644                               WHEN  TOO_MANY_ ROWS THEN
  645                                      BEGIN
  646                                               v_err_code       := S QLCODE ;
  647                                               v_err_msg_ text  := s ubstr(SQLE RRM,1,64)  ;
  648                                               v_err_desc r     := ' PS_Person  Name Data  (Too Many  Rows) for  the follow ing VPID/P erson Trai t Id: ' ||  to_char(v _ps_vpid_r ecs.ps_per sonvpid_id ) || '/' | | to_char( v_person_t rait_id);
  649  
  650                                               v_Primary_ Key_Value      := to_ char( v_pe rson_trait _id) ;
  651  
  652                                      -- Call  to Insert  record int o Error Me ssages tab le
  653  
  654                                               Ins_Error_ Messages_S P(
  655                                                       v_ Process_Na me,
  656                                                       v_ Primary_Ke y_Value,
  657                                                       v_ err_code,
  658                                                       v_ err_msg_te xt,
  659                                                       v_ err_descr
  660                                                       )  ;
  661                                               v_Err_Koun t  :=  v_E rr_Kount +  1 ;
  662  
  663                                      END ;    -- End Per son Name E xception
  664  
  665                             END ;    -- End P erson Name  PL/SQL Bl ock
  666  
  667   -----   St ep 4: Fetc h SSN info rmation ba sed on Per son Trait  Id for eac h veteran  derived in  step2
  668  
  669  
  670                             BEGIN                     --  Begin Per son SSN PL /SQL Block
  671  
  672  
  673                                      SELECT
  674                                               ssn.Person _Trait_Id,
  675                                               ssnh.SSN_V alue,
  676                                               ssnt.code,
  677                                               ssnr.code,
  678                                               vs.code,
  679                                               ssnh.SSA_S ENT_Date,
  680                                               ssnh.SSA_R eceived_Da te,
  681                                               ssnh.SSA_V erified_Da te,
  682                                               ssc.code
  683                                      INTO
  684                                               v_Person_T rait_Id,
  685                                               v_SSN_Valu e,
  686                                               v_ssn_type _code,
  687                                               v_pseudoss nreason_co de,
  688                                               v_ssnverif icationsta tus_code,
  689                                               v_ssa_sent _date,
  690                                               v_ssa_rece ived_date,
  691                                               v_ssa_veri fied_date,
  692                                               v_ssaverif code_code
  693                                      FROM
  694                                               ps_ssn  ss n,
  695                                               ps_ssn_his tory ssnh,
  696                                               std_ssntyp e ssnt,
  697                                               std_pseudo ssnreason  ssnr,
  698                                               std_ssnver ifications tatus vs,
  699                                               std_ssaver ifcode ssc
  700                                      WHERE
  701                                               ssn.person _trait_id    = v_pers on_trait_i d
  702                                        AND    (( ssnh.ow ner_id         = ssn. ps_ssn_id  )
  703                                        AND    ( ssnh.is_ active_fla g   = p_Ac tive_Flag  ))
  704                                        AND    ssnt.ID(+)                = ssnh .STD_SSNTy pe_ID
  705                                        AND    ssnr.ID(+)                = ssnh .STD_Pseud oSSNReason _ID
  706                                        AND    vs.id(+)                  = ssnh .STD_SSNVe rification Status_ID
  707                                        AND    ssc.id(+)                 = ssnh .std_ssave rifcode_id ;
  708  
  709                             EXCEPT ION                         -- B egin Perso n SSN Exce ption
  710                               WHEN  NO_DATA_F OUND THEN
  711                                      BEGIN
  712                                               v_err_code       := S QLCODE ;
  713                                               v_err_msg_ text  := s ubstr(SQLE RRM,1,64)  ;
  714                                               v_err_desc r     := ' PS_SSN Dat a not avai lable for  the follow ing VPID/P erson Trai t Id: ' ||  to_char(  v_ps_vpid_ recs.ps_pe rsonvpid_i d) || '/'  || to_char (v_person_ trait_id);
  715  
  716                                               v_Primary_ Key_Value      := to_ char( v_pe rson_trait _id) ;
  717  
  718                             -- Cal l to Inser t record i nto Error  Messages t able
  719  
  720                                               Ins_Error_ Messages_S P(
  721                                                       v_ Process_Na me,
  722                                                       v_ Primary_Ke y_Value,
  723                                                       v_ err_code,
  724                                                       v_ err_msg_te xt,
  725                                                       v_ err_descr
  726                                                       )  ;
  727                                               v_Err_Koun t  :=  v_E rr_Kount +  1 ;
  728  
  729                                      END ;    -- End Per son SSN Ex ception
  730  
  731                               WHEN  TOO_MANY_ ROWS THEN
  732                                      BEGIN
  733                                               v_err_code       := S QLCODE ;
  734                                               v_err_msg_ text  := s ubstr(SQLE RRM,1,64)  ;
  735                                               v_err_desc r     := ' PS_SSN (To o Many Row s) for the  following  VPID/Pers on Trait I d: ' || to _char( v_p s_vpid_rec s.ps_perso nvpid_id)  || '/' ||  to_char(v_ person_tra it_id);
  736  
  737                                               v_Primary_ Key_Value      := to_ char( v_pe rson_trait _id) ;
  738  
  739                             -- Cal l to Inser t record i nto Error  Messages t able
  740  
  741                                               Ins_Error_ Messages_S P(
  742                                                       v_ Process_Na me,
  743                                                       v_ Primary_Ke y_Value,
  744                                                       v_ err_code,
  745                                                       v_ err_msg_te xt,
  746                                                       v_ err_descr
  747                                                       )  ;
  748                                               v_Err_Koun t  :=  v_E rr_Kount +  1 ;
  749  
  750                                      END ;    -- End Per son SSN Ex ception
  751  
  752  
  753                             END ;    -- End P erson SSN  PL/SQL Blo ck
  754  
  755   -----   St ep 5: Inse rt Record  into RPT_P SIM_TRAITS  table
  756  
  757                             IF v_p s_vpid_rec s.identity _transacti on_type =  'A'
  758                               THEN
  759                                      BEGIN
  760                                               INSERT INT O RPT_PSIM _TRAITS
  761                                                  (VPID_I D,             VPID_V alue,              La st_Name,
  762                                                   First_ Name,          Middle _Name,             Pr efix,
  763                                                   Suffix ,              SSN,                      SS N_TYPE_COD E,
  764                                                   PSEUDO _SSN_REASO N_CODE,                       SS N_VRFN_STA TUS_CODE,
  765                                                   SSA_Se nt_Date,       SSA_Re ceived_Dat e,      SS A_Verified _Date,
  766                                                   GENDER _CODE,         Date_o f_Birth,           RE CORD_CREAT ED_BY,
  767                                                   RECORD _CREATED_D ATE,                          ss averifcode _code
  768                                                  )
  769                                                 VALUES
  770                                                  (
  771                                                   v_ps_v pid_recs.p s_personvp id_id,             v_ ps_vpid_re cs.VPID_VA LUE,
  772                                                   v_Last _Name,         v_Firs t_Name,            v_ Middle_Nam e,
  773                                                   v_Pref ix,            v_Suff ix,                v_ SSN_Value,
  774                                                   v_ssn_ type_code,     v_pseu dossnreaso n_code, v_ ssnverific ationstatu s_code,
  775                                                   v_SSA_ SENT_Date,     v_SSA_ Received_D ate,    v_ SSA_Verifi ed_Date,
  776                                                   v_Gend er_Code,       v_Date _of_Birth,         'A DR_PSIM_IP ROCCESS',
  777                                                   sysdat e,             v_ssav erifcode_c ode
  778                                                  );
  779  
  780                                               v_Ins_Koun t := v_Ins _Kount + 1  ;
  781                                               v_Commit_K ount := v_ Commit_Kou nt + 1 ;
  782  
  783                                      EXCEPTIO N                -- i nsert repo rt table
  784  
  785                                               WHEN pk_vi olation th en
  786                                               BEGIN
  787                                                       v_ err_code                := SQLCO DE ;
  788                                                       v_ err_msg_te xt           := subst r(SQLERRM, 1,64) ;
  789                                                       v_ err_descr               := ' Mai n Exceptio n Error (R eport tabl e PK viola tion on in sert) for  the follow ing VPID/P erson Trai t Id: ' ||  to_char(  v_ps_vpid_ recs.ps_pe rsonvpid_i d) || '/'  || to_char (v_person_ trait_id);
  790  
  791                                                       v_ Primary_Ke y_Value      := to_ch ar( v_ps_v pid_recs.p s_personvp id_id) ;
  792  
  793                                                       pk _viol_flag              := 'x';
  794  
  795                                                       In s_Error_Me ssages_SP                     --  Call to I nsert reco rd into Er ror Messag es table
  796                                                       (
  797                                                          v_Process_ Name,
  798                                                          v_Primary_ Key_Value,
  799                                                          v_err_code ,
  800                                                          v_err_msg_ text,
  801                                                          v_err_desc r
  802                                                       )  ;
  803  
  804                                                       v_ Process_En d_Date       :=  sysd ate  ;
  805                                                       IF  v_Ins_Kou nt = 0 THE N
  806                                                                v_Pr ocess_Stat us_Code :=  'NO Recor ds process ed';
  807                                                       EN D IF;
  808  
  809                                                       In s_Process_ Log_SP
  810                                                       (
  811                                                          v_Process_ Name,
  812                                                          v_Process_ Start_Date ,
  813                                                          v_Process_ End_Date,
  814                                                          v_Process_ Status_Cod e,
  815                                                          v_Ins_Koun t,
  816                                                          v_Err_Koun t
  817                                                       )  ;
  818  
  819                                               END ;
  820  
  821                                      END ;
  822  
  823                             END IF ;
  824  
  825   -----           Check  for PK vi olation an d fix acco rdingly
  826                             IF pk_ viol_flag  = 'x'
  827                               THEN
  828                                      BEGIN
  829                                               update ps_ person_vpi d
  830                                                 set IDEN TITY_TRANS ACTION_TYP E = 'M',
  831                                                     IDEN TITY_UPDAT E_EVENT_DA TE = trunc (sysdate)
  832                                                where ps_ personvpid _id = v_ps _vpid_recs .ps_person vpid_id;
  833  
  834                                               v_Commit_K ount  := v _Commit_Ko unt + 1 ;
  835                                               pk_viol_fl ag    := ' ';
  836  
  837                                      EXCEPTIO N
  838  
  839                                        WHEN N O_DATA_FOU ND THEN
  840                                               BEGIN
  841                                               v_err_code       := S QLCODE ;
  842                                               v_err_msg_ text  := s ubstr(SQLE RRM,1,64)  ;
  843                                               v_err_desc r     := ' Update of  Person_VPI D failed f or the fol lowing VPI D/Person T rait Id: '  || to_cha r( v_ps_vp id_recs.ps _personvpi d_id) || ' /' || to_c har(v_pers on_trait_i d);
  844  
  845                                               v_Primary_ Key_Value      := to_ char( v_pe rson_trait _id) ;
  846  
  847                                               -- Call to  Insert re cord into  Error Mess ages table
  848  
  849                                               Ins_Error_ Messages_S P(
  850                                                       v_ Process_Na me,
  851                                                       v_ Primary_Ke y_Value,
  852                                                       v_ err_code,
  853                                                       v_ err_msg_te xt,
  854                                                       v_ err_descr
  855                                                       )  ;
  856                                               v_Err_Koun t  :=  v_E rr_Kount +  1 ;
  857  
  858                                               END ;   --  End Perso n SSN Exce ption
  859  
  860                                      END ;
  861  
  862                             END IF ;
  863  
  864                             IF v_C ommit_Koun t = 25000  THEN
  865                               COMM IT;
  866                               v_Co mmit_Kount  := 0 ;
  867                             END IF ;
  868  
  869                      EN D LOOP;
  870                      CL OSE c_ps_v pid_recs;
  871  
  872                      --  Call to I nsert reco rd into Pr ocess Log  table
  873  
  874                      v_ Process_En d_Date     :=  sysdat e  ;
  875                      IF  v_Ins_Kou nt = 0 THE N
  876                             v_Proc ess_Status _Code := ' NO Records  processed ';
  877                      EN D IF;
  878  
  879                      In s_Process_ Log_SP
  880                               (
  881                                v_P rocess_Nam e,
  882                                v_P rocess_Sta rt_Date,
  883                                v_P rocess_End _Date,
  884                                v_P rocess_Sta tus_Code,
  885                                v_I ns_Kount,
  886                                v_E rr_Kount
  887                               ) ;
  888  
  889                      CO MMIT;
  890  
  891                      EX CEPTION               -- Main SP : Raise Ex ception
  892  
  893                      WH EN NO_DATA _FOUND the n
  894                             BEGIN
  895                                      v_err_co de               := S QLCODE ;
  896                                      v_err_ms g_text           := s ubstr(SQLE RRM,1,64)  ;
  897                                      v_err_de scr              := '  Main Exce ption Erro r (No Data  Found) fo r the foll owing VPID /Person Tr ait Id: '  || to_char ( v_ps_vpi d_recs.ps_ personvpid _id) || '/ ' || to_ch ar(v_perso n_trait_id );
  898  
  899                                      v_Primar y_Key_Valu e     := t o_char( v_ ps_vpid_re cs.ps_pers onvpid_id)  ;
  900  
  901                                      Ins_Erro r_Messages _SP                     -- Call  to Insert  record int o Error Me ssages tab le
  902                                               (
  903                                                 v_Proces s_Name,
  904                                                 v_Primar y_Key_Valu e,
  905                                                 v_err_co de,
  906                                                 v_err_ms g_text,
  907                                                 v_err_de scr
  908                                               ) ;
  909  
  910                                      v_Proces s_End_Date       :=   sysdate  ;
  911                                      IF v_Ins _Kount = 0  THEN
  912                                               v_Process_ Status_Cod e := 'NO R ecords pro cessed';
  913                                      END IF;
  914  
  915                                      Ins_Proc ess_Log_SP
  916                                               (
  917                                                 v_Proces s_Name,
  918                                                 v_Proces s_Start_Da te,
  919                                                 v_Proces s_End_Date ,
  920                                                 v_Proces s_Status_C ode,
  921                                                 v_Ins_Ko unt,
  922                                                 v_Err_Ko unt
  923                                               ) ;
  924  
  925                             END ;
  926  
  927                      WH EN OTHERS  then
  928                             BEGIN
  929                                      v_err_co de      :=  SQLCODE ;
  930                                      v_err_ms g_text  :=  substr(SQ LERRM,1,64 ) ;
  931                                      v_err_de scr     :=  ' Main Ex ception Er ror (Other s) for the  following  VPID/Pers onTrait Id : ' || to_ char( v_ps _vpid_recs .ps_person vpid_id) | | '/' || t o_char(v_p erson_trai t_id);
  932  
  933                                      v_Primar y_Key_Valu e     := t o_char( v_ ps_vpid_re cs.ps_pers onvpid_id)  ;
  934  
  935                                      Ins_Erro r_Messages _SP                     -- Call  to Insert  record int o Error Me ssages tab le
  936                                               (
  937                                                 v_Proces s_Name,
  938                                                 v_Primar y_Key_Valu e,
  939                                                 v_err_co de,
  940                                                 v_err_ms g_text,
  941                                                 v_err_de scr
  942                                               ) ;
  943  
  944                                      v_Proces s_End_Date       :=   sysdate  ;
  945  
  946                                      IF v_Ins _Kount = 0  THEN
  947                                               v_Process_ Status_Cod e := 'NO R ecords pro cessed';
  948                                      END IF;
  949  
  950                                      Ins_Proc ess_Log_SP
  951                                               (
  952                                                  v_Proce ss_Name,
  953                                                  v_Proce ss_Start_D ate,
  954                                                  v_Proce ss_End_Dat e,
  955                                                  v_Proce ss_Status_ Code,
  956                                                  v_Ins_K ount,
  957                                                  v_Err_K ount
  958                                               ) ;
  959  
  960                    END  ;  --  Clo sing END t o EXCEPTIO N OTHERS B EGIN
  961           EN D;    -- P rocedure B ody End
  962  
  963   END InitLo ad_PSIM_Tr aits_SP ;  -- Main SP  End (Init Load_PSIM_ Traits_SP)
  964   /
  965  
  966   GRANT EXEC UTE ON PSI M.INITLOAD _PSIM_TRAI TS_SP TO P SIM_R;
  967  
  968   GRANT EXEC UTE ON PSI M.INITLOAD _PSIM_TRAI TS_SP TO P SIM_RW;
  969   DROP PROCE DURE PSIM. BATCH_TAB_ PRIVS;
  970  
  971   CREATE OR  REPLACE PR OCEDURE PS IM.BATCH_T AB_PRIVS
  972    (GRANTEE  STRING
  973    ,TAB_NAME _PAT STRIN G := '%'
  974    ,SELECT_P RIV BOOLEA N := TRUE
  975    ,REFERENC ES_PRIV BO OLEAN := T RUE
  976    ,UPDATE_P RIV BOOLEA N := FALSE
  977    ,INSERT_P RIV BOOLEA N := FALSE
  978    ,DELETE_P RIV BOOLEA N := FALSE
  979    )
  980    IS
  981  
  982       priv_n ot_granted  EXCEPTION ;
  983       PRAGMA  EXCEPTION _INIT(priv _not_grant ed, -1927) ;
  984  
  985       CURSOR  matching_ tables IS  SELECT tab le_name FR OM user_ta bles WHERE  table_nam e LIKE UPP ER(tab_nam e_pat);
  986  
  987       schema _owner  ST RING(30);
  988   BEGIN
  989       DBMS_O UTPUT.ENAB LE(1000000 );
  990  
  991       -- Val idate the  grantee na me
  992       SELECT  username                 -- Loo k for the  grantee in  the all_u sers view
  993         INTO  schema_ow ner
  994         FROM  all_users
  995        WHERE  username  = UPPER(gr antee);
  996  
  997       -- Exe cute GRANT /REVOKE fo r
  998  
  999       FOR th is_table I N matching _tables LO OP
  1000          BEG IN
  1001               IF select _priv THEN
  1002                  EXECUT E IMMEDIAT E 'GRANT S ELECT ON '  || this_t able.table _name || '  TO ' || U PPER(grant ee);
  1003               ELSE
  1004                  EXECUT E IMMEDIAT E 'REVOKE  SELECT ON  ' || this_ table.tabl e_name ||  ' FROM ' | | UPPER(gr antee);
  1005               END IF;
  1006          EXC EPTION
  1007               WHEN priv _not_grant ed THEN
  1008                   NULL;
  1009          END ;
  1010          BEG IN
  1011               IF refere nces_priv  THEN
  1012                  EXECUT E IMMEDIAT E 'GRANT R EFERENCES  ON ' || th is_table.t able_name  || ' TO '  || UPPER(g rantee);
  1013               ELSE
  1014                  EXECUT E IMMEDIAT E 'REVOKE  REFERENCES  ON ' || t his_table. table_name  || ' FROM  ' || UPPE R(grantee)  ||
  1015                                      ' CASCAD E CONSTRAI NTS';
  1016               END IF;
  1017          EXC EPTION
  1018               WHEN priv _not_grant ed THEN
  1019                   NULL;
  1020          END ;
  1021          BEG IN
  1022               IF update _priv THEN
  1023                  EXECUT E IMMEDIAT E 'GRANT U PDATE ON '  || this_t able.table _name || '  TO ' || U PPER(grant ee);
  1024               ELSE
  1025                  EXECUT E IMMEDIAT E 'REVOKE  UPDATE ON  ' || this_ table.tabl e_name ||  ' FROM ' | | UPPER(gr antee);
  1026               END IF;
  1027          EXC EPTION
  1028               WHEN priv _not_grant ed THEN
  1029                   NULL;
  1030          END ;
  1031          BEG IN
  1032               IF insert _priv THEN
  1033                  EXECUT E IMMEDIAT E 'GRANT I NSERT ON '  || this_t able.table _name || '  TO ' || U PPER(grant ee);
  1034               ELSE
  1035                  EXECUT E IMMEDIAT E 'REVOKE  INSERT ON  ' || this_ table.tabl e_name ||  ' FROM ' | | UPPER(gr antee);
  1036               END IF;
  1037          EXC EPTION
  1038               WHEN priv _not_grant ed THEN
  1039                   NULL;
  1040          END ;
  1041          BEG IN
  1042               IF delete _priv THEN
  1043                  EXECUT E IMMEDIAT E 'GRANT D ELETE ON '  || this_t able.table _name || '  TO ' || U PPER(grant ee);
  1044               ELSE
  1045                  EXECUT E IMMEDIAT E 'REVOKE  DELETE ON  ' || this_ table.tabl e_name ||  ' FROM ' | | UPPER(gr antee);
  1046               END IF;
  1047          EXC EPTION
  1048               WHEN priv _not_grant ed THEN
  1049                   NULL;
  1050          END ;
  1051          DBM S_OUTPUT.P UT_LINE('P rivileges  updated on  ' ||this_ table.tabl e_name ||  ' for ' ||  UPPER(gra ntee) ||'. ');
  1052       END LO OP;
  1053  
  1054   EXCEPTION
  1055       WHEN n o_data_fou nd THEN
  1056           DB MS_OUTPUT. PUT_LINE(' Grantee: '  || UPPER( grantee) | | ' is not  a valid u ser on thi s database .');
  1057  
  1058       WHEN o thers THEN
  1059           DB MS_OUTPUT. PUT_LINE(S QLERRM);
  1060  
  1061   END;
  1062   /
  1063  
  1064   GRANT EXEC UTE ON PSI M.BATCH_TA B_PRIVS TO  PSIM_R;
  1065  
  1066   GRANT EXEC UTE ON PSI M.BATCH_TA B_PRIVS TO  PSIM_RW;
  1067   DROP PROCE DURE PSIM. BATCH_SEQ_ PRIVS;
  1068  
  1069   CREATE OR  REPLACE PR OCEDURE PS IM.BATCH_S EQ_PRIVS
  1070    (GRANTEE  STRING
  1071    ,SEQ_NAME _PAT STRIN G := '%'
  1072    ,SELECT_P RIV BOOLEA N := TRUE
  1073    )
  1074    IS
  1075  
  1076       priv_n ot_granted  EXCEPTION ;
  1077       PRAGMA  EXCEPTION _INIT(priv _not_grant ed, -1927) ;
  1078  
  1079       CURSOR  matching_ sequences  IS SELECT  sequence_n ame FROM u ser_sequen ces WHERE  sequence_n ame LIKE U PPER(seq_n ame_pat);
  1080  
  1081       schema _owner  ST RING(30);
  1082   BEGIN
  1083       DBMS_O UTPUT.ENAB LE(1000000 );
  1084  
  1085       -- Val idate the  grantee na me
  1086       SELECT  username                 -- Loo k for the  grantee in  the all_u sers view
  1087         INTO  schema_ow ner
  1088         FROM  all_users
  1089        WHERE  username  = UPPER(gr antee);
  1090  
  1091       -- Exe cute GRANT /REVOKE fo r
  1092  
  1093       FOR th is_sequenc e IN match ing_sequen ces LOOP
  1094          BEG IN
  1095               IF select _priv THEN
  1096                  EXECUT E IMMEDIAT E 'GRANT S ELECT ON '  || this_s equence.se quence_nam e || ' TO  ' || UPPER (grantee);
  1097               ELSE
  1098                  EXECUT E IMMEDIAT E 'REVOKE  SELECT ON  ' || this_ sequence.s equence_na me || ' FR OM ' || UP PER(grante e);
  1099               END IF;
  1100          EXC EPTION
  1101               WHEN priv _not_grant ed THEN
  1102                   NULL;
  1103          END ;
  1104          DBM S_OUTPUT.P UT_LINE('P rivileges  updated on  ' ||this_ sequence.s equence_na me || ' fo r ' || UPP ER(grantee ) ||'.');
  1105       END LO OP;
  1106  
  1107   EXCEPTION
  1108       WHEN n o_data_fou nd THEN
  1109           DB MS_OUTPUT. PUT_LINE(' Grantee: '  || UPPER( grantee) | | ' is not  a valid u ser on thi s database .');
  1110  
  1111       WHEN o thers THEN
  1112           DB MS_OUTPUT. PUT_LINE(S QLERRM);
  1113  
  1114   END;
  1115   /
  1116  
  1117   GRANT EXEC UTE ON PSI M.BATCH_SE Q_PRIVS TO  PSIM_R;
  1118  
  1119   GRANT EXEC UTE ON PSI M.BATCH_SE Q_PRIVS TO  PSIM_RW;