Code not compiling - Any suggestion? [message #8162] |
Wed, 30 July 2003 19:44 |
nm
Messages: 3 Registered: July 2003
|
Junior Member |
|
|
I have written this code and cannot get this function to compile successfully
CREATE OR REPLACE FUNCTION get_budget
(v_school_id IN NUMBER)
RETURN number
IS
v_yearly_budget NUMBER;
BEGIN
SELECT yearly_budget
INTO v_yearly_budget
FROM school
WHERE id = school_id;
END;
Can someone please help me out, and let me know which of the following code must be added to the executable section?
a. RETURN;
b. RETURN get_budget;
c. RETURN school;
d. RETURN v_yearly_budget;
|
|
|
Re: Code not compiling - Any suggestion? [message #8164 is a reply to message #8162] |
Wed, 30 July 2003 21:05 |
|
Barbara Boehmer
Messages: 9090 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
You should try testing each one to find out. You should also attempt to understand why. Since this is a funciton you need to return something. You need to specify what you are returning, so a is incorrect. You don't want to return the name of the function (get_budget), so b is incorrect. You don't want to return the table name (school), so c is incorret. You have selected data into the variable v_yearly_budget so that you can return the value in that variable, so you want to return v_yearly_budget, so d is the correct answer:
CREATE OR REPLACE FUNCTION get_budget
(v_school_id IN NUMBER)
RETURN number
IS
v_yearly_budget NUMBER;
BEGIN
SELECT yearly_budget
INTO v_yearly_budget
FROM school
WHERE id = school_id;
<b>RETURN v_yearly_budget;</b>
END;
/
|
|
|