Do I need to specify the INTO
parameter for every column I want sent out of the procedure?
If I have the following:
SELECT col1, col2, col3, col4
FROM
table
WHERE
col1 = 'something'
Do I need to specify INTO for each column?
Do I need to specify the INTO
parameter for every column I want sent out of the procedure?
If I have the following:
SELECT col1, col2, col3, col4
FROM
table
WHERE
col1 = 'something'
Do I need to specify INTO for each column?
yes , see example
BEGIN
SELECT password ,
active_flg ,
lastname ,
firstname ,
gender_code ,
birth_dttm
INTO p_password ,
p_active_flg ,
p_lastname ,
p_firstname ,
p_gender_code ,
p_birth_dttm
FROM students
WHERE student_id = p_student_id ;
END
take from link : http://www.sqlinfo.net/mysql/mysql_stored_procedure_SELECT.php
It depends upon what you are trying to achieve.
CREATE PROCEDURE testproc ()
BEGIN
SELECT col1, col2, col3, col4
FROM
table
WHERE
col1 = 'something'
END;
Will return results similar to SELECTing a table, you can get multiple rows, returned.
CREATE PROCEDURE testproc (OUT col1 INT, OUT col2 VARCHAR(255), OUT col3 INT, OUT col4 INT)
BEGIN
SELECT col1, col2, col3, col4 INTO col1, col2, col3, col4
FROM
table
WHERE
col1 = 'something'
END;
Can ONLY return 1 row, and you call it like so CALL testproc(@col1, @col2, @col3, @col4); nothing is returned visable, though the variables are set, these variables can be used in other queries or just called together SELECT @col1, @col2, @col3, @col4; OR
SELECT blah from othertable where col2=@col2;
Your stored procedure can also contain multiple selects where it uses those variables internally for inputs into new selects, with IF THENs etc, etc.