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
Parameter and Keyword Description: SQL: This SQL is the name of the implicit SQL cursor. %FOUND: This attribute results TRUE if an INSERT, DELETE, or UPDATE state

Semijoin and Composition - SQL For semijoin, the dyadic relational operator MATCHING, defined thus: r1 MATCHING r2, where r1 and r2 are relations such that r1 JOIN r2 is de

What are the rates for help in writing PL/SQL procedures and functions?

EXECUTE Privilege To call an invoker-rights routine straightforwardly, the users should have the EXECUTE privilege on that routine. By yielding the privilege, you permit a user

Error Handling The PL/SQL makes it easy to detect and process the predefined and user-defined error conditions known as exceptions. Whenever an error occurs, an exception is ra

Example of Cast Operator So long as CAST is used as shown, we could obtain the total marks for each exam in similar fashion, using SUM (Mark) AS TotalMarks. However, this giv

Use of COUNT in SQL It describes and discusses various general methods of expressing constraints, eventually noting that support for "=" with relation operands is sufficient f

Using Aggregation on Nested Tables Example is the most direct translation of its counterpart in the theory book that can be obtained in SQL but it is so over-elaborate that no

Datatype Conversion At times it is necessary to convert a value from one datatype to another. For e.g. if you want to inspect a rowid, you should convert it to a character stri

Parameter and Keyword Description: label_name: This is an undeclared identifier which optionally labels a loop. When used, the label_name should be enclosed by double ang