This content has been marked as final. Show 5 replies
Simply you can try..
select sum(emp_rate_1)+sum(emp_rate_2) from employee_t
V_emp_rate_1_ID := 1;
execute immediate 'select SUM(emp_rate_'|| trim(V_emp_rate_1_ID)||' ) from employee_t ' into V_emp_rate_sum;
Try with dynamic sql - Execute immidiate, it will solve your problem.
Requirements are not clear..
What do you want to do after looping?
Post sample data and xpected output
Not clear whether you are trying to get two sums (one for each column) or one sum that totals both columns)
But you can do all three with one query
select SUM(emp_rate_1) as emp_rate_1 from employee_t result $60
select SUM(emp_rate_1) as emp_rate_1, sum(emp_rate_2) as emp_rate_2, sum (emp_rate_1 + emp_rate_2) as sum_both from employee_t