Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PLSQL : Modify IN parameters of a procedure

Tags:

plsql

I have procedure like this:

Procedure(var1 IN VARCHAR2, var2 IN VARCHAR2 ... )
---lines of code---

---inside this procedure i want to do the below

var1 := filter(var1); -- filter & assign to the same variable
....
....
--do something with var1

But the problem is am not able to modify a IN parameter to a procedure as its a constant. The only option i can think of is to create/declare a new local variable & assign it the modified IN parameter & use it in the subsequent code. But this is leading to clumsy code as there are nearly 30 IN parameters.So i need to create 30 new variables for each of them.

Need your help to change the IN parameter in a plsql procedure OR any other workaround to the above problem.

Regards Vj

like image 849
Vijay Avatar asked Jul 06 '11 13:07

Vijay


2 Answers

The problem is that you're trying to pass var1 as an OUT param into your filter function, which isn't allowed. The only options you have are:

  • Make it an IN OUT parameter
  • Assign it to a local variable
like image 81
StevieG Avatar answered Jan 02 '23 00:01

StevieG


If you want to modify var1, you will have to change the procedure specification to:

Procedure(var1 IN OUT VARCHAR2 ...

However, you said that there are nearly 30 IN parameters. If the data is related, why not create a custom record type?

-- use CREATE OR REPLACE if at the schema level
CREATE TYPE my_params_type IS RECORD(var1 type, var2 type ...);

Then your procedure...

Procedure(params IN my_params_type) IS
filtered_params my_params_type := params; 
BEGIN
  filterd_params.var1 := filter(params.var1);
  ... 

something like that

like image 27
gyoder Avatar answered Jan 01 '23 22:01

gyoder