Access the answers to your technology questions today.
Subscribe Now
30-day free trial. Register in 60 seconds.
What Makes Experts Exchange Unique?
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.
Try it out and discover for yourself.
Subscribe Now
30-day free trial. Register in 60 seconds.
Join the Community
Give a Little. Get a Lot.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Join the Community
by: sdstuberPosted on 2008-02-20 at 21:17:50ID: 20945175
You can only do this in 9i or above. You are looking for something called a "user defined aggregate"
tx IN OUT product_type)
tx IN OUT product_type)
CREATE OR REPLACE TYPE PRODUCT_TYPE AS OBJECT(
total NUMBER,
STATIC FUNCTION odciaggregateinitialize(sc
RETURN NUMBER,
MEMBER FUNCTION odciaggregateiterate(
SELF IN OUT product_type,
VALUE IN NUMBER
)
RETURN NUMBER,
MEMBER FUNCTION odciaggregateterminate(
SELF IN product_type,
returnvalue OUT NUMBER,
flags IN NUMBER
)
RETURN NUMBER,
MEMBER FUNCTION odciaggregatemerge(
SELF IN OUT product_type,
ctx2 IN product_type
)
RETURN NUMBER
);
/
CREATE OR REPLACE TYPE BODY product_type
IS
STATIC FUNCTION odciaggregateinitialize(sc
RETURN NUMBER
IS
BEGIN
sctx := product_type(NULL);
RETURN odciconst.success;
END;
MEMBER FUNCTION odciaggregateiterate(
SELF IN OUT product_type,
VALUE IN NUMBER
)
RETURN NUMBER
IS
BEGIN
SELF.total := NVL(SELF.total, 1) * VALUE;
RETURN odciconst.success;
END;
MEMBER FUNCTION odciaggregateterminate(
SELF IN product_type,
returnvalue OUT NUMBER,
flags IN NUMBER
)
RETURN NUMBER
IS
BEGIN
returnvalue := SELF.total;
RETURN odciconst.success;
END;
MEMBER FUNCTION odciaggregatemerge(
SELF IN OUT product_type,
ctx2 IN product_type
)
RETURN NUMBER
IS
BEGIN
SELF.total := NVL(SELF.total, 1) * NVL(ctx2.total, 1);
RETURN odciconst.success;
END;
END;
/
CREATE OR REPLACE FUNCTION product(input NUMBER)
RETURN NUMBER PARALLEL_ENABLE AGGREGATE
USING product_type;
/