Error while creating database function in migration file

Posted 2 months ago by muazzamazaz

I am creating a database function through laravel migration script as follows: ` DB::statement(' CREATE or REPLACE FUNCTION plan_status(planid bigint) RETURNS varchar(15) CHARSET latin1 BEGIN DECLARE vcount int;

DECLARE plan_status varchar(15);

SELECT COUNT(*) INTO vcount FROM ticket_purchase WHERE id=planid;

IF vcount >0 THEN SET plan_status= "In Process";

END IF;

SELECT COUNT(*) INTO vcount FROM ticket_delivery WHERE id=planid; if (vcount>0) then set plan_status="Delivered"; end if;

RETURN plan_status; ');`

But it gives me following error:

Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check th e manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 18

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.