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
Managing Cursors The PL/SQL uses 2 types of cursors: implicit and explicit. The PL/SQL declares a cursor implicitly for all the SQL data manipulation statements, including th

INSERT Statement The INSERT statement adds fresh rows of data to the specified database table or view. Syntax:

Using a join on 2 tables, select all columns and 10 rows from the 2 tables without the use of a Cartesian product. Query: SELECT * FROM EMPLOYEE1 E JOIN STAFF S ON E.EMP_

Initializing and Referencing Collections Until you initialize a collection, a nested table or varray is automatically null (i.e. the collection itself is null, not its elements)

Updating Objects: To change the attributes of objects in an object table, you can use the UPDATE statement, as the illustration below shows: BEGIN UPDATE persons p SET p

Parameter Aliasing   To optimize the subprogram call, the PL/SQL compiler can decide between the two techniques of the parameter passing. With the by-value techniques, the v

Example of Using Aggregation on Nested Tables Example: How many students sat each exam WITH C_ER AS (SELECT CourseId, CAST (TABLE (SELECT DISTINCT StudentId, Mark FROM EXAM

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

Defining Autonomous Transactions To define an autonomous transaction, you use the pragma (compiler directive) AUTONOMOUS_TRANSACTION. The pragma instructs the PL/SQL compiler

How Transactions Guard Your Database The transaction is a sequence of SQL data manipulation statements which does a logical unit of work. The Oracle treats the sequence of SQL