Category: MySQLDevelopmentTutorials

Characteristics


When creating stored routines we can specify a number of characteristics which allow us to tell MySQL some important information with regards to how the procedure will function. Currently a most of these characteristics are for future support only. The four we can currently specify are as follows

   LANGUAGE SQL
   [NOT] DETERMINISTIC
   SQL SECURITY {DEFINER | INVOKER}
   COMMENT ´string´


Contents

[edit] LANGUAGE

In the future it will be possible to write stored routines not just in ANSI SQL but also in a number of other different programming languages. MySQL have highlighted PHP in particular and Oracles PL/SQL has been mentioned on a number of websites. This will open stored procedure programming to developers who have skills in other programming languages. But for now we are limited to ANSI SQL therefore we can only use the SQL characteristic like so.

drop function helloworld
//
create function helloworld() returns varchar(20) language SQL
return "Hello World";
//

Download characteristic1.myp

As you can tell all that needs to be done is to specify the characteristic after the initial create function command. Currently SQL is the only supported value for the language characteristic, you do not need to specify this as it is the default value and is likely to be when new languages become supported.

[edit] DETERMINISTIC

The deterministic characteristic is used only within functions. A function is deterministic if it returns the same value each time for the same set of parameters. This will allow the optimizer to make decisions on how to handle the function and make improvements in speed based on this information. We can specifiy this characteristic like so.

drop function helloworld
//
create function helloworld() returns varchar(20) deterministic
return "Hello World";
//

Download characteristic2.myp

There is little point in using this characteristic at present however as the optimizer currently ignores it and is only included for future compatibility.

[edit] SQL SECURITY

This is possibly the most important of the characteristics at present. The SQL Security characteristic can be set to either definer or invoker. This means that when the procedure is run any SQL statments will run against the security permissions of either the definer (the user who created the stored routine) or the invoker (the user calling the stored routine). This is set like so.

drop function helloworld
//
create function helloworld() returns varchar(20) sql security definer
return "Hello World";
//

Download characteristic3.myp

[edit] COMMENT

The final characteristic is comment. As the name suggests the comment charactersitic is used to add a comment to the function. This comment is in the form of a string enclosed in quote marks. This is done like so.

drop function helloworld
//
create function helloworld() returns varchar(20) comment ´This is a function to return the string helloworld´
return "Hello World";
//

Download characteristic4.myp

The comment can be seen when using the show command as we will see in the next section. In addition to adding a routine level comment you can also added inline comments. These can be either a single line comment or multiple lines. To use a single line comment we use two - characters and to use a multiple line comment we place the comment between /* and */. This is done like so

drop function helloworld
//
create function helloworld() returns varchar(20) comment ´This is a function to return the string helloworld´
begin

-- this is a single line comment
/* this is a multiple
   line comment
*/

return "Hello World";
end
//











[l_sp_9] Tankless Heater Water Heater Tankless Water Heater Hot Water Heater Hot Tankless Water Electric Heater Tankless Water Electric Heater Water Heater Solar Water Gas Heater Water Gas Heater Hot Water Bosch Heater Tankless Water Heater Rheem Water Electric Heater Hot Water Bed Heater Water Heater Rinnai Tankless Water Gas Heater Tankless Water Demand Heater Water Heater Richmond Water Heater Services Water Heater State Water Heater Rinnai Water Bosch Heater Water Ao Heater Smith Water Heater Water Whirlpool Bradford Heater Water White Heater Repair Water Electric Heater Hot Tankless Water Gas Heater Hot Tankless Water Dealer Heater Water 40 Electric Gal Heater Water Heater Hot Instant Water American Heater Water Heater O Smith Water Ge Heater Water Heater Hot Solar Water Demand Heater Hot Water Heater Rv Water Heater Paloma Tankless Water Heater Instant Water Heater Paloma Water Heater Propane Water Atwood Heater Water Heater Noritz Water Heater Hot Rheem Water Commercial Heater Water Heater Rheem Tankless Water Heater Noritz Tankless Water Heater Marathon Water Gas Heater Natural Water Heater Review Tankless Water Heater Polaris Water Heater Installation Water Heater Indirect Water Heater Hot Price Water Heater Reliance Water Heat Heater Pump Water Demand Electric Heater Water Heater Part Water Heater Hot Rinnai Water A O Heater Smith Water Heater Tankless Titan Water Heater Lochinvar Water Heater Suburban Water Heater Problem Water Heater Hot Rv Water Gas Heater Natural Tankless Water Heater Renco Tankless Water Heater Takagi Tankless Water Heater Hot Repair Water Heater Hot Rinnai Tankless Water Heater Timer Water Heater Hot Water Whirlpool Heater Point Use Water Bosch Electric Heater Tankless Water Heater Titan Water Electric Heater Powerstar Tankless Water Bradford Heater Hot Water White Heater Select State Water Heater Ruud Water Heater Sears Water Heater Takagi Water Ariston Heater Water Bosch Heater Hot Tankless Water Heater Instantaneous Water Heater Price Water Heater Power Vent Water Heater Install Water Bosch Gas Heater Tankless Water Heater Portable Water Heater Home Mobile Water Build Heater Solar Water Fired Heater Water Wood Drain Heater Water Heater Renai Tankless Water Heater Hot Problem Water Heater Propane Tankless Water Baseboard Heater Hot Water Heater Maintenance Water Heater Review Water Gas Heater Rheem Water Bosch Heater Hot Water

Retrieved from "http://forge.mysql.com/wiki/Characteristics"

This page has been accessed 5,992 times. This page was last modified 00:40, 19 November 2006.

Find

Browse
MySQLForge
Main Page
Current events
Recent changes
Random page
Help
Edit
Edit this page
Editing help
This page
Discuss this page
Post a comment
Printable version
Context
Page history
What links here
Related changes
My pages
Special pages
New pages
File list
Statistics
Bug reports
More...