I'm trying to build a mysql function which inserts values into a table and returns me the last_id inserted, which should be the same after executing the insertion. But Xampp gives me an error in the line where im declaring the "last_bill_id" variable. Can someone please help me to understand what am I doing wrong?
Here is the code for the function:
CREATE FUNCTION insert_bill(
client_id varchar (12),
bill_date date
) RETURNS INT
BEGIN
DECLARE last_bill INT;
INSERT INTO bill
(
client_id, bill_date
)
VALUES
(
client_id, bill_date
);
SET last_bill = LAST_INSERT_ID();
RETURN last_bill;
END $$
DELIMITER ;
Error: #1064 - Something is wrong about 'INT