Jump to content

Recommended Posts

Hi all

 

I have 2 question's.

Recently I have started trying to impliment stored procedures in our application, but am having a little trouble learning everything. My first question is can a stored procedure return more than one record. In other words, if I had a stored procedure, that fetched all the records from a table, could I get all the records returned from the stored procedure?

 

DELIMITER $$

DROP PROCEDURE IF EXISTS `test`.`p2` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `p2`(OUT user_ids INTEGER(10))
BEGIN
  SELECT DISTINCT user_id INTO user_ids
  FROM users;
END $$

DELIMITER ;

 

Lets assume this is my simple stored procedure, I call it like so

CALL p2(@var);

 

And get the following error message

"Error 1172: Result consisted of more than one row"

 

Can anyone help?

 

My second question isn't really a stored procedures question, but more of a query related question.

Lets assume I have a users table, with a user_id column.

I then have a user_group table, with a user_id, and group_id column.

Given that a group can be any size (ie there can be multiple records in the user_group table for a given group) how can I check if a group exists, given the user_id's? And if the group does exist, return the group_id?

 

Can any one help?

 

Thanks in advance ;)

Link to comment
https://forums.phpfreaks.com/topic/78906-stored-procedures/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.