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
Project Description: I want to write some SQL statements. The things I need are between pages 5-7. The only problem is that i want it till tomorrow. Skills required is SQL

Relational Algebra - SQL It describes some operators, that together constitute an algebra that is not only relationally complete but also irreducibly so (very nearly- apart f

Procedural Constraint Enforcement (Triggers) SQL has an alternative method of addressing database integrity, involving event-driven procedural code. The special procedures th

Example of Table Literal - SQL Example: A Table Literal (correct version) VALUES ('S1', 'C1', 'Anne'), ('S1', 'C2', 'Anne'), ('S2', 'C1', 'Boris'), ('S3', 'C3'

Project Description: I want a database for large governmental and private data sets on one country that will be easily extended to other countries in the future. Also, the datab

Advantages of Subprograms The Subprograms give extensibility; that is, tailor the PL/SQL language to suit your requirements. For illustration, if you require a procedure which

Inner Join We have learned how to retrieve data from one table by using SELECT statement. But, as we have learned, normalized relational databases mean the data is spread betw

Manipulating Objects: You can use an object type in the CREATE TABLE statement to indicate the datatype of a column. When the table is created once, you can use the SQL statem

Using a Join on 2 tables, select all columns and all rows from the tables without the use of a Cartesian product. Query: SELECT * FROM EMPLOYEE1 JOIN CONTRACT ON EMPLOYEE

FORALL Statement The FORALL statements instruct the PL/SQL engine to bulk-bind the input collections before sending them to the SQL engine. Though the FORALL statement consists