Citizendia
Your Ad Here

A stored procedure is a subroutine available to applications accessing a relational database system. In Computer science, a subroutine ( function, method, procedure, or subprogram) is a portion of code within a larger A relational database is a Database that groups data using common attributes found in the data set A database management system ( DBMS) is Computer software designed for the purpose of managing Databases DBMSes may use any of a variety of Data models Stored procedures (sometimes called a sproc or SP) are actually stored in the database data dictionary. A Computer Database is a structured collection of records or data that is stored in a computer system A data dictionary, as defined in the IBM Dictionary of Computing is a "centralized repository of information about data such as meaning relationships to other data origin

Typical uses for stored procedures include data validation (integrated into the database) or access control mechanisms. In Computer science, data validation is the process of ensuring that a program operates on clean correct and useful data Access control is the ability to permit or deny the use of a particular resource by a particular entity Furthermore, stored procedures are used to consolidate and centralize logic that was originally implemented in applications. Large or complex processing that might require the execution of several SQL statements is moved into stored procedures and all applications call the procedures only.

Stored procedures are similar to user-defined functions (UDFs). A User-Defined Function, or UDF, is a function provided by the user of a program or environment in a context where the usual assumption is that functions are built The major difference is that UDFs can be used like any other expression within SQL statements, whereas stored procedures must be invoked using the CALL statement

CALL procedure(…)

Stored procedures can return result sets, i. An SQL result set is a set of rows from a Database, as well as meta-information about the query such as the column names and the types and sizes of each column e. the results of a SELECT statement. Such result sets can be processed using cursors by other stored procedures by associating a result set locator, or by applications. In Database packages the term cursor refers to a control structure for the successive traversal (and potential processing of records in a Result Stored procedures may also contain declared variables for processing data and cursors that allow it to loop through multiple rows in a table. The standard Structured Query Language provides IF, WHILE, LOOP, REPEAT, CASE statements, and more. Stored procedures can receive variables, return results or modify variables and return them, depending on how and where the variable is declared.

Contents

Implementation

The exact and correct implementation of stored procedure varies from one database system to another. Most major database vendors support them in some form. Depending on the database system, stored procedures can be implemented in a variety of programming languages, for example SQL, Java, C, or C++. A programming language is an Artificial language that can be used to write programs which control the behavior of a machine particularly a Computer. tags please moot on the talk page first! --> In Computing, C is a general-purpose cross-platform block structured Stored procedures written in non-SQL programming languages may or may not execute SQL statements themselves.

The increasing adoption of stored procedures led to the introduction of procedural elements to the SQL language in the SQL:1999 and SQL:2003 standards in the part SQL/PSM. SQL1999 is the fourth revision of the SQL Database Query language. SQL2003 is the fifth revision of the SQL Database Query language. That made SQL an imperative programming language. In Computer science, imperative programming is a Programming paradigm that describes computation in terms of statements that change a program state Most database systems offer proprietary and vendor-specific extensions, exceeding SQL/PSM. For example, Microsoft SQL Server allows for stored procedures to be written using Transact-SQL; Oracle calls its dialect PL/SQL, DB2 uses SQL/PL , PostgreSQL provides PL/pgSQL and also allows users to define their own function languages such as pl/perl or pl/php, and MySQL supports their own stored procedures that try to adhere closely to the SQL:2003 standard


Example1. Microsoft SQL Server is a Relational database management system (RDBMS produced by Microsoft. Transact-SQL ( T-SQL) is Microsoft 's and Sybase 's proprietary extension to the SQL. Oracle Database (commonly referred to as Oracle RDBMS or simply Oracle) is a Relational database management system (RDBMS produced and marketed by PL/SQL (Procedural Language/Structured Query Language is Oracle Corporation 's proprietary procedural extension to the SQL database language, used DB2 is one of IBM 's families of Relational database management system (RDBMS (or as IBM now calls it data server software products within IBM's broader Information PostgreSQL is an Object-relational database management system (ORDBMS PL/pgSQL (Procedural Language/PostgreSQL Structured Query Language is a procedural language supported by the PostgreSQL RDBMS. MySQL is a Relational database management system (RDBMS which has more than 11 million installations SQL2003 is the fifth revision of the SQL Database Query language.

ed ex1. sql
create or replace procedure myproc(a in number,b in number)as
add number;
begin
add:=a+b;
dbms_output. put_line('The sum is'||add);
end;
/

Calling the procedure:

ed ex2. sql

declare
x number:=&a;
y number:=&b;
begin
myproc(x,y);
end;
/

Now run the proc1 and then run the proc2 like

@proc1. sql

after executing the proc1 myproc will be created.

@proc2. sql

you will get the result.

Features

Pre-compilation of SQL statements

SQL statements implemented as stored procedures in some cases run faster, as they can be pre-compiled. Execution plans for compiled statements can be stored in the database, together with the procedure. This can remove the compilation overhead that is typically required in situations where software applications send inline SQL queries to a database. However, most database systems implement statement caches to avoid repetitive compilation of dynamic SQL statements.

In addition, pre-compiled SQL statements, while avoiding some overhead, add to the complexity of creating an optimal execution plan because not all arguments of the SQL statement are supplied at compile time. Depending on the specific database implementation and configuration, mixed performance results will be seen from stored procedures versus generic queries or user defined functions . .

Execution on a database server

Stored procedures can run directly within the database engine. In a production system, this typically means that the procedures run entirely on a specialized database server, which has direct access to the data being accessed. The benefit here is that network communication costs can be avoided completely. This becomes particularly important for complex series of SQL statements.

However, note that unnecessary or excessive procedural statement execution in the database server (typically a singular shared resource) may impair overall enterprise system performance - i. e. , while application servers can often be dramatically scaled horizontally for increased processing capacity, the same is not generally or as easily accomplished for database servers.

Therefore, a growing school of thought advocates the database be used for what it's best at - i. e. , a very efficient file cabinet. Thereby restricting any database-local procedural executions to only very specific cases rather than the old school ubiquity - instead advocating the use of advanced object oriented domain class ontologies and reusable parameterized SQL generation.

Simplification of data management

Stored procedures allow for business logic to be embedded as an API in the database, which can simplify data management and reduce the need to encode the logic elsewhere in client programs. Business logic is a non-technical term generally used to describe the functional Algorithms which handle Information exchange between a Database and a This may result in a lesser likelihood of data becoming corrupted through the use of faulty client programs. Thus, the database system can ensure data integrity and consistency with the help of stored procedures.

Some critics claim that databases should be for storing data only, and that business logic should only be implemented by writing a business layer of code, through which client applications should access the data. However, the use of stored procedures does not preclude the use of a business layer.

Security

Carefully written stored procedures may allow for fine grained security permissions to be applied to a database. For example, client programs might be restricted from accessing the database via any means except those that are provided by the available stored procedures.

Other uses

In some systems, stored procedures can be used to control transaction management; in others, stored procedures run inside a transaction such that transactions are effectively transparent to them. Stored procedures can also be invoked from a database trigger or a condition handler. A database trigger is Procedural code that is automatically executed in response to certain events on a particular table in a Database. For example, a stored procedure may be triggered by an insert on a specific table, or update of a specific field in a table, and the code inside the stored procedure would be executed. Writing stored procedures as condition handlers also allow DBAs to track errors in the system with greater detail by using stored procedures to catch the errors and record some audit information in the database or an external resource like a file.

References

External links

Dictionary

stored procedure

-noun

  1. (computing) A named program or routine stored in a database.
© 2009 citizendia.org; parts available under the terms of GNU Free Documentation License, from http://en.wikipedia.org
Dapyx Software network: MP3 Explorer | Ebook Manager | Zenithic