Syntax\n------\n\nCREATE [ OR REPLACE ]\n    [DEFINER = { user | CURRENT_USER | role | CURRENT_ROLE }]\n    PACKAGE BODY\n    [ IF NOT EXISTS ]\n    [ db_name . ] package_name\n    [ package_characteristic... ]\n{ AS | IS }\n    package_implementation_declare_section\n    package_implementation_executable_section\nEND [ package_name]\n\npackage_implementation_declare_section:\n    package_implementation_item_declaration\n      [ package_implementation_item_declaration... ]\n      [ package_implementation_routine_definition... ]\n  | package_implementation_routine_definition\n      [ package_implementation_routine_definition...]\n\npackage_implementation_item_declaration:\n    variable_declaration ;\n\nvariable_declaration:\n    variable_name[,...] type [:= expr ]\n\npackage_implementation_routine_definition:\n    FUNCTION package_specification_function\n       [ package_implementation_function_body ] ;\n  | PROCEDURE package_specification_procedure\n       [ package_implementation_procedure_body ] ;\n\npackage_implementation_function_body:\n    { AS | IS } package_routine_body [func_name]\n\npackage_implementation_procedure_body:\n    { AS | IS } package_routine_body [proc_name]\n\npackage_routine_body:\n    [ package_routine_declarations ]\n    BEGIN\n      statements [ EXCEPTION exception_handlers ]\n    END\n\npackage_routine_declarations:\n    package_routine_declaration ';' [package_routine_declaration ';']...\n\npackage_routine_declaration:\n          variable_declaration\n        | condition_name CONDITION FOR condition_value\n        | user_exception_name EXCEPTION\n        | CURSOR_SYM cursor_name\n          [ ( cursor_formal_parameters ) ]\n          IS select_statement\n        ;\n\npackage_implementation_executable_section:\n          END\n        | BEGIN\n            statement ; [statement ; ]...\n          [EXCEPTION exception_handlers]\n          END\n\nexception_handlers:\n           exception_handler [exception_handler...]\n\nexception_handler:\n          WHEN_SYM condition_value [, condition_value]...\n            THEN_SYM statement ; [statement ;]...\n\ncondition_value:\n          condition_name\n        | user_exception_name\n        | SQLWARNING\n        | SQLEXCEPTION\n        | NOT FOUND\n        | OTHERS_SYM\n        | SQLSTATE [VALUE] sqlstate_value\n        | mariadb_error_code\n\nDescription\n-----------\n\nThe CREATE PACKAGE BODY statement creates the package body for a stored package. The package specification must be previously created using the CREATE PACKAGE statement.\n\nA package body provides implementations of the package public routines and can optionally have:\n\n package-wide private variables\n package private routines\n forward declarations for private routines\n an executable initialization section\n\n> Starting with MariaDB 13.0.1, package bodies can define RECORD and REF CURSOR types that can be used as:\n>\n>  Parameters (IN, OUT, INOUT) for procedures and functions defined in the package\n>  RETURN clause data types for package functions\n>\n> For detailed syntax and examples, see DECLARE TYPE.<br>\n\nExamples\n--------\n\nSET sql_mode=ORACLE;\nDELIMITER $$\nCREATE OR REPLACE PACKAGE employee_tools AS\n  FUNCTION getSalary(eid INT) RETURN DECIMAL(10,2);\n  PROCEDURE raiseSalary(eid INT, amount DECIMAL(10,2));\n  PROCEDURE raiseSalaryStd(eid INT);\n  PROCEDURE hire(ename TEXT, esalary DECIMAL(10,2));\nEND;\n$$\nCREATE PACKAGE BODY employee_tools AS\n  -- package body variables\n  stdRaiseAmount DECIMAL(10,2):=500;\n\n  -- private routines\n  PROCEDURE log (eid INT, ecmnt TEXT) AS\n  BEGIN\n    INSERT INTO employee_log (id, cmnt) VALUES (eid, ecmnt);\n  END;\n\n  -- public routines\n  PROCEDURE hire(ename TEXT, esalary DECIMAL(10,2)) AS\n    eid INT;\n  BEGIN\n    INSERT INTO employee (name, salary) VALUES (ename, esalary);\n    eid:= last_insert_id();\n    log(eid, 'hire ' || ename);\n  END;\n\n  FUNCTION getSalary(eid INT) RETURN DECIMAL(10,2) AS\n    nSalary DECIMAL(10,2);\n  BEGIN\n    SELECT salary INTO nSalary FROM employee WHERE id=eid;\n    log(eid, 'getSalary id=' || eid || ' salary=' || nSalary);\n    RETURN nSalary;\n  END;\n\n  PROCEDURE raiseSalary(eid INT, amount DECIMAL(10,2)) AS\n  BEGIN\n    UPDATE employee SET salary=salary+amount WHERE id=eid;\n    log(eid, 'raiseSalary id=' || eid || ' amount=' || amount);\n  END;\n\n  PROCEDURE raiseSalaryStd(eid INT) AS\n  BEGIN\n    raiseSalary(eid, stdRaiseAmount);\n    log(eid, 'raiseSalaryStd id=' || eid);\n  END;\n\nBEGIN\n  -- This code is executed when the current session\n  -- accesses any of the package routines for the first time\n  log(0, 'Session ' || connection_id() || ' ' || current_user || ' started');\nEND;\n$$\n\nDELIMITER ;\n\nURL: https://mariadb.com/docs/server/reference/sql-statements/data-definition/create/create-package-body