How to create function using another functions mysql I want to create a function in MySQL using another function but I am getting an error "Explicit or implicit commit is not allowed in stored function or trigger".

This is my code:

DELIMITER $$

CREATE FUNCTION `ufn_gettotalavg` (pUserID bigint,pclass bigint) RETURNS int(11)
BEGIN
  DECLARE learnavg BIGINT;
  DECLARE Assesavg BIGINT;
  DECLARE Pratiecavg BIGINT;
  DROP TABLE IF EXISTS AvgTemp;
  CREATE TEMPORARY TABLE IF NOT EXISTS AvgTemp (SType varchar(20),Percentage bigint);
  DROP TABLE IF EXISTS  assesTemp;
  CREATE TEMPORARY TABLE IF NOT EXISTS assesTemp AS (SELECT  COALESCE(ROUND(((SELECT uf_GetTotalScoreByAssessment( AssessmentID,pUserID,1)) /
  (SELECT ufn_getMaxMarks( AssessmentID))) * 100),0) AS Percentage FROM tr_t_assessments where AssessmentType='LiveTest');
  SET Assesavg= (SELECT COALESCE(round(AVG(Percentage)),0) FROM assesTemp);
  DROP TABLE IF EXISTS  learnTemp;
  CREATE TEMPORARY TABLE IF NOT EXISTS   learnTemp AS (SELECT IFNULL(ROUND((SELECT count(MaterialID) FROM tr_t_materialtracking 
  where MaterialStatus=1 and UserID=pUserID and SubjectID = S.SubjectID and MaterialID in 
  (SELECT MaterialID FROM tr_m_material where ClassID=pclass and SubjectID = S.SubjectID)) /
  (SELECT COUNT(TopicID) FROM tr_m_material where TopicID IN 
  (SELECT TopicID FROM tr_m_subjecttopics where SubjectID = S.SubjectID))* 100) ,0) AS Percentage
  FROM tr_m_subjects S WHERE Status = 1 AND SubjectID IN (SELECT SubjectID FROM tr_m_subjects where ClassID=pclass));
  SET learnavg= (SELECT round(AVG(Percentage)) FROM learnTemp);
  DROP TABLE IF EXISTS  PratiecTemp;
  CREATE TEMPORARY TABLE IF NOT EXISTS PratiecTemp AS (SELECT COALESCE(ufn_getPracticePercentage(pUserID,pclass,S.SubjectID),0) as Percentage   
  FROM tr_m_subjects S WHERE Status = 1 AND SubjectID IN (SELECT SubjectID FROM tr_m_subjects where ClassID=pclass)) ;
  SET Pratiecavg= (SELECT ROUND(AVG(Percentage)) FROM PratiecTemp); 
  INSERT INTO AvgTemp(SType ,Percentage) VALUES('Learn',learnavg);
  INSERT INTO AvgTemp(SType ,Percentage) VALUES('Pratice',Pratiecavg);
  INSERT INTO AvgTemp(SType ,Percentage) VALUES('Assess',Assesavg);
RETURN (SELECT ROUND(AVG(Percentage)) as consolidatedAvg FROM AvgTemp);
END
Instead of DROP + CREATE, simply do TRUNCATE TABLE.  That should avoid the error about COMMIT.

Drawback:  Other code would need to originally do the CREATE and DROP.