Call stored procedure with input and output parameters


results = runstoredprocedure(conn, sp_name, parms_in, types_out)


results = runstoredprocedure(conn, sp_name, parms_in, types_out) calls a stored procedure with specified input parameters and returns output parameters, for the database connection handle conn . sp_name is the stored procedure to run, parms_in is a cell array containing the input parameters for the stored procedure, and types_out is the list of data types for the output parameters.

Use runstoredprocedure to return the value of a variable to a MATLAB® variable, which you cannot do when running a stored procedure via exec. Running a stored procedure via exec returns resultsets but cannot return output parameters.


These examples illustrate how runstoredprocedure differs from running stored procedures via exec.

  1. Run a stored procedure that has no input or output parameters:

    x = runstoredprocedure(c,'myprocnoparams')
  2. Run a stored procedure given input parameters 2500 and 'Jones' with no output parameters.

    x = runstoredprocedure(c,'myprocinonly',{2500,'Jones'}) 
  3. Run the stored procedure myproc given input parameters 2500 and 'Jones'. Return an output parameter of type java.sql.Types.NUMERIC, which could be any numeric Oracle® Java® data type. The output parameter x is the value of a database variable n. The stored procedure myproc creates this variable, given the input values 2500 and 'Jones'. For example, myproc computes n, the number of days when Jones is 2500. It then returns the value of n to x.

    x = runstoredprocedure(c,'myproc',{2500,'Jones'},{java.sql.Types.NUMERIC})

See Also


Was this topic helpful?