How we can use mysql_affected_rows() in stored procedure

后端 未结 3 1812
清酒与你
清酒与你 2021-02-07 04:13

How we can use mysql_affected_rows() in stored procedure..

相关标签:
3条回答
  • 2021-02-07 04:47

    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
    
    0 讨论(0)
  • 2021-02-07 05:03

    Use the ROW_COUNT() information function.

    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.

    0 讨论(0)
  • 2021-02-07 05:03

    You cannot use mysql_affected_rows() in a stored procedure since it's a C API function. You can use FOUND_ROWS() function which gives a similar functionality. Refer this link for more details.

    0 讨论(0)
提交回复
热议问题