tags:

views:

23

answers:

2

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?

A: 

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

Haim Evgi
Thank you sir.. This was what I needed to know.. :) I was unclear if INTO was only used when calculations or other operations were needed but I can see that INTO is always used.
jim
One more question.. Do I need to specify OUT?
jim
Thanks for the link, it answeres my last question as well. Cheers.
jim
wellcome :))))))
Haim Evgi
A: 

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.

MindStalker