Create a stored procedure "ll" has 1 input value aid. The following tables exist in…
- User
Create a stored procedure "ll" has 1 input value a_id. The following tables exist in MySQL database. The "aaa" table has the following columns a_id as int, ar_id as int, o_id as int, p_id as int. The "pa_a" table has the following columns p_id as int, a_id as int. The stored procedure "ll" should get the records from tables aaa and pa_a in the following manner: a_id should match the value in "aaa" table a_id column and p_id from "aaa" table should match p_id table in "pa_a" table p_id column. The result shuold contain a joint result of these two tables.
- Assistant
DELIMITER //
CREATE PROCEDURE ll(IN a_id INT) BEGIN SELECT * FROM aaa INNER JOIN pa_a ON aaa.p_id = pa_a.p_id WHERE aaa.a_id = a_id; END//
DELIMITER ;
- User
optimize the "SELECT *" row so each selected name would be appended with word "my_param_"
- Assistant
DELIMITER //
CREATE PROCEDURE ll(IN a_id INT) BEGIN SELECT aaa.a_id AS my_param_a_id, aaa.ar_id AS my_param_ar_id, aaa.o_id AS my_param_o_id, aaa.p_id AS my_param_p_id, pa_a.p_id AS my_param_pa_a_p_id, pa_a.a_id AS my_param_pa_a_a_id FROM aaa INNER JOIN pa_a ON aaa.p_id = pa_a.p_id WHERE aaa.a_id = a_id; END//
DELIMITER ;
In this modified stored procedure, each selected name will be appended with the prefix "my_param_". This will make it easier to distinguish which columns are related to the stored procedure and which are not.
- User
thank you
- Assistant
You're welcome! Let me know if you have any more questions or need further assistance.