What are MySQL functions? [closed]
I use Navicat for MySQL and I see "functions". How they are used? What are they? What is their main purpose?
In SQL functions are subprograms defined inside the database. They are basically functions that can be called from inside SQL statements, and are useful for the same reasons that calling functions in other languages are useful. Most SQL languages come with some simple important functions and user defined functions can be added. For example, MySQL contains the function count(). It can be called like so:
select count(some_column) from some_table;
This will count the number of rows that are in the some_column column of the some_table table. You will get a response something like:
*|count(some_column)
1|200
SQL functions similar to, but different from stored procedures in SQL for these reasons:
- Functions must return a single value. Stored procedures on the other hand, may return multiple values or even no return value.
- Functions can be placed inside select statements. Stored procedures can't.
You can find more information about functions and stored procedures here:
http://www.w3schools.com/sql/sql_functions.asp
http://en.wikipedia.org/wiki/User-defined_function
http://dev.mysql.com/doc/refman/5.0/en/functions.html
What's the point of a stored procedure?
http://en.wikipedia.org/wiki/Stored_procedure
精彩评论