I'm trying to write a procedure that uses a cursor in a loop to execute a statement (I am not using it to manipulate data.) When I declare the cursor, I need to assign the cursor based on a parameter meeting a specific condition (of which I have two now, possibly more later). I want to code for an exception, in case an invalid parameter is sent to the procedure. The exception is what I don't know how to code. If the parameter does NOT meet one of the conditions and my cursor is not declared, an error will raise when I try to use the cursor in my loop.
I could write two procedures, but the only thing that changes is the result set for the cursor. I thought of sending the where clause as the parameter, but I prefer not to complicate the code calling the procedure. Also, if I did so, I would still need to code for an invalid where clause being passed.
HELP!
It would seem like I could code a simple IF statement, but I can't find any reference or example for doing so:
PROCEDURE run_process(parameter_in VARCHAR2)
IS
-- Declare cursor variable
IF parameter_in = condition1
THEN
CURSOR company_cur IS
SELECT field
FROM table
WHERE condition1;
ELSIF parameter_in = condition2
THEN
CURSOR company_cur IS
SELECT field
FROM table
WHERE condition2;
ELSE
[This is where I need help!]
END IF;
BEGIN
BEGIN
FOR i IN company_cur
LOOP
<execute statements>
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
RAISE_APPLICATION_ERROR(-20001,'Error message.',True);
END;
END run_process;
Thanks for any help!
I could write two procedures, but the only thing that changes is the result set for the cursor. I thought of sending the where clause as the parameter, but I prefer not to complicate the code calling the procedure. Also, if I did so, I would still need to code for an invalid where clause being passed.
HELP!
It would seem like I could code a simple IF statement, but I can't find any reference or example for doing so:
PROCEDURE run_process(parameter_in VARCHAR2)
IS
-- Declare cursor variable
IF parameter_in = condition1
THEN
CURSOR company_cur IS
SELECT field
FROM table
WHERE condition1;
ELSIF parameter_in = condition2
THEN
CURSOR company_cur IS
SELECT field
FROM table
WHERE condition2;
ELSE
[This is where I need help!]
END IF;
BEGIN
BEGIN
FOR i IN company_cur
LOOP
<execute statements>
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
RAISE_APPLICATION_ERROR(-20001,'Error message.',True);
END;
END run_process;
Thanks for any help!