Home > Archive > MySQL ODBC Connector > April 2006 > Way of declaring variables?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Way of declaring variables?
Yemi Obembe

2006-04-03, 7:32 am

------ =_Part_6728_23747758
.1144061998596
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Got the snippet from the mysql website:

select @last :=3D last_insert_id()

i av the hunch that is to assign the variable 'last' to the
last_insert_id(). Im i right? is placing @ before a word mysql's way of
declaring variables? what's the work of the colon preceeding the equal sign=
?


--
http://ngBot.com | http://wap.ngBot.com
Nigeria's #1 website directory.

------ =_Part_6728_23747758
.1144061998596--
Gabriel PREDA

2006-04-03, 7:32 am

------ =_Part_6841_28503480
.1144064177739
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

First of all... yes... in MySQL variables are declared and used with @

Now for the ":" ... there is no particular role... they're there because
otherwise the SQL parser will be confused...

*SELECT column1, @neededValue=3Dcolum
n2 FROM table_name LIMIT 1*
*SELECT column1, @neededValue:=3Dcolu
mn2 FROM table_name LIMIT 1*

In the first SQL the parser would test whether @neededValue is equal tot th=
e
value in column2 instead of assigning to @neededValue the value from column=
2

This confusion can happen only in SELECT statements... so you are required
to add ":" only in SELECT statements.

In SET statements you don't need that... you can write:
*SET @last =3D last_insert_id()*
Or with values from outside MySQL:
*SET @iNeedThis =3D 'someText';*
Then use both in an insert statement:
*INSERT INTO table (lid, txt) VALUES (@last, @iNeedThis);*

Hope this cleared up things !

--
Gabriel PREDA
Senior Web Developer


On 4/3/06, Yemi Obembe <ray@ngbot.com> wrote:
>
> Got the snippet from the mysql website:
>
> select @last :=3D last_insert_id()
> i av the hunch that is to assign the variable 'last' to the
> last_insert_id(). Im i right? is placing @ before a word mysql's way of
> declaring variables? what's the work of the colon preceeding the equal
> sign?
>


------ =_Part_6841_28503480
.1144064177739--
Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2009 droptable.com