Expression in assignment statement - pl sql, PL-SQL Programming

Expression:

This is a randomly complex combination of constants, variables, literals, operators, & function calls. The simplest expression consists of a single variable. If the assignment statement is executed, the expression is computed and the resulting value is stored in the assignment target. The value and target must have well-suited datatypes.

By default, unless the variable is initialized in its declaration, it is initialized to NULL every time a subprogram or block is entered. Therefore, never reference a variable before you assign it a value. You can't assign nulls to a variable defined as NOT NULL. If you attempt, the PL/SQL raises the predefined exception VALUE_ERROR. The values TRUE, FALSE, & NULL can also be assigned to a Boolean variable. If applied to an expression, the relational operators return a Boolean value. And hence, the assignment below is legal:

DECLARE

out_of_range BOOLEAN;

...

BEGIN

...

out_of_range := (salary < minimum) OR (salary > maximum);

As the later illustration shows, you can assign the value of an expression to an  explicit field in a record:

DECLARE

emp_rec emp%ROWTYPE;

BEGIN

...

emp_rec.sal := current_salary + increase;

Furthermore, you can assign values to all the fields in a record at once. The PL/SQL permits an aggregate assignment between the whole records if their declarations refer to similar cursor or table. For illustration, the assignment below is legal:

DECLARE

emp_rec1 emp%ROWTYPE;

emp_rec2 emp%ROWTYPE;

dept_rec dept%ROWTYPE;

BEGIN

...

emp_rec1 := emp_rec2;

The later assignment is illegal as you cannot use the assignment operator to assign the list of values to a record:

dept_rec := (60, 'PUBLICITY', 'LOS ANGELES');

Using the syntax below, you can assign the value of an expression to the specific element in a collection:

collection_name(index) := expression;

In the example below, you assign the uppercase value of the last_name to the third row in nested table ename_tab:

ename_tab(3) := UPPER(last_name);

Posted Date: 10/6/2012 8:45:37 AM | Location : United States







Related Discussions:- Expression in assignment statement - pl sql, Assignment Help, Ask Question on Expression in assignment statement - pl sql, Get Answer, Expert's Help, Expression in assignment statement - pl sql Discussions

Write discussion on Expression in assignment statement - pl sql
Your posts are moderated
Related Questions
Role of Abstraction in pl/sql: The abstraction is a high-level description or model of a real-world entity. The Abstractions keep our daily lives convenient. They help us ca

Pl/SQL Expressions The Expressions are constructed by using the operands and operators. An operand is a constant, literal, variable, or function call which contributes a value

Architecture The PL/SQL run-time system and compilation is a technology, not an independent product. Consider this technology as an engine that compiles and executes the PL/SQL

Passing Cursor Parameters You use the OPEN statement to pass the parameters to a cursor. Unless you want to accept the default values, each proper parameter in the cursor decl

Fetching with a Cursor The FETCH statements retrieve the rows in the result set one at a time. After each and every fetch, the cursor advance to the next row in the result set

IS NULL Operator The IS NULL operator returns the Boolean value TRUE whenever its operand is null or FALSE if it is not null. The comparisons including the nulls always yield NU

Using TRIM This process has two forms. The TRIM removes an element from the end of the collection. The TRIM(n) removes the n elements from the end of the collection. For e.g.

Procedures The procedure is a subprogram which can take parameters and be invoked. Normally, you can use a procedure to perform an action. The procedure has 2 sections: the spe

Wrapping and unwrapping in SQL Operators WRAP and UNWRAP in connection with attributes whose declared types are tuple types. Example shows how extension and projection can be

WHEN or THEN Key Constraints Suppose a table has two columns representing a period of time throughout which the information conveyed by the other columns is recorded as having