Common Questions in Oracle
-----------------------------------------------
NOT NECESSARYIMPORTANT1. Difference between procedure, function & package.Procedure:
It is a type of subprogram that performs an action.It can be stored in the database, as a schema object, for repeated execution.Execute as a PL/SQL statementDo not contain RETURN clause in the headerCan return none, one, or many valuesCan contain a RETURN statement
Functions:
It is a named PL/SQL block that returns a value.It can be stored in the database as a schema object for repeated execution.Invoke as part of an expressionMust contain a RETURN clause in the headerMust return a single valueMust contain at least one
Package:
It is a database object that groups logically related PL/SQL types, objects, and subprograms.Packages usually have two parts, a specification and a body, but body is optional.The specification is the interface to the applicationsIt declares the types, variables, constants, exceptions, cursors, and subprograms available for use.The body fully defines cursors and subprograms, and so implements the specification.
Advantages:
Packages offer several advantages:
Modularity:
Each package is easy to understand, and the interfaces between packages are simple,clear, and well defined. This aids application development.
Easier application design:
When designing an application, all we need initially is the interfaceinformation in the package specifications. We can code and compile a specification without itsbody. Once the specification has been compiled, stored subprograms that reference the packagecan be compiled as well. We need not define the package bodies fully until you are ready tocomplete the application.
Information hiding:
With packages, you can specify which types, objects, and subprograms arepublic (visible and accessible) or private (hidden and inaccessible). For example, if a packagecontains four subprograms, three might be public and one private. The package hides thedefinition of the private subprogram so that only the package (not your application) is affected if the definition changes. This simplifies maintenance and enhancement. Also, by hidingimplementation details from users, you protect the integrity of the package.
Added functionality:
Packaged public variables and cursors persist for the duration of a session.So, they can be shared by all subprograms that execute in the environment. Also, they allow youto maintain data across transactions without having to store it in the database.
Better performance:
When you call a packaged subprogram for the first time, the whole packageis loaded into memory. Therefore, subsequent calls to related subprograms in the package requireno disk I/O.
Leave a Comment