|
-
I will try that, but I think I will eventually run into the same problem of handling a large number of varibales. One thing that I began to do and could not figure out was to, instead of using one large procedure, use several smaller procedures within the same package body, but in order to do this I would need to reference the variables from these smaller procedures from another procedure (that is, declare global variables that can be referenced from anywhere in the package body). But, if I use 2 or more procedures in the same package body, I don't know how to make the variables in one procedure available in other procedures. I think this would solve the problems that I'm having. Can you help me with this?
This is an example of what I need to do:
CREATE OR REPLACE PACKAGE BODY load_employees_p AS
--load employees from DEPT1
PROCEDURE pr_load_dept1 (
v_emp1 OUT dept1.emps%TYPE,
v_emp2 OUT dept1.emps%TYPE)
IS
BEGIN
BEGIN
BEGIN
SELECT emp_name INTO v_emp1 FROM emps
WHERE emp_no=1 and dept=1;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
END;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
BEGIN
BEGIN
SELECT emp_name INTO v_emp2 FROM emps
WHERE emp_no=2 and dept=1;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
END;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
END;
END pr_load_dept1;
--load employees from DEPT2
PROCEDURE pr_load_dept2 (
v_emp3 OUT dept2.emps%TYPE,
v_emp4 OUT dept2.emps%TYPE)
IS
BEGIN
BEGIN
BEGIN
SELECT emp_name INTO v_emp3 FROM emps
WHERE emp_no=1 and dept=2;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
END;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
BEGIN
BEGIN
SELECT emp_name INTO v_emp4 FROM emps
WHERE emp_no=2 and dept=2;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
END;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
END pr_load_dept2;
/*NOW THIS IS THE PART THAT I DON'T KNOW HOW TO DO. IN THE NEXT
PROCEDURE, I NEED TO BE ABLE TO ACCESS v_emp1, v_emp2, v_emp3, and
v_emp4 FROM THE PROCEDURES ABOVE.*/
--Update temp table
PROCEDURE pr_update_temp (
v_week_no OUT week_no.temp%TYPE)
IS
BEGIN
BEGIN
BEGIN
UPDATE temp SET emp_name=v_emp1 WHERE week_no=v_week_no and
emp_no=1; --v_emp1 NEEDS TO BE REFERENCED FROM ANOTHER PROCEDURE
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
END;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
END pr_update_temp;
END load_employees_p;
How can I create this package body so that this last procedure can
use variables from the 1st 2 procedures? I think the way I have it
set up above is that all of the variables can only be accessed
within their own procedures. Thus, it will fail when pr_update_temp attempts to reference v_emp1, which is in pr_load_dept1. How can I make v_emp1... v_emp4 need to be global within the package body?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|