Search code examples
plsqlpentahopentaho-spoonpentaho-data-integration

Using custom number of parameters while using Call db procedure step in Pentaho (PDI)


Description:

Recently I've been trying to automatize some tasks at work using Pentaho (PDI), and I've come upon a problem that I had no luck of solving/finding solution for (I did research for many hours, been trying to solve it on my own as well). My aim is to load a text file containing name of the PL/SQL procedure stored on the server, and custom ammount of parameters for the procedure. For example if the source text file would contain following text:

Test_schema.job_pkg.run_job;12345

It should run job_pkg.run_job procedure from the defined connection, and use 12345 as a single parameter.

The problem:

The Call DB procedure transformation step only accepts SET ammount of parameters, for exampe I set the step to accept 4 parameters, but the procedure I'm calling is only accepting 1 parameter. I want to be able to IGNORE other parameters set in the step. When I try to send for example just one parameter but the step is set to accept 4 parameters, it throws:

Call DB Procedure.0 - ORA-06550: row 1, column 7:

PLS-00306: wrong number or types of arguments in call to 'RUN_JOB'

ORA-06550: row 1, column 7: PL/SQL: Statement ignored

What I have so far:

I've made a job that starts the transformation that loads the contents of the source file to memory, splits it to correct fields using Modified Java Script value, sets Pentaho variables with extraced values, then second transformation is loaded, that reads these variables and passes them as fields to Call DB procedure step. The last step always fails unless I manually remove all unused arguments.

My current settings for Call DB Procedure step

Solution:

Based on AlainD's answer I've tried to use the Switch / Case step which solved the problem. Now there is different problem regarding conversion of values. If I pass a number but set it as STRING in Call DB Procedure's parameters, it throws

ORA-01403 no data found

This can be solved by handling the data via Modified Java Script Value step or any other step in order to convert the data into the "correct" format.

Final transformation view


Solution

  • What I do in cases like that is to build a SQL command in a String, something like Test_schema.job_pkg.run_job(12345) and execute it with an Execute SQL script.

    An other workaround would be to cont the number of parameters in the Modified Javascript step, and use a Switch/Case to redirect the flow on a sequence of DB Procedure steps: one with 0 parameter, one with 1 parameter, one with 2 parameters,... This method assume that the max number of parameters is small.