The following lines contain the word 'select', 'insert', 'update' or 'delete':
Select
nvl(max(acb.gen_number),0) + 1
From
pay_za_acb_user_gen_nos acb
Where
acb.user_code = p_code
And acb.payroll_action_id =
(
Select max(sub.payroll_action_id)
From pay_za_acb_user_gen_nos sub
Where sub.user_code = p_code
)
And not exists
(
Select 1
From pay_za_acb_user_gen_nos sub
Where sub.payroll_action_id = p_payroll_action_id
And sub.user_code = p_code
)
Union
Select
acb.gen_number
From
pay_za_acb_user_gen_nos acb
Where
acb.user_code = p_code
And acb.payroll_action_id = p_payroll_action_id;
/* Insert the new gen number into pay_za_acb_user_gen_nos */
Insert into pay_za_acb_user_gen_nos
(
payroll_action_id
,user_code
,gen_number
)
Select
p_payroll_action_id
, p_user_code
, user_gen
From
sys.dual
Where
not exists
(
Select 1
From pay_za_acb_user_gen_nos sub
Where sub.payroll_action_id = p_payroll_action_id
And sub.user_code = p_user_code
);
/* Insert new user generation number */
Insert into pay_za_acb_user_gen_nos
(
payroll_action_id
,user_code
,gen_number
)
Select
p_payroll_action_id
, p_acb_inst_code
, inst_gen
From
sys.dual
Where
not exists
(
Select 1
From pay_za_acb_user_gen_nos sub
Where sub.payroll_action_id = p_payroll_action_id
And sub.user_code = p_acb_inst_code
);
/* Select the next installation gen no from sequence */
Select
pay_za_acb_user_gen_nos_s.nextval into inst_gen
From
sys.dual;