Procedures & Functions Flashcards
Different types of Functions
Aggregate Function
Scalar Functions
User Defined Functions (UDF)
Aggregate Function
Returns a single calculated value. Examples: AVG() LAST() SUM() COUNT() MIN() FIRST() MAX()
Scalar Function
Returns a single value based on input. Examples: UCASE() LEN() FORMAT() LCASE() ROUND() MID() NOW()
User Defined Functions
UDF Used for complex processing
Usually Input/Output
Anonymous Block
An unnamed sequence of actions. Since they are not named they are not stored in the DB
Stored Procedure
A named PL/SQL block which performs one or more specific tasks for repeated usage.
Has a header and a body
Header contains name of proc and variables or pram to passed to the proc
Body consists of declaration section, execution section and exception section
PL/SQL Function Stored Function (user or user defined function)
Set of PL/SQL statements call by name
Like a stored procedure but can only return 1 value
User function can be used in an SQL statement
Deterministic Function
Always returns the same result for a specific input value
If you specify DETERMINISTIC improves the performance the second time called with the same parameter. No need to execute again for the result
Package
A schema object that groups logically PL/SQL Types, items, and sub programs. Packages usually have two parts
Specifications (spec)
Body
A body is not always necessary
Package Specification
Interface to your application
Declares the types, variables, constants, exceptions, cursors and sub programs available for use
Procedure and function declaration
Global declaration area
Package Body
Fully defines cursors and sub programs and implements the specifications
Procedure and Function definition and exception handling
Local declaration
Why would you use a Package
Organized code management- easy to locate
Easy (top down design) application design.
Painless implementation changes
Security and maintain ability through private code
New functionality session wide persistence of public variables
Better Performance first time entire package loaded into memory later calls better performance