See comments interspersed below. Rhino ----- Original Message ----- From: "Duncan Miller" <[EMAIL PROTECTED]> To: <mysql@lists.mysql.com> Sent: Sunday, November 06, 2005 8:36 PM Subject: Evaluating text as an expression
> I am trying to set up a table where the returned value is a result of > evaluating an expression that is stored as text (or varchar). > > The idea is to have a table with a couple of fields that can contain > numeric values or expressions eg > > Name Fred > Years 3 > Commission base 10% > Commission Commission Base + (Years * 2)% > > > I sort imagines that I could do it like SELECT Name, > Evaluate(Commission) or as a subquery. > Assuming you want to invoke this code with a function name, as in your example, what you're requesting is called a UDF (user-defined function). These are supported as early as MySQL 4.1. Basically, you create a function with a name of your choosing (usually with some restrictions), then write some code behind it to do the work you want. Then you drop that code into MySQL and it becomes just another function that you can use, just like the standard ones built into MySQL. See this page of the 4.1 manual for more information: http://dev.mysql.com/doc/refman/4.1/en/create-function.html. > Another example I have is to be able to store queries in a table and be > able to call them in one call to the database rather than through the > provider eg > > Select evaluate(queryText) from queryTable where queryId = x > > This is probably a bit more redundant now that 5 has stored procedures > etc but still... > I haven't seen the exact functionality you are describing in either DB2 or MySQL but what you are describing is not too different from stored procedures. A stored procedure is basically the name of some code that you can invoke, passing in parameters if you like, and that returns a result set. They are invoked via CALL statements though, not via SELECT statements. Rhino -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.362 / Virus Database: 267.12.8/162 - Release Date: 05/11/2005 -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]