23.10.2012 Views

Structured Query Language (SQL) - Cultural View of Technology

Structured Query Language (SQL) - Cultural View of Technology

Structured Query Language (SQL) - Cultural View of Technology

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PL/<strong>SQL</strong> 76<br />

BEGIN<br />

[Exception<br />

END;<br />

[declaration block]<br />

<br />

PIPE ROW ;<br />

RETURN;<br />

exception block]<br />

PIPE ROW ;<br />

RETURN;<br />

There are three types <strong>of</strong> parameter: IN, OUT and IN OUT. An IN parameter is used as input only. An IN parameter<br />

is passed by reference and thus cannot be changed by the called program. An OUT parameter is initially NULL. The<br />

program assigns the parameter a value and that value is returned to the calling program. An IN OUT parameter may<br />

or may not have an initial value. That initial value may or may not be modified by the called program. Any changes<br />

made to the parameter are returned to the calling program by default by copying but, with the NOCOPY hint may be<br />

passed by reference.<br />

Procedures<br />

Procedures are similar to Functions, in that they can be executed to perform work. The primary difference is that<br />

procedures cannot be used in a <strong>SQL</strong> statement and although they can have multiple out parameters they do not<br />

"RETURN" a value.<br />

Procedures are traditionally the workhorse <strong>of</strong> the coding world and functions are traditionally the smaller, more<br />

specific pieces <strong>of</strong> code. PL/<strong>SQL</strong> maintains many <strong>of</strong> the distinctions between functions and procedures found in many<br />

general-purpose programming languages, but in addition, functions can be called from <strong>SQL</strong>, while procedures<br />

cannot.<br />

Packages<br />

Packages are groups <strong>of</strong> conceptually linked Functions, Procedures,Variable,PL/<strong>SQL</strong> table and record TYPE<br />

statements,Constants & Cursors etc. The use <strong>of</strong> packages promotes re-use <strong>of</strong> code. Packages usually have two parts,<br />

a specification and a body, although sometimes the body is unnecessary. The specification (spec for short) is the<br />

interface to your applications; it declares the types, variables, constants, exceptions, cursors, and subprograms<br />

available for use. The body fully defines cursors and subprograms, and so implements the spec. They are stored<br />

permanently in USER_SOURCE system table. Advantages 1.Modular approach, Encapsulation/hiding <strong>of</strong> business<br />

logic, security, performance improvement, re-usability.They support OOPS features like function over<br />

loading,encapsulation. 2.Using we can declare session level (scoped) variables. Since variable declared in pack spec<br />

has session scope.<br />

Variables<br />

Numeric variables<br />

variable_name number(P[,S]) := value;<br />

To define a numeric variable, the programmer appends the variable type NUMBER to the name definition. To<br />

specify the (optional) precision(P) and the (optional) scale (S), one can further append these in round brackets,<br />

separated by a comma. ("Precision" in this context refers to the number <strong>of</strong> digits which the variable can hold, "scale"<br />

refers to the number <strong>of</strong> digits which can follow the decimal point.)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!