r/plsql • u/BradWS • May 09 '16
PLSQL FUNCTIONS, HELP Please
I am trying to learn plsql and i have a teacher and student database to play around with.
I am trying to turn this plsql block into a function
DECLARE v_class_id enrollments.class_id%type:=:CLass_ID; v_count number; BEGIN SELECT count(stu_id) INTO v_count FROM enrollments WHERE class_id=v_class_id; dbms_output.put_line('The amount of people in this class are: ' || v_count); END;
This is what i've tried doing,
CREATE OR REPLACE FUNCTION STUDENTCOUNT v_class_id enrollments.class_id%type:=:CLass_ID;
RETURN Number IS v_count number; BEGIN SELECT count(stu_id) INTO v_count FROM enrollments WHERE class_id=v_class_id; dbms_output.put_line('The amount of people in this class are: ' || v_count); END;
I am very new to this, any help and good explanation would be awesome
THANKS!
1
0
May 09 '16
[deleted]
1
u/BradWS May 09 '16
I'm trying to create a function. The first piece of code runs well and works, i am trying to turn that into a function.
The second piece of code is me trying to turn the first into a function but it doesn't process. What am i doing wrong?
1
1
u/BradWS May 09 '16
Sorry about the formatting, looks good when its in the editer box