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
UPDATE Command- SQL Loosely speaking, UPDATE changes some of the column values of some existing rows of its target table. Thus, although some rows disappear from the target an

Parameter and Keyword Description: type_name: This identifies a user-defined type specifier that is used in the subsequent declarations of the objects. AUTHID Clause:

Write an anonymous block that contains a PL/SQL procedure. The procedure takes two input parameter: oldZip and newZip, and it updates the zipcodes table by replacing all oldZip wit

Quantification in SQL To quantify something, as the theory book has it, is to state its quantity, to say how many of it there are. For example, in Tutorial D the expression CO

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

Joining in SQL Joining IS_CALLED and IS_ENROLLED_ON in SQL SELECT * FROM IS_CALLED NATURAL JOIN IS_ENROLLED_ON This is an example of an SQL table expression. I have been

Package STANDARD The package named STANDARD defines the PL/SQL atmosphere. The package specification globally declares the exceptions, types, and subprograms that are available

Use the PLS_INTEGER Datatype When you require to declare an integer variable, use the datatype PLS_INTEGER that is the most efficient numeric type. That is as the PLS_INTEGER

I need to write one function and one procedure to query a Oracle 10.1 DB using PL SQL. I have the schema and exact queries...along with work Ive started and a template to put the a

Using %TYPE The %TYPE attribute gives the datatype of a variable or the database column. In the example below, the %TYPE gives the datatype of a variable: credit REAL(7,2); debi