Following along with the video, I came up with this code:
DROP PROCEDURE IF EXISTS emp_avg_salary_out;
USE employees $$
CREATE PROCEDURE emp_avg_salary_out (in p_emp_no integer, out p_avg_salary decimal(10,2))
ROUND(AVG(s.salary),2) AS avg_salary
INTO p_avg_salary FROM
salaries s ON e.emp_no = s.emp_no
e.emp_no = p_emp_no;
My call statement returned an error. I found that it should be written as CALL emp_avg_salary_out(11300, @p_avg_salary); but this is not covered in the video because the procedure was called from the schemas section.
Can you provide more detail?
Thanks for reaching out.
Since by construction you have an out parameter as well, you need to designate where/how(i.e. in which variable) do you want to store the output of the procedure while calling it. That’s why the code that you have found works.
Hope this helps.
Thank you. I suppose I dont understand the syntax of emp_avg_salary_out(11300, @p_avg_salary), particularly the @p_avg_salary. Does the @ make it a variable? I don't recall seeing this before.
You are very welcome! Yes, you are very right – @ makes it a variable. It is normal to not have seen this earlier – we are talking about variables later in the course, starting here:https://365datascience.teachable.com/courses/360102/lectures/5529194 Hope this helps. Best, Martin
Ahh! Thank you!
You are very welcome!