Hi!
Like Jay suggested, in that thread are some examples. TO cut through all that, take a look at the manual here:
http://dev.mysql.com/doc/refman/5.0/en/sqlps.html
or here:
http://mysql.gilfster.com/page.php?parent_id=1.3&page_id=1.3.6
MySQL does not support execute directly (or imediately): you must prepare the statement first:
SET @StatementText := concat(
'insert into '
,TblName
,' default values'
);
PREPARE StatementHandle FROM @StatementText;
(you really must use a user variable, else it won't work)
Then, execute it:
EXECUTE StatementHandle;
If you need to, you can repeat this step any number of times. In fact, if you need to repeatedly execute dynamic sql, you really should prepare just once, and repeat the execute step at will. The statement handle has session scope, so you can even use it between procedures.
When you're done executing, clean up (free resources).
DEALLOCATE PREPARE StatementHandle;
When you quit the session, this is done for you automatically, but it is a good idea to do it yourself when you know you can.
The get your hands at the inserted id, use LAST_INSERT_ID() (http://dev.mysql.com/doc/refman/5.0/en/information-functions.html).
Put together:
CREATE PROCEDURE `testcreate`.`MyAddRecord` (TblName varchar(50),OUT NewIDVal int)
BEGIN
SET @StatementText := concat(
'insert into '
,TblName
,' default values'
);
PREPARE StatementHandle FROM @StatementText;
EXECUTE StatementHandle;
DEALLOCATE PREPARE StatementHandle;
SET NewIDVal = last_insert_id();
END