Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Nerwbie needs help

Nerwbie needs help

From: <Scott>
Date: 7 May 1999 15:50:44 GMT
Message-ID: <XtL26jvDWiRB-pn2-vywWnyq8uugr@slip-32-100-164-28.in.us.ibm.net>


I am a newbie that needs help with writing a function. I have goten 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.

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
m_avg number;
BEGIN
Select avg(sum(close)) into m_avg From awt_stock_price Where symbol = p_symbol
And seq_no In (Select seq_no from awt_stock_price where seq_no between p_seq_no
                         And p_seq_no - p_len)
group by symbol;
Return m_avg;
END awt_ma;
/ Received on Fri May 07 1999 - 10:50:44 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US