MySQL 我们如何在存储过程中使用 mysql_affected_rows()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4458264/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How we can use mysql_affected_rows() in stored procedure
提问by Null Pointer
How we can use mysql_affected_rows()
in stored procedure..
我们如何mysql_affected_rows()
在存储过程中使用..
回答by martin clayton
Use the ROW_COUNT()information function.
使用ROW_COUNT()信息函数。
ROW_COUNT() returns the number of rows changed, deleted, or inserted by the last statement if it was an UPDATE, DELETE, or INSERT. For other statements, the value may not be meaningful.
The ROW_COUNT() value is the same as the value from the mysql_affected_rows() C API function and the row count that the mysql client displays following statement execution.
ROW_COUNT() 返回由最后一条语句更改、删除或插入的行数(如果它是 UPDATE、DELETE 或 INSERT)。对于其他语句,该值可能没有意义。
ROW_COUNT() 值与来自 mysql_affected_rows() C API 函数的值以及 mysql 客户端在语句执行后显示的行数相同。
回答by egemen
example
例子
BEGIN
DECLARE countRow INT;
DECLARE roomTypeId INT;
INSERT INTO room_type (room_type)
SELECT * FROM (SELECT paramRoomType) AS tmp
WHERE NOT EXISTS (
SELECT room_type_id FROM room_type WHERE room_type = paramRoomType
) LIMIT 1;
SET countRow = ROW_COUNT();
IF(countRow > 0) THEN
SET roomTypeId = LAST_INSERT_ID();
INSERT hotel_has_room_type (hotel_id,room_type_id) VALUES (paramHotelId,roomTypeId);
END IF;
END