From the course: MySQL Advanced Topics
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Creating a stored function - MySQL Tutorial
From the course: MySQL Advanced Topics
Creating a stored function
- [Bill] Hi, I am Bill Weinman. A stored function is defined with the create function statement. I've copied this block of SQL from the chapter three exercise file. We'll start with the use album statement, which will open the album database. Then we're going to define a function. We're going to create a function. Now, my SQL already provides a function for converting seconds to time, but I usually need to reformat it as a string anyway. So I tend to use a stored function like this one. It starts with the delimiter command. Now delimiter is used to set the delimiter to something other than the semicolon. This allows us to send a whole block of code to the server that includes a semicolon in it. And to do that, we need to change the delimiter to something other than the semicolon. Now the delimiter statement is actually implemented on the client and not on the server. So this allows it to send something to the server all as one unit. The create function statement creates the function…
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.