SQL STORED PROCEDURES

SQL Stored Procedures

SQL stored procedures are executed on Teradata Database server space. It is a combination of procedural control statements, SQL statements, and control declarations that provide a procedural interface to Teradata Database.

Using SQL Stored Procedures

Using SQL stored procedures, you can build large and complex database applications. In addition to a set of SQL control statements and condition handling statements, an SQL stored procedure can contain the following: • Multiple input and output parameters. • Local variables and cursors. • SQL DDL, DCL, and DML statements, including dynamic SQL, with a few exceptions. Dynamic SQL is a method of invoking an SQL statement by creating and submitting it at runtime from within a stored procedure. Applications based on SQL stored procedures provide the following benefits. They: • Reduce network traffic in the client-server environment because stored procedures reside and execute on the server. • Allow encapsulation and enforcement of business rules on the server, contributing to improved application maintenance. • Provide better transaction control. • Provide better security. The data access clause of an SQL stored procedure can restrict access to the database. • Provide better security by granting the user access to the procedures rather than to the data tables. • Provide an exception handling mechanism to handle the runtime conditions generated by the web application.• Allow all the SQL and SQL control statements embedded in an SQL stored procedure to be executed by submitting one CALL statement. Nested CALL statements further extend the versatility.

Elements of an SQL Stored Procedure

An SQL stored procedure contains some or all of the following elements.

AnSQL stored procedure contains some or all of the following elements.

This element…

Includes…

SQL control statements Control declarations

nested or non-nested compound statements.

• Condition handlers in DECLARE HANDLER statements for completion and exception conditions. Conditional handlers can be:

  • CONTINUE or EXIT type.
  • Defined for a specific SQLSTATE code, the generic exception condition SQLEXCEPTION, or generic completion conditions NOT FOUND and SQLWARNING.• Cursor declarations in DECLARE CURSOR statements or in FOR iteration statements.

    Cursors can be either updatable or read only type.

    Cursors can also be result set cursors for returning the result of a SELECT statement executed in the stored procedure to the caller or client applications

    • Local variable declarations in DECLARE statements.
    DDL, DCL, DML, and SELECT statements, including dynamic

    SQL statements, with a few exceptions.

    with all supported SQL statements except CALL.

    bracketed and simple comments.
    Note: Nestedbracketedcommentsarenotallowed.

 

Source: Github

Leave a Reply

Your email address will not be published. Required fields are marked *