นำคำสั่งนี้ไป Run ใน MySQL หรือที่สายฟ้า เสร็จแล้ว Restart MySQL
CREATE FUNCTION get_serialnumber(param1 varchar(150)) RETURNS int(11)
begin declare serial_exist int; declare xserial_no int; if param1='' then select 'test' into param1; end if; select count(serial_no) into serial_exist from serial where name = param1; if serial_exist = 0 then insert into serial (name,serial_no) values (param1,0); end if; update serial set serial_no = serial_no + 1 where name = param1; select serial_no into xserial_no from serial where name = param1; return xserial_no; end