I tried this way:
CREATE FUNCTION `num_friends`(id int) RETURNS int(11) DETERMINISTIC BEGIN declare res int; select id into res from friend