Select Into Question for Stored Procedure

This is a discussion on Select Into Question for Stored Procedure within the MySQL Database forums, part of the Database Forums category; I am doing a select into a list of variables, but I don't know how to tell if the ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-18-2007
Tony
 
Posts: n/a
Default Select Into Question for Stored Procedure

I am doing a select into a list of variables, but I don't know how to
tell if the select returns no rows, in which case I don't want to
proceed. Is there a success value or other technique?

Thanks!
Tony

Reply With Quote
  #2 (permalink)  
Old 10-18-2007
Peter H. Coffin
 
Posts: n/a
Default Re: Select Into Question for Stored Procedure

On Thu, 18 Oct 2007 08:18:51 -0700, Tony wrote:
> I am doing a select into a list of variables, but I don't know how to
> tell if the select returns no rows, in which case I don't want to
> proceed. Is there a success value or other technique?


Some language libraries have a function for determining how many rows
are returned in a data set. Others may leave you to do something like

result_set = execute_mysql_query(my_query)
WHILE (my_row = get_mysql_row(result_set) IS SUCCESSFUL)
DO stuff in a loop
DONE

--
50. My main computers will have their own special operating system that will
be completely incompatible with standard IBM and Macintosh powerbooks.
--Peter Anspach's list of things to do as an Evil Overlord
Reply With Quote
  #3 (permalink)  
Old 10-18-2007
Tony
 
Posts: n/a
Default Re: Select Into Question for Stored Procedure

On Oct 18, 11:42 am, "Peter H. Coffin" <hell...@ninehells.com> wrote:
> On Thu, 18 Oct 2007 08:18:51 -0700, Tony wrote:
> > I am doing a select into a list of variables, but I don't know how to
> > tell if the select returns no rows, in which case I don't want to
> > proceed. Is there a success value or other technique?

>
> Some language libraries have a function for determining how many rows
> are returned in a data set. Others may leave you to do something like
>
> result_set = execute_mysql_query(my_query)
> WHILE (my_row = get_mysql_row(result_set) IS SUCCESSFUL)
> DO stuff in a loop
> DONE
>
> --
> 50. My main computers will have their own special operating system that will
> be completely incompatible with standard IBM and Macintosh powerbooks.
> --Peter Anspach's list of things to do as an Evil Overlord


I am in a stored procedure, so no PHP or other functions are
available. Just native MySQL operations. Thanks, Tony

Reply With Quote
  #4 (permalink)  
Old 10-18-2007
lark
 
Posts: n/a
Default Re: Select Into Question for Stored Procedure

== Quote from Tony (google@sendto.org)'s article
> On Oct 18, 11:42 am, "Peter H. Coffin" <hell...@ninehells.com> wrote:
> > On Thu, 18 Oct 2007 08:18:51 -0700, Tony wrote:
> > > I am doing a select into a list of variables, but I don't know how to
> > > tell if the select returns no rows, in which case I don't want to
> > > proceed. Is there a success value or other technique?

> >
> > Some language libraries have a function for determining how many rows
> > are returned in a data set. Others may leave you to do something like
> >
> > result_set = execute_mysql_query(my_query)
> > WHILE (my_row = get_mysql_row(result_set) IS SUCCESSFUL)
> > DO stuff in a loop
> > DONE
> >
> > --
> > 50. My main computers will have their own special operating system that will
> > be completely incompatible with standard IBM and Macintosh powerbooks.
> > --Peter Anspach's list of things to do as an Evil Overlord

> I am in a stored procedure, so no PHP or other functions are
> available. Just native MySQL operations. Thanks, Tony


what you need is a condition and a handler. the following will set a phoney
sqlstate (there is one for no record found). if mysql hits that sqlstate it'll set
the exit_loop to 1, you'd check that in your logic and exit accordingly and move
on to the next record.

DECLARE CONTINUE HANDLER FOR SQLSTATE '999999' SET exit_loop = 1; DECLARE CONTINUE
HANDLER FOR SQLSTATE '939999'
BEGIN
statement_list
END;



--
POST BY: lark with PHP News Reader ;o)
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:24 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0