3

MySQL ストアド プロシージャを作成したい

DELIMITER $$

DROP PROCEDURE IF EXISTS `SECTOR_INDUSTRY_SP` $$
CREATE PROCEDURE `SECTOR_INDUSTRY_SP`(IN RINSERIES TEXT, IN COMMUNITYIDS TEXT)
    READS SQL DATA
BEGIN
SELECT *
from PROFESSIONAL_IDENTITY_MERGED p , std_company_detail s
where (p.pim_company_id = s.cid) AND p.pim_community_id IN  ('+'+COMMUNITYIDS+'+')
AND p.pim_rin IN  ('+'+RINSERIES+'+');

END $$

DELIMITER ;

ご覧のとおり、このプロシージャ RINSERIES を呼び出す引数が 2 つあります。これは、'12312,1234,1239' のようなテキスト形式になります。

SELECT *
    from PROFESSIONAL_IDENTITY_MERGED p , std_company_detail s
    where (p.pim_company_id = s.cid) AND p.pim_community_id IN  ('12312,1234,1239')
    AND p.pim_rin IN  ('2,5,8');

しかし、このクエリを次のようにしたい

SELECT *
        from PROFESSIONAL_IDENTITY_MERGED p , std_company_detail s
        where (p.pim_company_id = s.cid) AND p.pim_community_id IN  (12312,1234,1239)
        AND p.pim_rin IN  (2,5,8);

これどうやってするの?ありがとう!

4

1 に答える 1

3

これを試して:

DELIMITER $$

DROP PROCEDURE IF EXISTS `SECTOR_INDUSTRY_SP` $$
CREATE PROCEDURE `SECTOR_INDUSTRY_SP`(IN RINSERIES TEXT, IN COMMUNITYIDS TEXT)
    READS SQL DATA
BEGIN

SET @s = CONCAT("SELECT *
from PROFESSIONAL_IDENTITY_MERGED p , std_company_detail s
where (p.pim_company_id = s.cid) AND p.pim_community_id IN  (", COMMUNITYIDS, ")
AND p.pim_rin IN  (",RINSERIES,")");

PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

END $$

DELIMITER ;
于 2012-11-09T07:13:52.913 に答える