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
Built-In Functions The PL/SQL provides a lot of powerful functions to help you to manipulate the data. These built-in functions fall into the categories as shown below: error r

PL SQL Code Review HEADER ELEMENTS File Name Clear, meaningful and descriptive about main objective of the file. Multiple words are joined using underscores which adh

FETCH Statement The FETCH statement retrieve rows of data one at a time from the result set of the multi-row query. The data is stored in fields or variables which correspond t

Collections:   The collection is an ordered group of elements, all of similar type (for illustration, the grades for a class of students). Each element has an exclusive subsc

Using Savepoints The scope of the savepoint is a transaction in which it is defined. The Savepoints defined in the major transaction are not related to the savepoints defined

SQL Database: So, an SQL database is one whose symbols are organized into a collection of tables. Now, shows an SQL table as the current value of an SQL variable, ENROLMENT, b

Create a Oracle procedure to produce vertical output format when selecting rows from a database table.

Cursor Variables Similar to a cursor, cursor variable points to the current row in the result set of a multi-row query. But, dissimilar a cursor, a cursor variable can be opene

Predicate - SQL Consider the declarative sentence-a proposition-that is used to introduce this topic:  "Student S1, named Anne, is enrolled on course C1." Recall that th

Cursor FOR Loops In most cases that need an explicit cursor, you can simplify the coding by using a cursor FOR loop rather of the OPEN, FETCH, and CLOSE statements. A cursor FO