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

Expert

Q:

23-20.

The most elegant (not necessarily the most efficient) solution involves recursion:


/* Filename on web page: println.sp */
CREATE OR REPLACE PROCEDURE println (val IN VARCHAR2)
IS
BEGIN
   /* Don't display lines longer than 80 characters;
      they are hard to read. */
   IF LENGTH (val) > 80
   THEN
      DBMS_OUTPUT.PUT_LINE (SUBSTR (val, 1, 80));
      println (SUBSTR (val, 81));
   ELSE
      DBMS_OUTPUT.PUT_LINE (val);
   END IF;
END;
/

Q:

23-21.

To obtain this behavior, add the following exception section to the implementation of println:

EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.ENABLE (1000000);
      println (val);
END;
/

In other words, if any problem occurs, expand the buffer to its maximum size and then try, try again.

Q:

23-22.

The most interesting aspect of the solution is the implementation of the Boolean overloading. Here is one possible approach:

 /* Filename on web page: print.pkg */ CREATE OR REPLACE PACKAGE BODY print IS PROCEDURE ln (val IN VARCHAR2) IS BEGIN IF LENGTH (val) > 80 THEN DBMS_OUTPUT.PUT_LINE (SUBSTR (val, 1, 80)); ln (SUBSTR (val, 81)); ELSE DBMS_OUTPUT.PUT_LINE (val); END IF; EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.ENABLE (1000000); ln (val); END; PROCEDURE ln (val IN DATE) IS BEGIN ln (TO_CHAR (val, 'MM/DD/YYYY HH24:MI:SS')); END; PROCEDURE ln (val IN NUMBER) IS BEGIN ln (TO_CHAR (val)); ...
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