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
Parameter and Keyword Description: select_item: This select_item is a value returned by the SELECT statement, and then assigned to the equivalent variable or field in the

ROWID The ROWID returns the rowid (binary address) of a row in the database table. You can use the variables of the type UROWID to store rowids in a readable format. In the il

BETWEEN Operator The operator BETWEEN, tests whether the value lies in a specified series. That means "greater than or equivalent to low value and less than or equivalent to hig

Deleting Objects You can use the DELETE statement to eradicate objects from an object table. To eradicate objects selectively, you use the WHERE clause, as shown below: BEG

Data Types in SQL - Decimal DECIMAL, NUMERIC, REAL, FLOAT and various other terms for various sets of rational numbers. When these key words are specified for the declared typ

%FOUND Subsequent to a cursor or cursor variable is opened but before the first fetch, the %FOUND yields NULL. Afterward, it yields TRUE when the last fetch returned a row, or

At times, customers make mistakes in submitting their orders and call to cancel the order. Brewbean’s wants to create a trigger that automatically updates the stock level of all pr

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

Stored Subprograms Normally, tools (like Oracle Forms) which incorporate the PL/SQL engine can store subprograms locally for later, strictly local execution. Though, to become

Expressions   An expression is a randomly complex combination of the constants, variables, literals, operators, & function calls. The simplest expression is the single variabl