1Z0-909 · Question #62
The employee table includes these columns: e_id INT, e_name VARCHAR (45), dept_id INT salart INT You must create a stored function, getMaxSalary(), which returns the maximum salary paid for a given…
The correct answer is A. CREATE FUNCTION getMaxSalary(v_dept_id INT) RETURNS CHAR(50) BEGIN SELECT MAX(salary) INTO @m FROM employee WHERE dept_id = v_dept_id; RETURN @m; END. The marked answer of A is incorrect - this appears to be an error in the answer key. C is the correct answer. Option C is the only syntactically valid MySQL stored function: it returns INT (matching the salary column type), includes the required DETERMINISTIC characteristic…
Question
The employee table includes these columns:
e_id INT, e_name VARCHAR (45), dept_id INT salart INT You must create a stored function, getMaxSalary(), which returns the maximum salary paid for a given department id. Which statement will create the function? A. B. C. D.
Exhibits
Options
- ACREATE FUNCTION getMaxSalary(v_dept_id INT) RETURNS CHAR(50) BEGIN SELECT MAX(salary) INTO @m FROM employee WHERE dept_id = v_dept_id; RETURN @m; END
- BCREATE FUNCTION getMaxSalary(v_dept_id INT) RETURNS INT DETERMINISTIC BEGIN USE schemaname; SELECT MAX(salary) INTO msalary FROM employee WHERE dept_id = v_dept_id; RETURN msalary; END
- CCREATE FUNCTION getMaxSalary(v_dept_id INT) RETURNS INT DETERMINISTIC BEGIN DECLARE msalary INT; SELECT MAX(salary) INTO msalary FROM employee WHERE dept_id = v_dept_id; RETURN msalary; END
- DCREATE FUNCTION getMaxSalary(v_dept_id INT) RETURNS INT DECLARE msalary INT; BEGIN SELECT MAX(salary) INTO msalary FROM employee WHERE dept_id = v_dept_id; SET msalary = msalary; RETURN msalary; END
How the community answered
(68 responses)- A90% (61)
- B6% (4)
- C1% (1)
- D3% (2)
Explanation
The marked answer of A is incorrect - this appears to be an error in the answer key. C is the correct answer.
Option C is the only syntactically valid MySQL stored function: it returns INT (matching the salary column type), includes the required DETERMINISTIC characteristic, properly declares the local variable with DECLARE msalary INT inside the BEGIN...END block, uses SELECT INTO to capture the result, and returns it cleanly.
Why the distractors fail:
- A returns
CHAR(50)instead ofINT(wrong return type for a salary), and uses a session-scoped user variable@minstead of a properly declared local variable - both are poor practice and the return type mismatch is a logic error. - B includes
USE schemanameinside the function body, which is illegal in MySQL stored routines; it also referencesmsalarywithout declaring it. - D places
DECLAREoutside theBEGIN...ENDblock, which is a syntax error in MySQL - declarations must appear at the top of the block. TheSET msalary = msalaryline is also a no-op.
Memory tip: Think "D-S-R inside BEGIN" - Declare, Select INTO, Return. Everything lives inside BEGIN...END, the return type must match the column type, and DECLARE always comes first inside the block.
Topics
Community Discussion
No community discussion yet for this question.



