Declarations in sql-pl/sql, PL-SQL Programming

Declarations in SQL

Your program stores values in the variables and constants. As the program executes, the value of the variables can change, but the values constants cannot.

 

You can declare the variables and constants in the declarative part of any PL/SQL block, package, or subprogram. The Declarations allocate the storage space for a value, state its datatype, and name the storage location and hence, you can reference it.

 

A couple of examples are shown below:

 

birthday DATE;

emp_count SMALLINT := 0;

The first declaration names a variable of the type DATE. The second declaration names a variable of the type SMALLINT and uses the assignment operator to assign an initial value of zero to the variable.

 

The example next show that the expression following the assignment operator can be arbitrarily complex and can refer to the earlier initialized variables:

 

pi REAL := 3.14159;

radius REAL := 1;

area REAL := pi * radius**2;

 

By default, the variables are initialized to NULL. So, these declarations are equal:

 

birthday DATE;

birthday DATE := NULL;

 

In the declaration of a constant, the keyword CONSTANT should precede the type of the specifier, as the example below shows:

 

credit_limit CONSTANT REAL := 5000.00;

 

This declaration names a constant of the type REAL and assigns an initial value of 5000 to the constant. The constant must be initialized in its declaration. Or else, you get a compilation error whenever the declaration is elaborated. (The procedure of a declaration by the PL/SQL compiler is known as the elaboration.)

Posted Date: 10/3/2012 4:34:09 AM | Location : United States







Related Discussions:- Declarations in sql-pl/sql, Assignment Help, Ask Question on Declarations in sql-pl/sql, Get Answer, Expert's Help, Declarations in sql-pl/sql Discussions

Write discussion on Declarations in sql-pl/sql
Your posts are moderated
Related Questions
Character Types The Character types allow you to store alphanumeric data, represent words and text, and manipulate the character strings. CHAR You use the CHAR dataty

Question: (a) In the context of database security explain how the following database features help to enforce security in the database system: (i) Authorisation (ii) Access

Iteration Schemes The bounds of a loop range can be variables, literals, variables, or expressions but must compute to integers. Below are some of the examples. As you can see t

Description: Demonstrate your knowledge of PL/SQL programming by writing and thoroughly testing triggers and stored procedures associated with an e-commerce application that pr

Example of Using Aggregation on Nested Tables Example: How many students sat each exam WITH C_ER AS (SELECT CourseId, CAST (TABLE (SELECT DISTINCT StudentId, Mark FROM EXAM

Example of Check Constraints Example: Workaround for when subqueries not permitted in CHECK constraints CREATE FUNCTION NO_MORE_THAN_20000_ENROLMENTS ( ) RETURNS BOOLEAN

Quantification in SQL To quantify something, as the theory book has it, is to state its quantity, to say how many of it there are. For example, in Tutorial D the expression CO

Example of WHEN or THEN Constraints A concrete example showing how SQL supports WHEN/THEN constraints CREATE TABLE SAL_HISTORY (EmpNo CHAR (6), Salary INTEGER NOT NULL,

EXECUTE Privilege To call an invoker-rights routine straightforwardly, the users should have the EXECUTE privilege on that routine. By yielding the privilege, you permit a user

THEO R Y OF SPECIAL CREATION - Life originated on the earth due to natural events by the super natural power. The biblical story of creation of world within six days was p