Results 1 to 2 of 2

Thread: MYSQL Cursor doesnt working when inside select is null

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    58

    MYSQL Cursor doesnt working when inside select is null

    I have this stored procedure

    CREATE PROCEDURE `spCar`()
    begin
    declare exit1 int default 0;
    declare rec1 char(50);
    declare rec2 char(50);
    declare vgas int;
    declare cur1 cursor for select distinct car,driver from dates;
    declare exit handler for not found set exit1=1;
    open cur1;
    repeat
    fetch cur1 into rec2,rec1;

    -- select gas into vgas from someTable where car=rec2 and driver=rec1;
    select rec2,rec1,c_rest;

    until exit1=1 end repeat;
    close cur1;
    end


    if I uncommnet the line above ... the sp will not show anything if at some point the vgas variable is null

    if I leave it commented will display the right number of records but I need my sp with vgas variable ... and this variable might be null at some point

  2. #2
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: MYSQL Cursor doesnt working when inside select is null

    I don't know much about stored procedures. May be you could try
    Code:
    SELECT IFNULL(gas, 0) INTO vgas FROM someTable WHERE car=rec2 AND driver=rec1;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width