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
Opening a Cursor Opening the cursor executes the query & identifies the result set that consists of all rows that meet the query search criteria. For the cursors declared usin

Table Represents an Extension - SQL It describes how each tuple in a relation represents a true instantiation of some predicate and each true instantiation is represented by s

Find the account numbers of all customers whose balance is more than 10,000 $

Advantages of PL/SQL The PL/SQL is a high-performance transaction processing, completely portable language that offers the following advantages as shown: 1) Support for SQL

COSMOZOI C THEORY - Richter (1865) proposed the cosmozoic theory that says that life came by spores (cosmozoa) or other particles from other planets on the earth.

I would like to have a custom MS Access database designed and coded that would help me schedule my customer's orders and that would help me track my employees production output and

Restriction and AND - SQL Restriction is available via the WHERE operator, and so it is in SQL. However, by Example showing how a certain simple restriction can be expressed u

Advantages of Wrapping   The PL/SQL Wrapper convert the PL/SQL source code into a transitional form of the object code. By hiding the application internals, the Wrapper secure

DBMS: The answer to this question is of course given in of the theory book. This book is concerned with SQL DBMSs and SQL databases in particular. Soon we will be looking a

Enrolment was split - SQL Example shows how relvars IS_CALLED and IS_ENROLLED_ON can be derived from the original ENROLMENT relvar, using projection in the initial assignment