2014-02-14 5 views
0

단일 통화에 저장 프로 시저를하고 그것을 잘 작동하고 :여러 MySQL은이 같은 저장 프로 시저를

$drop = $mysqli->query("DROP PROCEDURE IF EXISTS changegroup"); 
$initiate = $mysqli->query(" 
    Create Procedure changegroup(IN param1 int(10),IN param2 int(10)) 
    BEGIN 
     UPDATE t_parts SET part_group_id = param2 WHERE part_id = param1; 
    END; 
"); 
$result = $mysqli->query("CALL changegroup($p1,$p2);"); 

내 질문은, 우리는 하나의 절차에서 두 개의 SQL 문을 넣을 수 있습니다 및 기반 두 번째 프로 시저를 실행 에이 같은 첫 번째 : 저장 프로 시저에서

BEGIN 
    SELECT * FROM ........ 
    /**fetch the result of this mysql statment and if matches certain conditions,then execute the update statment***/ 

    UPDATE t_parts SET part_group_id = param2 WHERE part_id = param1; 
END; 

답변

1

if <condition> then 
    your code 
end if; 

그래서 코드 말아야 쓰기 d 이렇게 말하십시오

Create Procedure changegroup(IN param1 int(10),IN param2 int(10)) 
BEGIN 
    DECLARE totalcount Integer default 0; 
    SELECT count(*) into totalcount FROM yourtable where <condition>; 
    /**fetch the result of this mysql statment and if matches certain conditions,then execute the update statment***/ 
    if(totalcount > 0) then 
    UPDATE t_parts SET part_group_id = param2 WHERE part_id = param1; 
    end if; 
END; 
+0

감사합니다. 시도해보십시오. – coolguy

관련 문제