MySQL Forums
Forum List  »  Stored Procedures

Display all the records from table using cursor
Posted by: kaji Pasa
Date: September 22, 2017 06:21PM

Hello, I am new in cursor,
I am trying to fetch all the records form a table using cursor. Here is my code , i am able do display the first row only.
how can i display all the rows


DELIMITER $$
CREATE PROCEDURE build_title_list (INOUT title_list varchar(4000),INOUT st varchar(4000))
BEGIN
DECLARE v_finished INTEGER DEFAULT 0;
DECLARE v_title varchar(100) DEFAULT "";
DECLARE v_st varchar(100) DEFAULT "";


DEClARE title_cursor CURSOR FOR
SELECT StandardTitle,Title_sci FROM master_data;


DECLARE CONTINUE HANDLER
FOR NOT FOUND SET v_finished = 1;

OPEN title_cursor;

get_title: LOOP
FETCH title_cursor INTO v_title,v_st;
IF v_finished = 1 THEN
LEAVE get_title;
END IF;
SET title_list = v_title;
set st= v_st;
END LOOP get_title;
CLOSE title_cursor;
END$$

DELIMITER ;

call build_title_list(@title_list,@st);
select @title_list,@st

Below is the output.



output
---------------------------------------------------------------
AMERICANJOURNALOFEDUCATION American Journal of Education
___________________________________________________________________

Options: ReplyQuote


Subject
Views
Written By
Posted
Display all the records from table using cursor
3930
September 22, 2017 06:21PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.