简体   繁体   中英

Return count of processed rows with mysql dynmic query

I have written a mysql dynamic query to insert data from a database to another database. here is the query.

CREATE DEFINER=`Definer1`@`%` PROCEDURE `PushData`()
BEGIN
Set @SqlQuery = 'Insert Into Table_A (Column1,Column2,Column3)
                    Select Column1,Column2,Column3
                    From Table_B
                    Where Table_B.Column1=1;';
PREPARE  Statement From @SqlQuery;
EXECUTE Statement;  
DEALLOCATE PREPARE Statement; 
Select Count(*); -- Count of Inserted Rows
End

This Query will send data from Table_B to Table_A. in last i want to return the count of inserted rows. How do i do it. I know it is easy when i am not using dynamic query. it's just assign the count to a variable and use it with select syntax. but i have no idea how to do it with dynamic query. can someone suggest?

To return the number of rows affected by an INSERT or an UPDATE query, use ROW_COUNT() . So replace

Select Count(*);

with

SELECT ROW_COUNT();

SQL%rowcount can be used to fetch the number of records inserted. May be below link could be of help.

https://community.oracle.com/thread/2370954?start=0&tstart=0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM