MySQL Forums
Forum List  »  Stored Procedures

Re: Dynamic SQL. Is it possible?
Posted by: Roland Bouman
Date: November 04, 2005 05:21PM

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?

Options: ReplyQuote


Subject
Views
Written By
Posted
3537
November 04, 2005 01:40AM
2693
November 04, 2005 03:51AM
2732
November 04, 2005 08:51AM
2430
November 23, 2005 10:50AM
2389
November 23, 2005 02:18PM
2467
November 04, 2005 08:54AM
6763
November 04, 2005 03:40PM
Re: Dynamic SQL. Is it possible?
2513
November 04, 2005 05:21PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.