Truncate table with a stored procedure in Mariadb

82 Views Asked by At

I need to truncate a table with a stored procedure. Here is the code for the stored procedure:

DELIMITER //
CREATE PROCEDURE MA_ClearPenaltyExport

BEGIN

   TRUNCATE TABLE MA_STG_PenaltyExport;
    
END //
DELIMITER ;

but I'm getting an error as #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'BEGIN

   TRUNCATE TABLE MA_STG_PenaltyExport;
    
END' at line 3
2

There are 2 best solutions below

1
Surya On
DELIMITER $$ 
CREATE OR REPLACE DEFINER=dbadmin@% PROCEDURE MA_ClearPenaltyExport( ) 
BEGIN 
TRUNCATE MA_STG_PenaltyExport; 
END$$
 DELIMITER ;
0
danblack On

A its a single statement in the procedure the following also works:

CREATE PROCEDURE MA_ClearPenaltyExport()
TRUNCATE TABLE MA_STG_PenaltyExport;