Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TYPE time_avg_row AS OBJECT (TIME TIMESTAMP, price FLOAT);
- /
- CREATE TYPE time_avg_table IS TABLE OF time_avg_row;
- /
- CREATE OR REPLACE FUNCTION moving_average
- RETURN time_avg_table PIPELINED
- AS
- val NUMBER := 0;
- BEGIN
- SELECT * INTO val FROM (SELECT MEDIAN.price FROM MEDIAN ORDER BY MEDIAN.TIME) WHERE ROWNUM = 1;
- FOR rec IN (SELECT * FROM MEDIAN ORDER BY TIME) LOOP
- val := val + (rec.price - val) * 2 / 11;
- PIPE ROW(time_avg_row(rec.TIME, val));
- END LOOP;
- RETURN;
- END;
- /
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement