Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to call Oracle stored procedures with cursors in C #

Shulou Source: shulou.com Published: 2022-06-02 07:38:03 09月11日 Update

How to call Oracle stored procedures with cursors in C #. In order to solve this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Stored procedure

Let's first write a simple stored procedure named sTest in our Oracle database, with one input parameter ps_SaleNo and three output parameters pi_Result,ps_Message,pc_cursor as shown below:

Where the CCurType type is the output cursor variable we defined.

The statement in the blue box above is the dataset of the output cursor. If we extract this sentence and query it separately, we can see the returned result, as shown in the following figure:

Code implementation

We open VS2017 and create a new C# project named TestOraCursor.

1. Quote Oracle.ManagedDataAccess

To call a stored procedure with a cursor, we must reference Oracle.ManagedDataAccess for two reasons:

Clients that do not need to install OracleClient

There is no RefCursor type in the parameter type of the original OracleClient, so it is impossible to call the stored procedure that returns the cursor.

We right-click on the program reference and select the package that manages the NuGet.

Then enter Oracle in the browse to find the Oracle.ManagedDataAccess and download it.

two。 Create a form

Create a new form FrmTest and add a Button and a textbox control to the form, as shown below:

We double-click the button event to write the code

The red box above is the connection setting of the database, and the red box below is the method of executing the stored procedure.

4. Core code

Next, let's take a look at the effect of running.

This is the answer to the question about how to call Oracle stored procedures with cursors in c #. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Tags: Procedures stores cursors code parameters data forms types questions outputs casks names that is databases methods more programs facets help answers Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Linux vpn Docker Shulou Tech Info