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:

22-19.

Construction of the package is straightforward; see the invasions.pkg file on this book’s web page for the details. Here are the highlights.

First, create a named constant for the pipe name so it is not repeated throughout:

CREATE OR REPLACE PACKAGE BODY invpkg
IS
   pipename CONSTANT VARCHAR2(20) := 'invasions';
   stat PLS_INTEGER;

The sendinfo procedure makes certain to reset the buffer; error handling is left out, but you should probably check for a nonzero status and report the error:

   PROCEDURE sendinfo (
      country IN VARCHAR2,
      date_of_invasion DATE,
      people_killed NUMBER
      )
   IS
   BEGIN
      DBMS_PIPE.RESET_BUFFER;
      DBMS_PIPE.PACK_MESSAGE (country);
      DBMS_PIPE.PACK_MESSAGE (date_of_invasion);
      DBMS_PIPE.PACK_MESSAGE (people_killed);
      stat := DBMS_PIPE.SEND_MESSAGE (pipename, timeout => 10);
   END;

The record overloading simply calls the other implementation; try hard to avoid any redundant code:

   PROCEDURE sendinfo (rec IN inv_rectype)
   IS
   BEGIN
      sendinfo (
         rec.country,
         rec.date_of_invasion,
         rec.people_killed);
   END;

The nextinfo function receives and unpacks without any surprises (see the file for details). Finally, you have to deal with pipe creation. You want to make sure the pipe is created before anyone sends or receives. Since the pipe is private, the creation step must be done explicitly. The best place for this to happen is the initialization section at the bottom of the package body: ...

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