What I need to do is check if a series of variables in a procedure have value, but the tricky part is that the list of which variables I have to check is in a table. Let me explain further:
We have a table where we keep all the variable names and an indicator for which variable shouldn't be null. This is so we can change in the that table which fields are required without having to change the code.
What we want to implement is something similar to the NAME_IN built-in in forms, where you have something like: v_value := GetValue('v_variable'); and that would assing the value of v_variable to v_value. And afterwards I would just check if v_value is null. This whole thing would be inside a LOOP of a cursor that would get all the variables in the table I mentioned earlier that were marked as required.
So far I've tried with EXECUTE IMMEDIATE to get the variable values assigned dynamically, but that doesn't work because EXECUTE IMMEDIATE runs in it's own scope and so it's not able to "see" the variables in the procedure scope.
The other thing I've tried is PL/SCOPE which allows me to actually see if the variables exists within my scope by supplying the name, but it has no mechanism to get the values of the variables that do exist.
Well, I hope anyone can help me. Help will be greatly appreciated.
Here is an example:
Say I got the following table named tblConfig with two columns: variable_name and required_ind.
variable_name | required_ind
-----------------------------
var1 | Y
var2 | N
var3 | N
Then I would have a procedure called check_variables like this:
PROCEDURE check_variables (
var1 VARCHAR2,
var2 VARCHAR2,
var3 VARCHAR2)
IS
CURSOR c_var_check IS
SELECT variable_name
FROM tblConfig
WHERE required_ind = 'Y';
BEGIN
FOR rec_var IN c_var_check LOOP
... check if rec_var.variable_name is the name of variable that has value ...
END LOOP;
END;
In this fisrt scenario, the loop would have to check if var1 has value. If I changed the values of required_ind for the other variables, they would be checked too.
I've read that article about soft coding... it's a good read, unfortunately in this scenario is not a choice I made as the developer. This is necessary because the table with the required config is managed by the user, not the development team.
check_variablesprocedure, you've declared three variables all namedvar1. I'm assuming you meant to declare parametersvar1,var2, andvar3. Does that mean that you know in advance the number and names of all the possible variables? What if the users added another row totblConfigwith avariable_nameoffoo? Would you then add a new parameter to thecheck_variablesprocedure?