In short: a COMMIT or ROLLBACK
inside a stored procedure actually impacts the outside transaction in which the procedure was called. ROLLBACK is a bit of a special case, however. You can (and probably should) set a savepoint and then roll back to that savepoint only.
As to your question: you don't need a ROLLBACK here:
Code:
IF pid = -1 THEN
--------- ROLLBACK; ------- ( Do I need this??? ) --> NO
SET errormsg = 'Error : Failed to lookup id';
RETURN;
END IF;
The reason is that you only did a SELECT and no data modifications. So no data changes need to be un-done. The only thing a ROLLBACK would achieve is to release any locks, depending on the isolation level.