Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. PL/MySQL - No data - zero rows fetched, selected, or processed

PL/MySQL - No data - zero rows fetched, selected, or processed

Scheduled Pinned Locked Moved Database
databasemysqlhelptutorialcareer
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    noislude
    wrote on last edited by
    #1

    Hi. When I try to run the following code, I get the error I wrote in the subject.

    delimiter //
    drop procedure if exists example_cursor;
    create procedure example_cursor() reads sql data
    begin
    -- declare variables
    declare var_wage numeric(8,2);
    declare var_employee_id int;
    declare var_department_id int;

    -- declarar done state
    declare done int default 0;
    
    -- create cursor for table
    declare cur1 cursor for
    select employee\_id, salary, department\_id from employees;
    
    -- set done to 1 if data wasn't found
    declare continue handler for not found set done = 1;
    
    -- open cursor
    open cur1;
    -- start loop
    emp\_loop:loop
       -- get data from cursor
       fetch cur1 into var\_employee\_id, var\_wage, var\_department\_id;
    if(done = 1) then
       leave emp\_loop;
     end if;
    end loop emp\_loop;
    -- close cursor
    close cur1;
    

    end;
    //

    CREATE TABLE `employees` (
    `EMPLOYEE_ID` int(11) NOT NULL auto_increment,
    `SURNAME` varchar(40) NOT NULL,
    `FIRSTNAME` varchar(40) NOT NULL,
    `ADDRESS1` varchar(40) NOT NULL,
    `ADDRESS2` varchar(40) NOT NULL,
    `ZIPCODE` varchar(6) NOT NULL,
    `DATE_OF_BIRTH` datetime NOT NULL,
    `PHONENO` varchar(12) NOT NULL,
    `MANAGER_ID` decimal(8,0) NOT NULL,
    `SALARY` decimal(8,0) NOT NULL,
    `STATUS` varchar(9) NOT NULL,
    `DEPARTMENT_ID` decimal(8,0) default NULL,
    `COMMENT_ID` decimal(8,0) default NULL,
    `DEPARTMENT_NAME` varchar(40) default NULL,
    `ADJUSTED_SALARY` decimal(8,0) default NULL,
    `HIRE_DATE` datetime default NULL,
    PRIMARY KEY (`EMPLOYEE_ID`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

    G 1 Reply Last reply
    0
    • N noislude

      Hi. When I try to run the following code, I get the error I wrote in the subject.

      delimiter //
      drop procedure if exists example_cursor;
      create procedure example_cursor() reads sql data
      begin
      -- declare variables
      declare var_wage numeric(8,2);
      declare var_employee_id int;
      declare var_department_id int;

      -- declarar done state
      declare done int default 0;
      
      -- create cursor for table
      declare cur1 cursor for
      select employee\_id, salary, department\_id from employees;
      
      -- set done to 1 if data wasn't found
      declare continue handler for not found set done = 1;
      
      -- open cursor
      open cur1;
      -- start loop
      emp\_loop:loop
         -- get data from cursor
         fetch cur1 into var\_employee\_id, var\_wage, var\_department\_id;
      if(done = 1) then
         leave emp\_loop;
       end if;
      end loop emp\_loop;
      -- close cursor
      close cur1;
      

      end;
      //

      CREATE TABLE `employees` (
      `EMPLOYEE_ID` int(11) NOT NULL auto_increment,
      `SURNAME` varchar(40) NOT NULL,
      `FIRSTNAME` varchar(40) NOT NULL,
      `ADDRESS1` varchar(40) NOT NULL,
      `ADDRESS2` varchar(40) NOT NULL,
      `ZIPCODE` varchar(6) NOT NULL,
      `DATE_OF_BIRTH` datetime NOT NULL,
      `PHONENO` varchar(12) NOT NULL,
      `MANAGER_ID` decimal(8,0) NOT NULL,
      `SALARY` decimal(8,0) NOT NULL,
      `STATUS` varchar(9) NOT NULL,
      `DEPARTMENT_ID` decimal(8,0) default NULL,
      `COMMENT_ID` decimal(8,0) default NULL,
      `DEPARTMENT_NAME` varchar(40) default NULL,
      `ADJUSTED_SALARY` decimal(8,0) default NULL,
      `HIRE_DATE` datetime default NULL,
      PRIMARY KEY (`EMPLOYEE_ID`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

      G Offline
      G Offline
      GuyThiebaut
      wrote on last edited by
      #2

      Have a look at this PL/SQL cursor example[^]. The example towards the bottom may help(Cursor with a While Loop).

      “That which can be asserted without evidence, can be dismissed without evidence.”

      ― Christopher Hitchens

      N 2 Replies Last reply
      0
      • G GuyThiebaut

        Have a look at this PL/SQL cursor example[^]. The example towards the bottom may help(Cursor with a While Loop).

        “That which can be asserted without evidence, can be dismissed without evidence.”

        ― Christopher Hitchens

        N Offline
        N Offline
        noislude
        wrote on last edited by
        #3

        thanks for the attention GuyThiebaut, I solved the problem.

        1 Reply Last reply
        0
        • G GuyThiebaut

          Have a look at this PL/SQL cursor example[^]. The example towards the bottom may help(Cursor with a While Loop).

          “That which can be asserted without evidence, can be dismissed without evidence.”

          ― Christopher Hitchens

          N Offline
          N Offline
          noislude
          wrote on last edited by
          #4

          Thanks GuyThiebaut. I Solved the problem even with the warning: I just printed the content with concat.

          delimiter //
          drop procedure if exists sp_exemplo_cursor;

          create procedure sp_exemplo_cursor() reads sql data
          begin
          declare var_salario numeric(8,2);
          declare var_empregado_id int;
          declare var_departamento_id int;
          declare flag_nao_encontrado int default 0;

          declare csr cursor for
          select employee_id, salary, department_id from employees;

          declare continue handler for not found set flag_nao_encontrado = 1;

          open csr;
          exemplo_loop:loop
          fetch csr into var_empregado_id, var_salario, var_departamento_id;
          if flag_nao_encontrado = 1 then
          leave exemplo_loop;
          end if;
          select concat(var_empregado_id, ' ', var_salario, ' ', var_departamento_id);
          end loop exemplo_loop;
          close csr;
          end //

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups