stored procedure

A stored procedure is a set of Structured Query Language (SQL) statements with an assigned name, which are stored in a relational database management system (RDBMS) as a group, so it can be reused and shared by multiple programs.

Stored procedures can access or modify data in a database, but it is not tied to a specific database or object, which offers a number of advantages.

Benefits of using stored procedures

A stored procedure provides an important layer of security between the user interface and the database. It supports security through data access controls because end users may enter or change data, but do not write procedures. A stored procedure preserves data integrity because information is entered in a consistent manner. It improves productivity because statements in a stored procedure only must be written once.

Stored procedures offer advantages over embedding queries in a graphical user interface (GUI). Since stored procedures are modular, it is easier to troubleshoot when a problem arises in an application. Stored procedures are also tunable, which eliminates the need to modify the GUI source code to improve its performance. It's easier to code stored procedures than to build a query through a GUI.

Use of stored procedures can reduce network traffic between clients and servers, because the commands are executed as a single batch of code. This means only the call to execute the procedure is sent over a network, instead of every single line of code being sent individually.

Stored procedure in SQL

Stored procedures in SQL Server can accept input parameters and return multiple values of output parameters; in SQL Server, stored procedures program statements to perform operations in the database and return a status value to a calling procedure or batch.

User-defined procedures are created in a user-defined database or in all system databases, except for when a read-only (resource database) is used. They are developed in Transact-SQL (T-SQL) or a reference to Microsoft. Temporary procedures are stored in tempdb, and there are two types of temporary procedures: local and global. Local procedures are only visible to the current user connection, while global procedures are visible to any user after they are created. System procedures arrive with SQL Server and are physically stored in an internal, hidden-resource database. They appear in the SYS schema of each system, as well as in a user-defined database.

How to run a stored procedure
How to run a stored procedure

Stored procedure in Oracle

Oracle's database language, PL/SQL, is made up of stored procedures, which build applications within Oracle's database. IT professionals use stored programs in Oracle's database to properly write and test code, and those programs become stored procedures once compiled.

A stored procedure in Oracle follows the basic PL/SQL block structure, which consists of declarative, executable and exception-handling parts.

Stored procedure vs. function

Stored procedures and Functions can be used to accomplish the same task. Both can be custom-defined as part of any application, but functions are designed to send their output to a query or T-SQL statement. Stored procedures are designed to return outputs to the application, while a user-defined function returns table variables and cannot change the server environment or operating system environment.

This was last updated in April 2019

Continue Reading About stored procedure

Dig Deeper on Oracle development languages

Data Management
Business Analytics
Data Center
Content Management