title: SQL Function and Anonymous block
body: <p>I'm taking a class about databases. I am very new to it, so excuse me if this is an obvious error, but I've been working on this problem for hours and not sure what else to do.</p>
  
  <p>The code is suppose to create a function to that<br/>
  A.) Outputs the average netwin for a year given by a parameter
     (given by the formula (SeasonW-Seasonl) + (PlayoffW - PlayoffL)<br/>
  B.) Outputs all of the coaches that have a netwin over the average <br/>
  C.) Returns the number of coaches that fits this criteria.<br/>
  D.)Have a anonymous block that calls this function, and outputs two different messages depending on the return on the function. <br/><br/>
  Now I have sucessfully done parts A, C, and D. But for some reason my function will not be created when I insert part B.</p>
  
  <pre><code>create or replace function GOOD_COACHES(season IN INT)
  return INT
  IS
  netwin INT;
  CNT INT;
  BEGIN
         --Calculated netwin
         select AVG((SEASON_WIN-SEASON_LOSS) + (PLAYOFF_WIN-PLAYOFF_LOSS)) into  netwin from COACHESSEASON where YEAR = season; 
  
         --Prints out A
         dbms_output.put_line('Average Netwin is: ' || netwin);
  
         --This Line messes up the function, I don't know why
         select T.FIRSTNAME, T.LASTNAME from COACHESSEASON T where ((T.SEASON_WIN-T.SEASON_LOSS) + (T.PLAYOFF_WIN-T.PLAYOFF_LOSS))&gt;netwin and YEAR = season;
  
         --Calculates the number of teams that satisfy average
          select count(T.FIRSTNAME) into CNT from COACHESSEASON T where ((T.SEASON_WIN-T.SEASON_LOSS) + (T.PLAYOFF_WIN-T.PLAYOFF_LOSS))&gt;netwin and YEAR = season;
  
  return CNT;
  END;
  --End of the Function
  --Start of the Anonymous Block
   DECLARE
        x int := GOOD_COACHES(1998);
   BEGIN
        if x = 0 then dbms_output.put_line('We didn''t find any good_coaches!');
        else dbms_output.put_line('The No. of good coaches is ' || x);
        end if;
  END;
  /
  </code></pre>
  
  <p>That third line in the function messes it up and doesn't allow it to be called. If I comment it out, it works properly.
  When I take it out of the function and make it into a regular SQL statement, it works.</p>
  
  <pre><code>select T.FIRSTNAME, T.LASTNAME from COACHESSEASON T where ((T.SEASON_WIN-T.SEASON_LOSS) + (T.PLAYOFF_WIN-T.PLAYOFF_LOSS))&gt;0 and YEAR = /*RandYear*/;
  </code></pre>
  
  <p>If anyone understands why the function can not be created with that line it in, I would appreciate the advice. I also do not know how I would print out the results of the selected row in the function.</p>