How do I call a stored procedure with an OUT parameter from MATLAB using the Database Toolbox?
5 ビュー (過去 30 日間)
古いコメントを表示
I am trying to access stored procedures containing OUT parameters from an Oracle database using functions from the Database Toolbox. Is is possible to do this with the Database Toolbox?
採用された回答
MathWorks Support Team
2009 年 6 月 27 日
This feature has been added in the Database Toolbox 3.2 (R2006b). You can use the RUNSTOREDPROCEDURE function. If you are using a previous version, read below for any workarounds.
You can retrieve the output value(s) as follows:
% Get one output.
x = runstoredprocedure(c,'myproc',{2500,'Jones'},{java.sql.Types.NUMERIC})
% Get two outputs.
x = runstoredprocedure(c,'myproc',{2500,'Jones'},{java.sql.Types.NUMERIC java.sql.Types.INTEGER})
% One integer output value.
%returnValue = runstoredprocedure(conn, 'test', {0}, {java.sql.Types.INTEGER})
% Two integer output values.
returnValues = runstoredprocedure(conn, 'test2', {0}, {java.sql.Types.INTEGER java.sql.Types.INTEGER})
To return data from a stored procedure, you will need to issue some commands from the MATLAB other than EXEC and FETCH commands.
The syntax for a stored procedure is:
{?= call <procedure-name>[<arg1>,<arg2>, ...]}
or
{call <procedure-name>[<arg1>,<arg2>, ...]}
The first case deals with a procedure that returns an OUT parameter and the second case shows no OUT parameter.
MATLAB (ODBC) example:
conn = database('source','username','password');
cs = conn.Handle.prepareCall('{?= call <procedure-name>[<arg1>,<arg2>, ...]}');
Assume this stored procedure returns a double
cs.registerOutParameter(2, java.sql.Types.DOUBLE, 3);
cs.executeQuery;
x = cs.getDouble(1);
The above code then returns a double value stored at index value 1 of the output parameters.
For more information about the above code, refer to the JDBC API documentation.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Database Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!