CS-GY 6083: Principles of Database Systems
1.0.0
1.0.0
  • Introduction
  • DBMS Basics
    • Introduction to DBMS
    • Why use a DBMS instead of a File System?
    • Levels of Abstraction
    • Instances and Schemas
  • Data Models
    • Introduction to Data Models
    • Database Languages
    • Database Design
  • DBMS Internals
    • Introduction to DBMS Internals
    • Storage Manager
    • Query Processor
    • Transaction Management
    • Database Users
    • Database Architecture
  • DBMS History
  • Some Popular Database Systems
  • OLTP, OLAP, and Data Mining
  • Databases vs. Information Retrieval
  • The Entity-Relationship Model - Details
    • Introduction
    • Cardinality Constraints
    • ER Diagram Components
    • ER Diagram to Relational Schema
    • Design Issues
  • The Relational Model - Details
    • Relations
    • Keys
    • Relational Query Languages
      • Relational Algebra
      • Relational Calculus
      • Relative Expressive Power
    • Relational Operators
  • SQL
    • Introduction to SQL
    • Domain Types in SQL
    • DDL Commands
      • Creating a Table
      • Alter and Drop
    • DML Commands
      • Basic Query Structure
      • Select
      • From
      • Where
      • Joins
      • Rename
      • String Operations
      • Ordering
      • Set Operations
      • Group By and Having
      • Nested Subqueries
      • Test for Empty Relations
      • Test for Duplicate Tuples
      • Derived Relations
      • With
      • Database Modification
    • Intermediate SQL
      • Joins Revisited
      • Views
      • Transactions
      • Integrity Constraints
      • More SQL Data Types and Schemas
        • Other Features
      • Authorization
    • Advanced SQL
      • Accessing SQL From a Programming Language
        • ODBC and JDBC
        • Embedded SQL
        • PHP
        • Some Security Issues
      • Accessing Metadata
      • Text Operations
        • Like
        • Contains
      • Cursors
      • Functions and Procedures
        • Procedural Constructs
        • External Language Routines
      • Triggers
      • Ranking
      • Windowing
      • OLAP
Powered by GitBook
On this page
  • Compound Statements
  • Loops
  • while
  • repeat
  • for
  • Conditional Constructs
  • Exception Handling

Was this helpful?

  1. SQL
  2. Advanced SQL
  3. Functions and Procedures

Procedural Constructs

Compound Statements

Refers to a set of SQL statements written between begin and end.

Loops

while

declare n integer default 0; 
while n < 10 do 
  set n = n + 1 
end while

repeat

repeat 
 set n = n – 1 
until n = 0 
end repeat

for

Permits iteration over all results of a query.

For example:

declare n integer default 0;
for r as
  select budget from department
  where dept_name = 'Music'
do
  set n = n - r.budget
end for
  • leave is used to exit the loop

  • iterate starts from the next tuple

Conditional Constructs

SQL also supports conditional constructs such as if-then-else and case.

Exception Handling

Example:

declare out_of_classroom_seats condition
declare exit handler for out_of_classroom_seats
begin
...
.. signal out_of_classroom_seats
end

exit is the handler; it causes the block enclosed by begin..end to be exited.

PreviousFunctions and ProceduresNextExternal Language Routines

Last updated 5 years ago

Was this helpful?