The DBMS_PIPE package provides a way for sessions in the same database instance to communicate with each other. One of the most useful aspects of Oracle pipes is that pipe communication is asynchronous: you need not COMMIT a transaction in order to initiate pipe-related activity, as is necessary with the DBMS_ALERT package. You can send a message through and receive a message from a pipe at any time. Indeed, more than one session can read or write to the same pipe.
With PL/SQL Release 2.2 only, the CREATE_PIPE function allows you to explicitly request the creation of a pipe, either public or private. The specification is:
FUNCTION DBMS_PIPE.CREATE_PIPE (pipename IN VARCHAR2, maxpipesize IN INTEGER DEFAULT 8192, private IN BOOLEAN DEFAULT TRUE) RETURN INTEGER;
The function returns a numeric status code. If it returns 0, then the pipe was created successfully.
The NEXT_ITEM_TYPE function returns the type of the next item in the local message buffer. Data is put in the message buffer with both the PACK_MESSAGE and the RECEIVE_MESSAGE procedures. Use NEXT_ITEM_TYPE to decide which kind of variable you should use to receive the data from the buffer with the overloaded UNPACK_MESSAGE module. The specification is:
FUNCTION DBMS_PIPE.NEXT_ITEM_TYPE RETURN INTEGER;
where the return value for the function is one of the following:
No more items in buffer
VARCHAR2
NUMBER
DATE
The PACK_MESSAGE procedure packs an item into the message buffer for your session. A pipe message item may have a datatype of VARCHAR2, NUMBER, or DATE. The specifications are:
PROCEDURE DBMS_PIPE.PACK_MESSAGE (item IN VARCHAR2); PROCEDURE DBMS_PIPE.PACK_MESSAGE (item IN NUMBER); PROCEDURE DBMS_PIPE.PACK_MESSAGE (item IN DATE);
The PURGE procedure empties the contents of the named pipe. The specification is:
PROCEDURE DBMS_PIPE.PURGE (pipename IN VARCHAR2);
The RECEIVE_MESSAGE function receives a message from the named pipe and copies the contents of that message to the local message buffer. Once you receive the message into the buffer, you can use the UNPACK_MESSAGE procedure to extract the items from the buffer into local variables. The specification is:
FUNCTION DBMS_PIPE.RECEIVE_MESSAGE (pipename IN VARCHAR2, timeout IN INTEGER DEFAULT MAXWAIT) RETURN INTEGER;
The function returns a status, which will be one of the following INTEGER values:
Successful receipt of message
Timed out waiting to receive a message
Record in pipe too big for buffer; this should never happen
Receipt of message was interrupted
The REMOVE_PIPE function removes a pipe from shared memory. This function must be called to remove a pipe created explicitly with CREATE_PIPE. If your pipe is created implicitly, then it will be removed with a call to PURGE or whenever the pipe is emptied. The specification is:
FUNCTION DBMS_PIPE.REMOVE_PIPE (pipename IN VARCHAR2) RETURN INTEGER;
The RESET_BUFFER procedure clears the buffer so that both PACK_MESSAGE and UNPACK_MESSAGE will work from the first item. The specification is:
PROCEDURE DBMS_PIPE.RESET_BUFFER;
The SEND_MESSAGE function sends the contents of the local message buffer to the named pipe. The specification is:
FUNCTION DBMS_PIPE.SEND_MESSAGE (pipename IN VARCHAR2, timeout IN INTEGER DEFAULT MAXWAIT, maxpipesize IN INTEGER DEFAULT 8192) RETURN INTEGER;
The function returns a status code as follows:
Successful receipt of message
Timed out waiting to send a message
Sending of message was interrupted
The UNIQUE_SESSION_NAME function returns a name that is unique among the sessions currently connected to the database. You can use this function to obtain a name for a pipe that you know will not be in use by any other sessions. The specification is:
FUNCTION DBMS_PIPE.UNIQUE_SESSION_NAME RETURN VARCHAR2;
The UNPACK_MESSAGE procedure unpacks the next item from the local message buffer and deposits it into the specified local variable. The specification is:
PROCEDURE DBMS_PIPE.UNPACK_MESSAGE (item OUT VARCHAR2); PROCEDURE DBMS_PIPE.UNPACK_MESSAGE (item OUT NUMBER); PROCEDURE DBMS_PIPE.UNPACK_MESSAGE (item OUT DATE);
Copyright (c) 2000 O'Reilly & Associates. All rights reserved.