0

I have to write PL/SQL Block that print salary of the people who have same job_title. Job_title must be entered in substitution variable. I struggle to print with 'dbms_output.put_line'. Also sql says that join is not right.

 DECLARE
  v_jobt VARCHAR2(50);
  v_sal Number ;
BEGIN
  SELECT j.job_title,e.salary INTO v_jobt, v_sal 
  FROM jobs j
  JOIN  EMPLOYEES e
  ON JOBS.JOB_ID=EMPLOYEES.salary
  WHERE  j.job_title = '&job_title';
  DBMS_OUTPUT.PUT_LINE ('Job Title is : ' ||v_jobt);
END;
2
  • FYI: In SQL WHERE is after JOIN. Commented May 13, 2019 at 23:21
  • Even then I have errors. Commented May 13, 2019 at 23:28

1 Answer 1

1

1, Put 'where clause' after 'join'

2, Use the Alias names in the 'on' condition

3, Add one single quote before ...is:'

If you get the error message, please tell us what message you got.

Try this:

DECLARE
 v_lname VARCHAR2(50);
 v_sal Number;
BEGIN
  SELECT j.job_title,e.salary INTO v_lname, v_sal 
  FROM jobs j 
  JOIN  EMPLOYEES e
  ON j.JOB_ID = e.JOB_ID
  WHERE  j.job_title = '&job_title';
  DBMS_OUTPUT.PUT_LINE ('...is : ' ||v_lname);
END;
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you ! Do you know how I can add Average salary. "e.avg(salary)" is not right syntax.
Put alias on the field and not function. See if you need GROUP BY clause.
@YavorPetranov It should be avg(e.salary). You also need to add 'group by j.job_title' after where clause if you want to get the average salary for each job title.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.