Re: Dynamic SQL. Is it possible?
1. I suspec you have version 5.0.15. To be sure, do:
SELECT version();
2. Yes, I made it up. You can't declare these user variables, or rather, referencing one implicitly declares it. The type is a runtime type: it is the type of whatever value you assigned to it.
see
http://dev.mysql.com/doc/refman/5.0/en/example-user-variables.html
and
http://dev.mysql.com/doc/refman/5.0/en/Variables.html
3. Good Question! Yes and No. Depending upon the context = means either assignment or equals. This can be confusing sometimes:
create procedure p()
begin
declare v1 int;
declare v2 int default 1;
set v1 = v2 = 0; -- leftmost means assign, rightmost means equals
select v1, v2;
end;
//
To prove that is can be really confusing, start a new, clean session, and do this:
select @v:=1, @v=0;
What would be the value of @v now? First, try and predict, then do:
select @v;
surprised?
I'm used to Oracle PLSQL, wich uses := for assignment, and = for equals (there's one exception, in the SET clause of an UPDATE statement = means assign. It would be a breach to standard sql to allow the := there. Interestingly, mysql DOES accept a := in the SET clause of an UPDATE statment)
So, I try to use := as much as I can to denote assignment (but I make the same exception as oracle does, I never use it in the SET of an UPDATE).
4) I wouldnt know. Maybe there's a feature request out already?