This topic describes how to create and use Oracle stored procedures and functions with dotConnect for Oracle by the help of OracleCommand class.
There are two general ways of executing a stored procedure via OracleCommand.
The first way is to include a procedure invocation into a PL/SQL block and execute this block by putting it into the OracleCommand.CommandText property. In this case, the data returned by the procedure may be at once processed in the same block. If the procedure needs some parameters, they should be added to the OracleCommand.Parameters collection. This method does not differ from the usual command execution, please see Using Parameters article and OracleCommand Class for details.
The second way is to set the OracleCommand.CommandType to System.Data.CommandType.StoredProcedure. In this case, CommandText should be set to the procedure's name. The following sample shows how a DataTable can be filled using the get_all_depts_proc procedure from the previous section:
Setting CommandText to "get_all_depts_func", the very same code fills the data table using the stored function instead of the procedure.
When executing ExecuteReader or ExecuteScalar, and OracleCommand.CommandType is set to System.Data.CommandType.StoredProcedure, by default an additional queries are performed that check whether the procedure is pipelined and, if not, describing the parameters (checking for OUT cursor parameters). This allows you to execute stored procedures after setting just the necessary procedure parameters without bothering to fill the parameters collection completely and correctly, because after getting metadata it will be filled automatically.
However, performing an additional query may be unsuitable, and in some cases may lead to a performance loss. dotConnect for Oracle allows disabling this check with the DescribeStoredProcedure connection string parameter.
If you simply set this connection string parameter to false, OracleCommand executes stored routines without any additional checks. In such case the routine must not be a table-valued function, and all its parameters must be set manually.
If you want to execute a table-valued function without additional checks, you need to set the IsTableValuedFunction property of OracleCommand to true. This allows you to execute table-valued functions without additional checks. Setting this property to true is also the only way to execute non-pipelined table-valued functions. Even if DescribeStoredProcedure is set to true, you must also set IsTableValuedFunction to true to execute a non-pipelined table-valued function.
When you want to disable additional checks just for a single instance of OracleCommand without disabling them for a connection, set both IsTableValuedFunction property (to true or false depending on whether the executed function is table-valued) and ImplicitRefCursors property to false. Setting the IsTableValuedFunction property disables the check whether the the executed function is table-valued, and setting the ImplicitRefCursors property to false disables the check for additional cursor parameters.
Working with Oracle Stored Procedures | Stored Procedures - General Information | Using Package Procedures | Using Stored Procedures in DataSets | Using Table-Valued Functions