Published in: SQL
Just a template...
CREATE OR REPLACE PROCEDURE P_SUMMARY_WSP IS cursor csr_hierarchy IS SELECT parent, child FROM hierarchy_deep ORDER BY parent; answered_no_total number; rec_csr_hierarchy csr_hierarchy%rowtype; BEGIN -- ** preparations execute immediate 'truncate table l_summary_wsp'; -- iterate cursor open csr_hierarchy; loop fetch csr_hierarchy INTO rec_csr_hierarchy; exit when csr_hierarchy%notfound; -- check if we already have an entry for the current person and add -- to that, create otherwise begin SELECT answered_no INTO answered_no_total FROM pp_summary_wsp WHERE person_id = rec_csr_hierarchy.parent; -- check for current subordinate if answered no UPDATE pp_summary_wsp SET answered_no = answered_no_total + 1 WHERE person_id = rec_csr_hierarchy.parent; exception when NO_DATA_FOUND then INSERT INTO pp_summary_wsp (person_id, answered_no) VALUES (rec_csr_hierarchy.parent, 1); end; end loop; -- close cursor IF csr_hierarchy%ISOPEN then close csr_hierarchy; end IF; END P_SUMMARY_WSP;
Comments
Subscribe to comments
- Posted By: indianocean on March 26, 2008
You need to login to post a comment.
