DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Working With dotConnect for Oracle in ASP.NET Core
  • Why Database Migrations Take Months and How to Speed Them Up
  • Unmasking Entity-Based Data Masking: Best Practices 2025
  • GDPR Compliance With .NET: Securing Data the Right Way

Trending

  • Developers Beware: Slopsquatting and Vibe Coding Can Increase Risk of AI-Powered Attacks
  • Intro to RAG: Foundations of Retrieval Augmented Generation, Part 2
  • Implementing API Design First in .NET for Efficient Development, Testing, and CI/CD
  • How to Merge HTML Documents in Java
  1. DZone
  2. Data Engineering
  3. Data
  4. Working With Stored Procedures Using dotConnect for Oracle

Working With Stored Procedures Using dotConnect for Oracle

The article discusses the striking features of dotConnect for Oracle and shows how to work with stored procedures and dotConnect for Oracle in ASP.NET Core 5.

By 
Joydip Kanjilal user avatar
Joydip Kanjilal
DZone Core CORE ·
Apr. 15, 21 · Opinion
Likes (2)
Comment
Save
Tweet
Share
8.0K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

A stored procedure comprises a set of SQL statements and PL/SQL constructs that are grouped together. Stored procedures, as well as functions, can have input, output as well as input/output parameters. dotConnect for Oracle provides excellent support for working with stored procedures.

It is a fast, scalable ORM for Oracle from Devart that is built on top of ADO.NET and provides you an opportunity to connect to and work with Oracle databases from your .NET or .NET Core applications. You can use this framework in your WinForms, WPF, ASP.NET, and ASP.NET Core applications.

The article talks briefly about the striking features of dotConnect for Oracle and shows how to work with stored procedures and dotConnect for Oracle in ASP.NET Core 5.

Prerequisites

To be able to work with the code examples demonstrated in this article, you should have the following installed in your system:

  • Visual Studio 2019 Community Edition
  • .NET 5
  • Oracle database
  • dotConnect for Oracle

You can download .NET 5.0 runtime from here.

You can download Visual Studio 2019 from here.

You can download Oracle Express Edition from here.

You can download a copy of dotConnect for Oracle from here.

Create a New ASP.NET Core 5.0 Project in Visual Studio 2019

Assuming that the necessary software has been installed in your computer to be able to work with Entity Developer, follow the steps outlined below to create a new ASP.NET Core Web API project.

  • First off, open the Visual Studio 2019 IDE.
  • Next, click "Create a new project" once the IDE has loaded.
  • In the "Create a new project" screen, select “ASP.NET Core Web API” as the project template.

Create a new project with ASP.NET Core Web API highlighted

  • Click the "Next" button.
  • Specify the project name and the location where it should be stored in your system.
  • Optionally, click the "Place solution and project in the same directory" checkbox.
  • Click the "Create" button.
  • In the "Create a new ASP.NET Core Web Application" dialog window that is shown next, select "API" as the project template.
  • In the “Additional Information” screen, select .NET 5.0 as the framework version.

Select .NET 5.0 as target framework

You should disable the "Configure for HTTPS" and "Enable Docker Support" options by disabling the respective checkboxes. Since we'll not be using authentication in this example, specify authentication as "No Authentication." Finally, click on the "Create" button to finish the process.

dotConnect For Oracle: Features and Benefits

Microsoft’s ADO.NET is a managed framework that can be used to connect to and work with several databases. dotConnect for Oracle is a high-performance ORM that sits on top of the ADO.NET data provider and enables you to perform CRUD operations against Oracle databases. It is a managed framework that is high performant and is easy to deploy supports load balancing, batch processing, asynchronous command execution, and data binding. It also supports several Oracle features that include Advanced Queuing, Change Notifications, Alerts, Pipes, Direct Path Loading, etc.

Create a Database Table

The following is the syntax for creating a new table in Oracle. Note how schema name and constraints are specified.

SQL
 




xxxxxxxxxx
1


 
1
CREATE TABLE schema_name.table_name (
2
    column_1 data_type column_constraint,
3
    column_2 data_type column_constraint,
4
    ...
5
    table_constraint
6
 );



The following code snippet can be used to create a new table called product in Oracle.

SQL
 




xxxxxxxxxx
1


 
1
CREATE TABLE product
2
  (
3
    product_id NUMBER PRIMARY KEY,
4
    product_name VARCHAR2(50) NOT NULL,
5
    quantity NUMBER NOT NULL
6
  );


Creating the Stored Procedure

To create a stored procedure in Oracle, use the following piece of code:

SQL
 




xxxxxxxxxx
1


 
1
CREATE PROCEDURE product_insert(pid INTEGER, pname VARCHAR, quantity INTEGER) AS
2
BEGIN
3
  INSERT INTO product(product_id, product_name, quantity) VALUES (pid, pname, qty);
4
END;


Creating OracleConnection

To connect to the Oracle database, you should provide the database credentials. This information is stored inside a connection string. The connection string comprises the server name, user Id, password, etc.

You can create OracleConnection in two different ways, i.e., design time and run time. You can create an OracleConnection at design time from the Toolbox inside the Visual Studio IDE. To create an instance of OracleConnection at run-time, you can use the following code snippet:

C#
 




xxxxxxxxxx
1


 
1
OracleConnection oracleConnection = new OracleConnection();
2
oracleConnection.Server = "DemoXServer";
3
oracleConnection.UserId = "scott";
4
oracleConnection.Password = "tiger";



You should include the following namespace in your program:

C#
 




xxxxxxxxxx
1


 
1
using Devart.Data.Oracle;



Executing a Stored Procedure Using the OracleCommand Class

You can execute an OracleProcedure in the following ways:

  • Using a PL/SQL block and the CommandText property of OracleCommand.
  • By setting the OracleCommand.CommandType property to System.Data.CommandType.StoredProcedure.

The following source code illustrates how you can execute a stored procedure to read data from the database table we've created earlier.

C#
 




xxxxxxxxxx
1


 
1
OracleConnection connection = new OracleConnection("Server=DemoXServer; User Id=scott; Password = tiger;");
2
connection.Open();
3
OracleCommand command = new OracleCommand();
4
command.Connection = connection;
5
command.CommandType = System.Data.CommandType.StoredProcedure;
6
command.CommandText = "getallproducts";
7
command.ParameterCheck = true;
8
OracleDataTable dataTable = new OracleDataTable(command, connection);
9
dataTable.Fill();



Working With Oracle Stored Procedures and DataSets

You can work with Oracle Stored Procedures with DataSets in two ways: using the DataSet Wizard as well as programmatically. If your stored procedure returns a result set, you can use this result set to generate a table in a typed data set.

Assuming you've created a DataSet already, you can use the following code to bind data to your data controller.

C#
 




xxxxxxxxxx
1


 
1
dataSet.Fill();
2
DataTable dataTable = dataSet.Tables[0];
3
dataGridView.DataSource = dataTable;



You can use the DataSet Wizard to update, insert, or delete data.

Working With Table-Valued Functions and dotConnect for Oracle

Table-valued functions in Oracle are functions return collections of rows. These functions return collections and can be queried similar to database tables. The following are the advantages of Table-value functions:

  • Can be used to merge session-specific data from tables.
  • Can be used to emulate a parameterized view.
  • Can be used to improve the performance of parallelized functions.

The following code snippet illustrates how you can work with table-valued functions in Oracle using dotConnect for Oracle to retrieve the top 5 records from the product table in the database.

C#
 




x
22


 
1
using (OracleConnection connection = new OracleConnection("Data Source=DemoXServer; User Id=scott; Password=tiger; DescribeStoredProcedure=false;")) 
2

          
3
 {
4

          
5
    connection.Open();
6
    using (OracleCommand command = 
7
    connection.CreateCommand("get_product_function", 
8
    CommandType.StoredProcedure)) 
9
    {
10

          
11
       command.IsTableValuedFunction = true;
12
       command.Parameters.Add("row_ctr", 5);
13
       List<object[]> data = new List<object[]>();
14

          
15
       using (OracleDataReader reader = cmd.ExecuteReader()) 
16
       {
17

          
18
          while (reader.Read())
19
          data.Add(reader.GetValues());
20
       }
21
    }
22
 }



Summary

Stored procedures are PL/SQL blocks that perform one or more specific tasks that enable you to reuse a set of PL/SQL statements if and when needed. You can know more on dotConnect for Oracle from their online documentation.

Database .NET ASP.NET Core Data (computing)

Opinions expressed by DZone contributors are their own.

Related

  • Working With dotConnect for Oracle in ASP.NET Core
  • Why Database Migrations Take Months and How to Speed Them Up
  • Unmasking Entity-Based Data Masking: Best Practices 2025
  • GDPR Compliance With .NET: Securing Data the Right Way

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!