Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Newbie needs help
I am a newbie that needs help with writing a function. I have gotten
stuck somewhere that I can't see at the moment. As you see I have
tried many conotations, including cursor for loop not included here.
I am just asking for some one to point the glasring errors so I can
get on my way to learning.
the function is to return a number value for a moving average
CREATE TABLE awt_stock_price
(Symbol varchar2(5)
, Close_Date date
, Seq_No number
, Open number(8,4)
, Hi number(8,4)
, Lo number(8,4)
, Close number(8,4)
, Volume number(12)
, PRIMARY KEY (Symbol, Close_Date));
CREATE OR REPLACE function awt_ma
(p_symbol in varchar2, p_seq_no in number ,p_len in number)
RETURN NUMBER IS
m_avg number;
BEGIN
Select avg(sum(close)) into m_avg From awt_stock_price
Where symbol = p_symbol
And seq_no Between p_seq_no And p_seq_no - p_len
group by symbol;
Return m_avg;
END awt_ma;
/
this didn't work
RETURN NUMBER IS
BEGIN
Select close into m_avg From awt_stock_price
Where symbol = p_symbol
And seq_no Between p_seq_no And p_seq_no - p_len;
Return Avg(Close);
END;
this didn't work
RETURN NUMBER IS
m_avg number;
BEGIN
Select close into m_avg From awt_stock_price
Where symbol = p_symbol
And seq_no Between p_seq_no And p_seq_no - p_len;
Return (m_avg = Avg(Close));
END awt_ma;
this didn't work
CREATE OR REPLACE function awt_ma
(p_symbol in varchar2, p_seq_no in number ,p_len in number)RETURN NUMBER IS
And p_seq_no - p_len)group by symbol;
![]() |
![]() |