Short-circuit evaluation-pl/sql expressions , PL-SQL Programming

Short-Circuit Evaluation

When computing a logical expression, the PL/SQL uses short-circuit evaluation. That is, the PL/SQL stops computing the expression as soon as the result can be determined. This permits you to write the expressions that might otherwise cause an error. Now consider the following OR expression:


DECLARE
...
on_hand INTEGER;
on_order INTEGER;
BEGIN
..
IF (on_hand = 0) OR ((on_order / on_hand) < 5) THEN
...
END IF;
END;


Whenever the value of on_hand is zero, the left operand yields TRUE, so the PL/SQL require not compute the right operand. If PL/SQL were to compute both operands before applying the OR operator, the right operand would cause a division by the zero error. In any case, it is a poor programming practice to rely on the short-circuit computation.

Posted Date: 10/3/2012 5:19:05 AM | Location : United States







Related Discussions:- Short-circuit evaluation-pl/sql expressions , Assignment Help, Ask Question on Short-circuit evaluation-pl/sql expressions , Get Answer, Expert's Help, Short-circuit evaluation-pl/sql expressions Discussions

Write discussion on Short-circuit evaluation-pl/sql expressions
Your posts are moderated
Related Questions
Package STANDARD package named STANDARD defines the PL/SQL atmosphere. The package specification globally declares the exceptions, types, and subprograms that are available a

Keys in SQL SQL support for keys in the following respects: SQL does not require at least one key for every base table. If no key is explicitly declared, then KEY {ALL B

Advantages of Packages The benefits of the Packages are as shown below: Modularity The Packages encapsulate logically associated items, types, and subprograms in the

Running the PL/SQL Wrapper To run the PL/SQL Wrapper, go through the wrap command at your operating system prompt by using the syntax as shown: wrap iname=input_file [oname=

Create the four tables and populate them with the given data. Answer the following queries in SQL. 1. Get all part-color/part-city combinations. Note: Here and subsequently, 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

Adding Table Constraints ALTER TABLE ENROLMENT ADD CONSTRAINT NameNotNull CHECK (Name IS NOT NULL) ; ALTER TABLE ENROLMENT ADD CONSTRAINT PK_StudentId_CourseId PRIM

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

1. Create a procedure called TAX_COST_SP to accomplish the tax calculation task. Keep in mind that the state and subtotal values are inputs into the procedure and the procedure is

Using NOT NULL Besides assigning an initial value, the declarations can impose the NOT NULL constraint, as the example below shows: acct_id INTEGER(4) NOT NULL := 9999; You ca