GOTO Statement - Oracle to MariaDB Migration

In Oracle, the GOTO statement allows you to unconditionally jump to a specified part of the code.

MariaDB does not support the GOTO statement, but you can use the LEAVE statement with a labeled BEGIN-END block.

Oracle:

  -- A sample procedure
  CREATE OR REPLACE PROCEDURE sp1
  AS
  BEGIN
    DBMS_OUTPUT.PUT_LINE('A');
 
    GOTO label;
    DBMS_OUTPUT.PUT_LINE('B');
 
    <<label>>
    DBMS_OUTPUT.PUT_LINE('C');
  END;
  /

MariaDB:

  DROP PROCEDURE IF EXISTS sp1;
 
  DELIMITER //
 
  -- A sample procedure
  CREATE PROCEDURE sp1()
  BEGIN
    label: BEGIN
      SELECT 'A' AS '';
 
      LEAVE label;
      SELECT 'B' AS '';
 
      END; -- <<label>>
    SELECT 'C' AS '';
  END;
  //
 
  DELIMITER ;

For more information, see Oracle to MariaDB Migration.