Oracle DBMS_PIPE
Version 21c

General Information
Library Note Morgan's Library Page Header
ACE Director Alum Daniel Morgan, founder of Morgan's Library, is scheduling complimentary technical Workshops on Database Security for the first 30 Oracle Database customers located anywhere in North America, EMEA, LATAM, or APAC that send an email to asra_us@oracle.com. Request a Workshop for your organization today.
Purpose Allow sessions to pass information between them through named SGA memory "pipes"
AUTHID DEFINER
Constants
Name Data Type Value
maxwait INTEGER 86400000 (1000 days)
Dependencies
DBMS_ALERT DBMS_SNAPSHOT_KKXRCA JVMRJBC
DBMS_CAPTURE_ADM_INTERNAL DBMS_SYS_ERROR JVMRJBCINV
DBMS_DEBUG DRIXMD PBREAK
DBMS_GSM_UTILITY DRVTMT PBRPH
DBMS_I_INDEX_UTL    
Documented Yes: Packages and Types Reference
Exceptions
Error Code Reason
ORA-06556 Generated if the buffer contains no more items, or if the item is not of the same type as that requested
ORA-06558 Generated if message buffer overflows (currently 4096 bytes). Each item in the buffer takes one byte for the type, two bytes for the length, plus the actual data. There is also one byte needed to terminate the message.
ORA-06559 Generated if the buffer contains no more items, or if the item is not of the same type as that requested
First Available 7.3.4
Security Model Owned by SYS with EXECUTE granted to the EXECUTE_CATALOG_ROLE role and SYSBACKUP.
Source {ORACLE_HOME}/rdbms/admin/dbmspipe.sql
Subprograms
 
CREATE_PIPE
Create a pipe dbms_pipe.create_pipe(
pipename    IN VARCHAR2,
maxpipesize IN INTEGER DEFAULT 8192,
private     IN BOOLEAN DEFAULT TRUE,
global      IN BOOLEAN DEFAULT FALSE)
RETURN INTEGER;
desc v$db_pipes

SELECT * FROM v$db_pipes;

set serveroutput on

DECLARE
 retval INTEGER;
BEGIN
  retval := dbms_pipe.create_pipe('UWPIPE');
  dbms_output.put_line(retval);
END;
/

SELECT * FROM v$db_pipes;

DECLARE
 retval INTEGER;
BEGIN
  retval := dbms_pipe.remove_pipe('UWPIPE');
  dbms_output.put_line(retval);
END;
/

SELECT * FROM v$db_pipes;
 
NEXT_ITEM_TYPE
Returns the data type of the next item in the local message buffer

Value Description
0 No more items
6 NUMBER
9 VARCHAR2
11 ROWID
12 DATE
23 RAW
dbms_pipe.next_item_type RETURN INTEGER;
set serveroutput on

DECLARE
 retval NUMBER;
BEGIN
  retval := dbms_pipe.next_item_type;
  dbms_output.put_line(retval);
END;
/
 
PACK_MESSAGE
Pack a message of a string data type
Overload 1
dbms_pipe.pack_message(item IN VARCHAR2 CHARACTER SET ANY_CS);
See DBMS_PIPE at page bottom
Pack a message of numeric data type
Overload 2
dbms_pipe.pack_message(item IN NUMBER);
See DBMS_PIPE at page bottom
Pack a message of DATE data type
Overload 3
dbms_pipe.pack_message(item IN DATE);
See DBMS_PIPE at page bottom
 
PACK_MESSAGE_RAW
Pack a message of RAW data type dbms_pipe.pack_message_raw(item IN RAW);
See DBMS_PIPE at page bottom
 
PACK_MESSAGE_ROWID
Pack a message of ROWID data type dbms_pipe.pack_message_raw(item IN ROWID);
See DBMS_PIPE at page bottom
 
PURGE
Empty the named pipe of all messages dbms_pipe.purge(pipename IN VARCHAR2);
exec dbms_pipe.purge('UWPIPE');
 
RECEIVE_MESSAGE
Receive a message from the named pipe and copy the message into the local message buffer dbms_pipe.receive_message(
pipename IN VARCHAR2,
timeout  IN INTEGER DEFAULT maxwait)
RETURN INTEGER;
See DBMS_PIPE at page bottom
 
REMOVE_PIPE
Remove a pipe dbms_pipe.remove_pipe(pipename IN VARCHAR2) RETURN INTEGER;
See DBMS_PIPE at page above
 
RESET_BUFFER
Resets pack and unpack positioning indicators to 0. Generally this routine is not needed dbms_pipe.reset_buffer;
exec dbms_pipe.reset_buffer;
 
SEND_MESSAGE
Send a message on the named pipe. The message is contained in the local message buffer which was filled with calls to 'pack_message'. dbms_pipe.send_message(
pipename    IN VARCHAR2,
timeout     IN INTEGER DEFAULT maxwait,
maxpipesize IN INTEGER DEFAULT 8192)
RETURN INTEGER;
See demo below
 
UNIQUE_SESSION_NAME
Creates a name that is unique among all sessions currently connected to the database. Multiple calls to this routine from the same session will always return the same value. dbms_pipe.unique_session_name RETURN VARCHAR2;
DECLARE
 retval VARCHAR2(128);
BEGIN
  retval := dbms_pipe.unique_session_name;
  dbms_output.put_line(retval);
END;
/
 
UNPACK_MESSAGE
Unpack a message of a string data type
Overload 1
dbms_pipe.unpack_message((item OUT VARCHAR2 CHARACTER SET ANY_CS);
See demo below
Unpack a message of a numeric data type
Overload 2
dbms_pipe.unpack_message((item OUT NUMBER);
See demo below
Unpack a message of a DATE data type
Overload 3
dbms_pipe.unpack_message((item OUT DATE);
See demo below
 
UNPACK_MESSAGE_RAW
Unpack a message of RAW data type dbms_pipe.unpack_message_raw(item OUT RAW);
See DBMS_PIPE at page bottom
 
UNPACK_MESSAGE_ROWID
Unpack a message of ROWID data type dbms_pipe.unpack_message_rowid(item OUT ROWID);
See DBMS_PIPE at page bottom
 
DBMS_PIPE Demo
Demo Package posted to the OTN forums by Velu CREATE OR REPLACE PACKAGE message_api AUTHID DEFINER AS
 PROCEDURE send (p_number IN NUMBER, p_text IN VARCHAR2, p_date IN DATE DEFAULT SYSDATE);
 PROCEDURE receive;
END message_api;
/

CREATE OR REPLACE PACKAGE BODY message_api AS
---------------------------------------------
 PROCEDURE send (p_number IN NUMBER, p_text IN VARCHAR2, p_date IN DATE DEFAULT SYSDATE) AS
  l_status NUMBER;
 BEGIN
   dbms_pipe.pack_message(p_number);
   dbms_pipe.pack_message(p_text);
   dbms_pipe.pack_message(p_date);

   l_status := dbms_pipe.send_message('message_pipe');
   IF l_status != 0 THEN
     RAISE_APPLICATION_ERROR(-20001, 'message_pipe error');
   END IF;
 END;
---------------------------------------------
 PROCEDURE receive AS
   l_result INTEGER;
   l_number NUMBER;
   l_text   VARCHAR2(32767);
   l_date   DATE;
 BEGIN
   l_result := dbms_pipe.receive_message(pipename => 'message_pipe', timeout => dbms_pipe.maxwait);

   IF l_result = 0 THEN
     -- message received successfully
     dbms_pipe.unpack_message(l_number);
     dbms_pipe.unpack_message(l_text);
     dbms_pipe.unpack_message(l_date);

     dbms_output.put_line('l_number: ' || l_number);
     dbms_output.put_line('l_text : ' || l_text);
     dbms_output.put_line('l_date : ' || l_date);
   ELSE
      RAISE_APPLICATION_ERROR(-20002, 'message_api.receive was unsuccessful. Return result: ' || l_result);
   END IF;
 END receive;
---------------------------------------------
END message_api;
/

Related Topics
Built-in Functions
Built-in Packages
DBMS_ALERT
DBMS_AQ
DBMS_AQADM
DBMS_STOCK_SERVER
What's New In 21c
What's New In 23c

Morgan's Library Page Footer
This site is maintained by Dan Morgan. Last Updated: This site is protected by copyright and trademark laws under U.S. and International law. © 1998-2023 Daniel A. Morgan All Rights Reserved
  DBSecWorx