title: Apex parse error when creating SQL query with sql function
body: <p>I have the following function:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION calc_a(BIDoctor number) RETURN number
  IS
    num_a number;
  BEGIN
    select count(NAppoint)
    into num_a
    from Appointment a
    where BIDoctor = a.BIDoctor;
    RETURN num_a;
  END calc_a;
  </code></pre>
  
  <p>What we want is adding a column to a report that shows us the number of appointments that doc have. </p>
  
  <pre><code>select a.BIdoctor "NUM_ALUNO",
    a.NameP "Nome",
    a.Address "Local",
    a.Salary "salary",
    a.Phone "phone",
    a.NumberService "Curso",
    c.BIdoctor "bi",
    calc_media(a.BIdoctor) "consultas"
  FROM "#OWNER#"."v_Doctor" a, "#OWNER#"."Appointment" c
  WHERE a.BIdoctor = c.BIdoctor; 
  </code></pre>
  
  <p>and we got this when we are writing the region source on apex. 
  But it shows a parse error, I was looking for this about 2 hours and nothing.</p>
  
  <p>Apex shows me this:</p>
  
  <blockquote>
    <p>PARSE ERROR ON THE FOLLOWING QUERY </p>
  </blockquote>