Skip to Main Content
Oracle PL/SQL Programming: A Developer's Workbook
book

Oracle PL/SQL Programming: A Developer's Workbook

by Steven Feuerstein, Andrew Odewahn
May 2000
Intermediate to advanced content levelIntermediate to advanced
594 pages
11h 32m
English
O'Reilly Media, Inc.
Content preview from Oracle PL/SQL Programming: A Developer's Workbook

Intermediate

Q:

3-10.

You can rewrite this block of code as follows:

DECLARE
   total_sales NUMBER :=
      sales_for_year (company_id=>1056, yearnum=>1998);
   no_revenue BOOLEAN;
BEGIN
   no_revenue := total_sales <= 0;
END;

You do not need an IF statement in situations where you assign the value to a Boolean variable. Instead, you can assign the expression that would have appeared in the IF statement, directly to the Boolean. Note that if total_sales is set to NULL, no_revenue is set to NULL in both cases.

Q:

3-11.

In this case, you can’t quite obtain the same behavior by replacing the IF statement with a direct assignment. You might consider the following statement:

no_revenue := total_sales <= 0;

But you run into trouble if total_sales is NULL. The original code would have set no_revenue to FALSE if total_sales was NULL, since it would cause the ELSE clause to execute. If you replace it with a single line assignment, no_revenue is set to NULL instead of FALSE.

Q:

3-12.

The queue_order_for_addtl_parts procedure is never executed, regardless of the values for order_date, order_total, and min_order_total. For this procedure to run, order_date must be less than or equal to SYSDATE. If this is the case, the second condition would also be TRUE, and then fill_order is run for “LOW PRIORITY”. When working with IF-ELSIF statements, it is extremely important that you make sure the Boolean expressions are mutually exclusive.

Q:

3-13.

There is no difference logically between these two statements. The only difference ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Oracle Database 12c PL/SQL Programming

Oracle Database 12c PL/SQL Programming

Michael McLaughlin
Oracle PL/SQL for DBAs

Oracle PL/SQL for DBAs

Arup Nanda, Steven Feuerstein
Oracle PL/SQL For Dummies

Oracle PL/SQL For Dummies

Michael Rosenblum, Paul Dorsey

Publisher Resources

ISBN: 9781449324070Supplemental ContentErrata Page