Requirements: WEBAPI server, access to data through the Oracle database's stored procedures.
To establish a stored procedure in PL/sql: (First and foremost, the entire table is detected)
Create or Replace procedure is begin Open for ' SELECT * from wx_sp ' ; End;
C # code: (This is the method called,Out_return , which corresponds to the cursor parameter in the stored procedure, and the type is oracledbtype.refcursor.) sql_wx_sp is the name of the stored procedure)
PublicDataTable function () {Try{oracleparameter[] par= { NewOracleParameter ("Out_return", Oracledbtype.refcursor)}; par[0]. Direction =ParameterDirection.Output; DataTable result= Dbconnect.getinstance (). Getdatatable ("sql_wx_sp", CommandType.StoredProcedure, par); returnresult; } Catch(Exception ex) {Throwex; } }
C # dbhelper code (no dbhelper directly add the database connection string should also do, is significantly a bit amateur, _connstr This is the database connection string )
Internal DataTable getdatatable (stringparams oracleparameter[] opar) { new DataTable (); using New oracledataadapter (SQL, _CONNSTR)) { DAP. SelectCommand.Parameters.AddRange (Opar); = CommandType; Dap. Fill (DT); } return dt; }
This is a good set, run up, the data is coming (the data type returned here is a DataTable), and then it can be processed.
The code is mainly from: Jory great god, thanks!
Original: http://www.cnblogs.com/jory/p/5362877.html
C # (in Webapi) gets the stored procedure for Oracle (in PL/SQL) cursor type (used with refcursor)