11.07.2015 Views

Oracle Database 11 g - Online Public Access Catalog

Oracle Database 11 g - Online Public Access Catalog

Oracle Database 11 g - Online Public Access Catalog

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER <strong>11</strong> ■ APPLICATION DEVELOPMENT 471BEGINIF livePipe IS NOT NULL THENmessQueue.EXTEND;messQueue(messQueue.LAST).donor_name:=:new.donor_name;messQueue(messQueue.LAST).donation_amount:=:new.donation_amount;END IF;END AFTER EACH ROW;AFTER STATEMENT ISBEGINIF livePipe IS NOT NULL THENLIVE_FEED.enqueue(livePipe,messQueue);END IF;END AFTER STATEMENT;END donation_ins_trg;This code collects donor/amount pairs in the messQueue collection. When the after triggeris called, the LIVE_FEED.enqueue() procedure is called. If a negative donation amount, or sometable constraint is violated, the after trigger is not called, except in certain cases with FORALLthat will be covered later.The following example shows a somewhat stubby implementation of LIVE_FEED:CREATE OR REPLACEpackage LIVE_FEED asSUBTYPE pipe_t IS PLS_INTEGER;TYPE messRec_t IS RECORD(donor_name VARCHAR2(256),donation_amount NUMBER);TYPE messTab_t IS TABLE OF messRec_t;FUNCTION getPipe RETURN pipe_t;PROCEDURE enqueue(pPipe pipe_t,messArr messTab_t);end;/CREATE OR REPLACEpackage body LIVE_FEED ISFUNCTION getPipe RETURN pipe_t ISBEGINRETURN 14553;END;PROCEDURE enqueue(pPipe pipe_t,messArr messTab_t) ISBEGINFOR i IN 1..messArr.COUNT LOOPdbms_output.put_line('Donor: '||messArr(i).donor_name||' Amount: '||messArr(i).donation_amount);END LOOP;END;END;/That’s pretty simple—the example just uses DBMS_OUTPUT to list the enqueued records. Thefollowing is a test of the trigger using a simple insert statement:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!