-
Notifications
You must be signed in to change notification settings - Fork 0
SQL Procedures
kusum18 edited this page Feb 25, 2013
·
1 revision
DELIMITER $$ DROP PROCEDURE IF EXISTS GetAllPosts$$
CREATE PROCEDURE GetAllPosts()
BEGIN
DECLARE no_more_rows BOOLEAN;
Declare pid,typeid,num_rows int default 0;
Declare p_post varchar(255);
Declare cur_post CURSOR FOR
SELECT posts
.id
,posts
.tags
FROM posts
where posts
.posttypeid
=1 limit 1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_rows = TRUE; open cur_post; select FOUND_ROWS() into num_rows;
the_loop: LOOP FETCH cur_post INTO pid,p_post; insert into tag_post_map2(post_id,tag) values(pid,p_post); IF no_more_rows THEN close cur_post; leave the_loop; END IF; END LOOP the_loop; END$$
DELIMITER ;