iSelfSchooling.com - Since 1999  References  |  Job Openings  |
    Home  | Search more  | Oracle Syntax  | Instructor-Led in Class   | (Members to access to VIDEOS)
 

Copyright & User Agreement

   Suggestions Email2aFriendHomepage us! |  Bookmark

Services

  Vision/Mission

  Services

  Biography

  Contact Us

 FREE Training

  Start...

  SQL

  PL/SQL

  Forms 

  Reports

  DBA Fundamentals

  Performance

  Prepare for OCP

  ShareUrNotes

...

  Acknowledgement

  Who is who

  University Directory

  Links...

 

 

 

FREE Online Oracle Training for beginners and advanced - The most comprehensive Oracle tutorial

The authors do not guarantee or take any responsibility for the accuracy, or completeness of the information.

BASICS

SQL | PL/SQL

DEVELOPERS

FORMS 2 | REPORTS | Other TOOLS

DBAs

FUNDAMENTALS 2 | PERFORMANCE | OEM

ADVANCE

APPLICATION SERVER | GRID CONTROL | ARTICLES 2 3 4

Advanced - Articles II

Lesson 01 | Lesson 02 | Lesson 03 | Lesson 04 | Lesson 05 | Lesson 06 | Lesson 07 | Lesson 08 | Lesson 09 | Lesson 10 | Lesson 11 | Lesson 12 | Lesson 13 | Lesson 14 | Lesson 15 | Lesson 16 | Lesson 17 | Lesson 18 | Lesson 19 | Lesson 20 | Lesson 21 | Lesson 22 | Lesson 23 | Lesson 24 | Lesson 25 | Lesson 26 | Lesson 27 | Lesson 28 | Lesson 29 | Lesson 30 | Lesson 31 | Lesson 32 | Lesson 33 | Lesson 34 | Lesson 35 |

Lesson 34

"There is another reality enfolding ours-as close as our breath!"

-Don Pendleton (1927-1995)

This case study will explain how the Oracle Pipes work and how to use DBMS_PIPE. 

What is the Oracle Pipe?
--------------------
The Oracle Pipe is a type of communication between sessions in the same instance of a database. Messages are put inside the pipe by one session and other takes the message out. 

You can have a pipe that is public or private. When a pipe is public, it means everybody can receive or send messages to it. And when it is a private then only the session with the same user can access it.

 

This case study will explain how the Oracle Pipes work and how to use DBMS_PIPE. 

What is the Oracle Pipe?
--------------------
The Oracle Pipe is a type of communication between sessions in
the same instance of a database. Messages are put inside the pipe
by one session and other takes the message out. 

You can have a pipe that is public or private. When a pipe is
public, it means everybody can receive or send messages to it. 
And when it is a private then only the session with the same
user can access it.

Make sure that user(s) have grant execute on the dbms_pipe,
dbms_output packages.

Run the dbmspipe.sql script, if you don't have this package or
you get the following error message:
PLS-00201: identifier 'DBMS_PIPE' must be declared
ORA-06550: line ?, column ?:

start %ORACLE_HOME%\rdbms\admin\dbmspipe.sql

--This procedure will send a message.
CREATE OR REPLACE PROCEDURE send_message 
(p_message VARCHAR2)
AS
    result NUMBER;
    my_pipe VARCHAR2(30); 
    user user_users%ROWTYPE; 

BEGIN
    --Query username.
    SELECT * INTO user FROM user_users;

    -- Get a unique session identifier.
    my_pipe:=dbms_pipe.UNIQUE_SESSION_NAME;

    -- Put the messages inside the private buffer.
    dbms_pipe.pack_message(my_pipe);

    -- Send the messages stored into the private buffer thru the pipe. 
    result:=dbms_pipe.send_message('waiter');

    -- Put the messages inside the private buffer.
    dbms_pipe.pack_message(user.USERNAME); 
    dbms_pipe.pack_message(p_message); 

    -- Send the messages.
    result:=dbms_pipe.send_message(my_pipe); 
END send_message; 
/

-- This procedure will get the message.
CREATE OR REPLACE PROCEDURE get_message
AS
    result number; 
    v varchar2(4000); 
    his_pipe varchar2(30); 

BEGIN
    -- Wait for message to appear in the pipe
    -- up to value of maxwait in seconds and then
    -- place them on the private buffer.
    -- The return value of 0, it means that process
    -- was successful.
    result:=dbms_pipe.RECEIVE_MESSAGE('waiter');

    -- Retrieve the messages from the buffer and 
    -- place them in variables based on their types. 
    dbms_pipe.unpack_message(his_pipe); 
    dbms_output.put_line('Pipe :'||his_pipe); 

    result:=dbms_pipe.RECEIVE_MESSAGE(his_pipe); 
    result:=dbms_pipe.next_item_type;

    WHILE result<>0 LOOP
        -- varchar2 
        dbms_pipe.unpack_message(v); 
        dbms_output.put_line(v); 
        result:=dbms_pipe.next_item_type; 
    END LOOP;

EXCEPTION 
    WHEN others THEN
        dbms_output.put_line('error: '||to_char(result)); 
        dbms_pipe.purge(his_pipe); 
END;


-- Query all pipes that you have.

COL name FORMAT A40 
SELECT * FROM v$db_pipes
/

-- This procedure will remove all your pipes.
CREATE OR REPLACE PROCEDURE clean_pipes
IS
    result number; 
BEGIN 
    FOR i IN (SELECT * FROM v$db_pipes) LOOP
        dbms_output.put('Pipe '||i.name);
        BEGIN 
            result:=dbms_pipe.remove_pipe(i.name); 
            dbms_output.put_line(' removed.');
        EXCEPTION 
            WHEN others THEN
                dbms_output.put_line(' not removed.'); 
        END; 
    END LOOP; 
END clean_pipes; 
/

To execute the procedures:

EXECUTE send_message ('this is my message');

EXECUTE get_message;
EXECUTE clean_pipes;

 

 
 
Google
 
Web web site