如何计算存储过程的结果

时间:2013-02-21 10:56:05

标签: mysql

程序运作正常。我需要的是对行程结果进行行计数。

DROP PROCEDURE `tradematch`//
CREATE DEFINER=`root`@`localhost` PROCEDURE `tradematch`(IN `pid` INT)
BEGIN 
SELECT p.company_name,p.company_info,pc.contact_address,pc.mobilenumber,p.idprofile,b.businesstype 
FROM profile p,profile_contact pc,businesstypelkp b 
WHERE p.idprofile=pc.idprofile_contact 
AND p.business_type=b.idbusinessTypeLKP 
AND p.idprofile not in (SELECT p.idprofile FROM profile p WHERE FIND_IN_SET(idprofile,(select Group_Concat(member_list) as group_members from groupmemberlkp where profile_id=pid))) AND FIND_IN_SET(idprofile,(SELECT group_concat(p.profileid) from products_profile p where FIND_IN_SET(product_id,(SELECT group_concat(product_id) FROM `rawmaterial_profile` WHERE profileid=pid))AND p.profileid!=pid));
END//

1 个答案:

答案 0 :(得分:0)

您可以使用OUT参数和SQL_CALC_FOUND_ROWS< - > FOUND_ROWS()组合。您可以阅读更多相关信息here

DROP PROCEDURE `tradematch`//
CREATE DEFINER=`root`@`localhost` PROCEDURE `tradematch`(IN `pid` INT, OUT result INT)
BEGIN 
SELECT SQL_CALC_FOUND_ROWS p.company_name,p.company_info,pc.contact_address,pc.mobilenumber,p.idprofile,b.businesstype 
FROM profile p,profile_contact pc,businesstypelkp b 
WHERE p.idprofile=pc.idprofile_contact 
AND p.business_type=b.idbusinessTypeLKP 
AND p.idprofile not in (SELECT p.idprofile FROM profile p WHERE FIND_IN_SET(idprofile,(select Group_Concat(member_list) as group_members from groupmemberlkp where profile_id=pid))) AND FIND_IN_SET(idprofile,(SELECT group_concat(p.profileid) from products_profile p where FIND_IN_SET(product_id,(SELECT group_concat(product_id) FROM `rawmaterial_profile` WHERE profileid=pid))AND p.profileid!=pid));

SET result:=FOUND_ROWS();

END//

然后执行查询时:

CALL yourProcedure(yourId, @whatever);
SELECT @whatever;

这样过程显示结果,第二个SELECT得到行数。如果您不需要显示查询结果,那么问题是,如果您需要存储过程。