如何在MySQL中将子存储过程的更新行数返回到父级?

时间:2017-01-30 09:19:03

标签: mysql stored-procedures

如何在MySQL中将子存储过程的更新行数返回到父级? 使用游标从父级调用子存储过程。

例如:

存储过程1(父):

DECLARE done INT DEFAULT FALSE;
DECLARE _a, _b, _c, VARCHAR(50);
DECLARE Mogambo_Cursor CURSOR FOR
    SELECT a, b, c, FROM tblMogambo;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

OPEN Mogambo_Cursor;    
read_loop: LOOP
    FETCH Mogambo_Cursor INTO _a, _b, _c;
    IF done THEN
        LEAVE read_loop;
    ELSE
        CALL storedProcedure2 (_a, _b, _c);
    END IF;
END LOOP;
CLOSE AdditionalConstraint_Cursor;

存储过程2(孩子):

INSERT IGNORE INTO tblLuke (a, b, c) ....

存储过程2并不总是插入一行。如何知道在存储过程1执行结束时更新了多少行?

我尝试使用@@ ROW_COUNT并使用变量,但无法获得预期的结果。有没有办法获得更新的行?

1 个答案:

答案 0 :(得分:2)

<nav>
    <div id="nav" align="center">
        <div style="display:inline-block">
        <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
        <form class="form">
            <input type="radio" id="male" name="gender" value="male"> Male
            <input type="radio" id="female" name="gender" value="female"> Female
        </form>
        </div>
        <div class = "dropdown" width = "10">
            <div class = "dropdown" width = "10">

            <button class="dropbtn">Clothing</button>
                    <div class="dropdown-content">
                        <a id="formal" href="#formal">Formal</a></br>
                                <a id="maleFormal" style="display:none" href="formalM.html">Male Formal</a>
                                <a id="femaleFormal" style="display:none" href="formalF.html">Female Formal</a>
                        <a id="shirt" href="#shirt">Shirt</a></br>
                                <a id="maleShirt" style="display:none" href="shirtM.html">Male Shirt</a>
                                <a id="femaleShirt" style="display:none" href="shirtF.html">Female Shirt</a>
                        <a id="jeans" href="#jeans">Jeans</a></br>
                                <a id="maleJeans" style="display:none" href="jeansM.html">Pants</a>
                                <a id="femaleJeans" style="display:none" href="jeansF.html">Jeans</a>
                        <a id="shortandskirt" href="#shortandskirt">Short and Skirt</a></br>
                                <a id="maleshortandskirt" style="display:none" href="shorts.html">Shorts</a>
                                <a id="femaleshortandskirt" style="display:none" href="skirts.html">Skirts</a>
                    </div>  
            </div>
            <script>
                $(document).ready(function(){
                    $("#male").click(function(){
                        $("#formal").hide();
                        $("#maleFormal").show();
                        $("#femaleFormal").hide();
                    });
                    $("#female").click(function(){ 
                        $("#formal").hide();
                        $("#maleFormal").hide();
                        $("#femaleFormal").show();
                    });
                });
            </script>

            <script>
                $(document).ready(function(){
                    $("#male").click(function(){
                        $("#shirt").hide();
                        $("#maleShirt").show();
                        $("#femaleShirt").hide();
                    });
                    $("#female").click(function(){ 
                        $("#shirt").hide();
                        $("#maleShirt").hide();
                        $("#femaleShirt").show();
                    });
                });
            </script>

            <script>
                $(document).ready(function(){
                    $("#male").click(function(){
                        $("#jeans").hide();
                        $("#maleJeans").show();
                        $("#femaleJeans").hide();
                    });
                    $("#female").click(function(){ 
                        $("#jeans").hide();
                        $("#maleJeans").hide();
                        $("#femaleJeans").show();
                    });
                });
            </script>

            <script>
                $(document).ready(function(){
                    $("#male").click(function(){
                        $("#shortandskirt").hide();
                        $("#maleshortandskirt").show();
                        $("#femaleshortandskirt").hide();
                    });
                    $("#female").click(function(){ 
                        $("#shortandskirt").hide();
                        $("#maleshortandskirt").hide();
                        $("#femaleshortandskirt").show();
                    });
                });
            </script>

        </div>
        <div class = "dropdown" width = "10">
            <button class="dropbtn">Accesory</button>
                    <div class="dropdown-content">
                        <a href="#ring">Ring</a></br>
                        <a href="#necklace">Necklace</a></br>
                        <a href="#pendant">Pendant</a></br>
                        <a href="#bracelet">Bracelet</a></br>
                        <a href="#eye glasses">Eye Glasses</a></br>
                        <a href="#sun glasses">Sun Glasses</a></br>
                        <a href="#fashion glasses">Fashion Glasses</a></br>
                    </div>  
        </div>
        <div class = "dropdown" width = "10">
            <button class="dropbtn">Shoe</button>
                    <div class="dropdown-content">
                        <a href="#rubber shoes">Rubber Shoes</a></br>
                        <a href="#running shoe">Running Shoe</a></br>
                        <a href="#formal shoe">Formal Shoe</a></br>
                        <a href="#flat shoes">Flat Shoes</a></br>
                        <a href="#high heels">High Heels</a></br>
                        <a href="#sandals">Sandals</a></br>
                    </div>  
        </div>
        <div class = "dropdown" width = "10">
            <button class="dropbtn">Bags</button>
                    <div class="dropdown-content">
                        <a href="#sling bags">Sling bags</a></br>
                        <a href="#backpack">Backpack</a></br>
                        <a href="#office Bags">Office Bags</a></br>
                        <a href="#fahion bags">Fashion bags</a></br>
                        <a href="#gym bag">Gym Bag</a></br>
                    </div>  
        </div>
        <div class = "dropdown" width = "10">
            <button class="dropbtn">Watches</button>
                <div class="dropdown-content">
                        <a href="#rolex">Rolex</a></br>
                        <a href="#swatch">Swatch</a></br>
                        <a href="#timex">Timex</a></br>
                    </div>  

        </div>
        <div class = "dropdown" width = "10">
            <button class="dropbtn">Kids</button>
                <div class="dropdown-content">
                        <a href="#clothing">Clothing</a></br>
                        <a href="#accesory">Accesory</a></br>
                        <a href="#shoe">Shoe</a></br>
                        <a href="#bags">Bags</a></br>
                        <a href="#watch">Watch</a></br>
                    </div>  
        </div>
        <div class = "dropdown" width = "10">
            <button class="dropbtn">Toys</button>
                    <div class="dropdown-content">
                        <a href="#cars">Cars</a></br>
                        <a href="#guns">Guns</a></br>
                        <a href="#kitchen sets">kitchen sets</a></br>
                        <a href="#doll">Doll</a></br>
                        <a href="#doll house">Doll House</a></br>
                        <a href="#stuff toys">Stuff Toy</a></br>
                    </div>  
        </div>
        <div class = "dropdown" width = "10">
            <button class="dropbtn">Unisex</button>
                    <div class="dropdown-content">
                        <a href="#clothing">Clothing</a></br>
                        <a href="#accesory">Accesory</a></br>
                        <a href="#shoe">Shoe</a></br>
                        <a href="#bags">Bags</a></br>
                        <a href="#watch">Watch</a></br>
                    </div>  
        </div>
        <div class = "dropdown" width = "10">
            <button class="dropbtn">Brands</button>
                    <div class="dropdown-content">
                        <a href="#nike">Nike</a></br>
                        <a href="#guess">Guess</a></br>
                        <a href="#humane">Humane</a></br>
                        <a href="#prada">Prada</a></br>
                        <a href="#LV">LV</a></br>
                    </div>  
        </div>
        <div class = "dropdown" width = "10">
            <button class="dropbtn">Deals</button>
                    <div class="dropdown-content">
                        <a href="#50% discounts">50% Discounts</a></br>
                        <a href="#60% discounts">60% Discounts</a></br>
                        <a href="#70% discounts">70% Discounts</a></br>
                        <a href="#free shipping">Free Shipping</a></br>
                        <a href="#coupons">Coupons</a></br>
                    </div>  
        </div>
    </div>
</nav>

如上面的代码所示,您可以为子程序声明一个out参数,并获得该参数的值,您可以计算给定procedure1插入的总行数。 您必须再声明一个变量以将最终的总更新行值作为上面代码中给出的total_count。 您可以使用任何形式获得该值,例如输出变量,或者只使用select from dual进行打印。 希望这会有所帮助。