From the course: Learning phpMyAdmin
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Creating a stored function
- Stored functions are useful if you want to calculate and return a single value on a regular basis. A stored function can contain conditional logic and it can be used in SQL statements. To create a stored function you need to select the database, so I'm going to select up_and_running from the panel on the left and then select the routines tab at the top right. Routines is where you create both stored procedures and stored functions, so under new click add routine. This opens this dialog box, by default type is set to procedure, so we need to change that to function and that changes some of the options that are available in here. We need to begin by giving our function a name. I'm going to call it apply_discount, and this will be a stored function to apply different levels of discount depending on price. Next we need to define the parameters, in other words the arguments that will be passed to the stored function. We're going to pass the normal price to the function, so that will be…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.