How to create a simple Procedure/Function

You should understand that phpMyAdmin doesn’t use Packages, as it could be realized in Oracle. All of the functions and procedures will be in a bundle, hence it’d be useful to apply some special prefix in the Routine name field.

The simplest way to create one you can see below. You need to know:

  1. The name of your Function/Procedure
  2. How many input parameters have you defined
  3. Their data types
  4. What do you need as output

Creating

  1. You can define what you need to create. It would a function or a procedure. Let’s create a :
Function by clicking on Functions -> New
Procedure by clicking on Procedures -> New
  1. Now you can see window below:
  1. Give it Routine name and define Type:
  1. Add as many input parameters as you wish. Give them names, data types, in case of INTEGER default values, in case of VARCHAR length, and Options :
In case of Function

Also, a Direction (IN / OUT) need to be defined during Procedure creating. Remember, that a Procedure doesn’t require Output parameters, as it does in case of Function. It’s optional.

In case of Procedure
  1. Define output parameter, its data type and/or length/values:
  1. Here should be SQL code or any other workable stuff. Start it with keyword BEGIN and close it with the other one END:
  1. At the end need to be defined Definer. For example, it could be like `dbprefix`@`localhost` and SQL data access.
  1. The final view of a simple complete Function looks like below:
  1. If you wanna use some Procedure(-s) inside of your Function, then you may need to use next construction. Here y1, y2 are Input parameters and a is an Output parameter, which you can use in further.
Here is a CALL of the Procedure named `get_test` with 2 Input parameters and 1 Output parameter, which then returning as Output of the parent Function.