想要从这个游标,存储过程返回数据集

时间:2018-01-23 07:55:08

标签: mysql database stored-procedures

我正在处理这个存储过程,任何正文都可以帮我从这个程序中获取数据集。

*使用名为list_g的变量条目创建存储过程 这是程序(见附件):

然后:

*=at
SET *list = "";
CALL getNodes(*list);
select *list;

以下是存储过程:

BEGIN
DECLARE done1, done2 BOOLEAN DEFAULT FALSE; 
DECLARE row1 varchar(900) default "";
DECLARE parentId INTEGER;

DECLARE cur1 CURSOR FOR SELECT idIncidence FROM incidence
WHERE DATE(dateTimeIn_dt)='2018-01-18' and hour(TIME(dateTimeIn_dt)) 
BETWEEN '08' and '15';

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done1 = TRUE;

open cur1;
loop1: LOOP

FETCH  cur1 INTO parentId;
IF done1 THEN
    CLOSE cur1;
    LEAVE loop1;
END IF;
 set list_g=CONCAT(parentId,";",list_g);
BLOCK1 : BEGIN
DECLARE cur2 CURSOR FOR SELECT 
a.idIncidence,DATE_FORMAT(dateTimeIn_dt,'%H:%i:%s') as dateTimeIn_dt,0 
as conteo, a.classification_str,measure_n,a.keyNode_str_fk,(
           SELECT GROUP_CONCAT( nameStation_str SEPARATOR ', ') AS 
idStation
    FROM ( 
    SELECT nameStation_str, 
    ( 6371 * acos(cos(radians((SELECT lat from incidence where 
idIncidence =@parentId))) * cos(radians(lat_str)) * 
cos(radians(lon_str) - radians((SELECT lon from incidence where 
idIncidence =@parentId))) + sin(radians((SELECT lat from incidence 
where idIncidence =@parentId))) * sin(radians(lat_str)))      )                     
    AS distance
    FROM station HAVING distance < 0.01 ORDER BY distance
    ) as s
     )as 
 idStation_fk,kp.kindProtective_str,m.nameModel_str 
 ,pa.keyArea_n,kp.idKinProtector FROM incidence a 
     JOIN node n on a.keyNode_str_fk=n.keyNode_str 
     JOIN protective pr on n.idProtective_fk=pr.idProtective 
     JOIN kindProtector kp on pr.idKindProtector_fk=kp.idKinProtector 
     JOIN model m on pr.idModel_fk=m.idModel 
     JOIN station st on a.idStation_fk =st.idStation 
     JOIN branch br on st.idBranch_fk=br.idBranch 
     JOIN ship sh on br.idShip_fk=sh.idShip
     JOIN protectiveArea pa on n.idProtectiveArea=pa.idProtectiveArea
     WHERE DATE(dateTimeIn_dt)='2018-01-18' and 
hour(TIME(dateTimeIn_dt)) BETWEEN '08' and '15';

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done2 = TRUE;

OPEN cur2;
loop2 : LOOP

if done2 THEN
    CLOSE cur2;
    SET done2 = FALSE;
    LEAVE loop2;
    END IF;


END LOOP loop2;
END BLOCK1;
END loop loop1;
END

我需要从查询中返回所有数据集 请帮我解决这个问题。这是我的表名: 分支,品牌,group_node,发生率,kindProtector,模型,节点,植物,保护,protectiveArea,protectiveGroup,传感器,班次,船舶,站,用户。

0 个答案:

没有答案