user defined variables in a query
Posted in 2008
The poster asked whether Informix SQL supports MySQL-style user-defined session variables (e.g. SET @var1 = 'hello'; then using @var1 in a SELECT) so a plain query could be parameterised at the top, without using an SPL routine. One reply pointed to the SPL documentation on defining variables; Art Kagel suggested just embedding the literal value or wrapping the script in shell/awk/Perl to supply values. Fernando Nunes gave the definitive answer: no, Informix has no such feature — alternatives are SPL OUT parameters used as statement-local variables, temp tables, or scripting.
Auto-generated by DrWatson from the posts below — may be imperfect; read the full thread.
Hi,
I need to know how to use user defined variables in a query in
Informix sql. For instance:
set @var1 = "hello";
select * from table1 where table1.column2 = @var1;
I know that it is possible in mysql (http://dev.mysql.com/doc/refman/
5.0/en/user-variables.html) but i dont know how to do it in informix
sql.
Thanks in advance.
On 13 Mar, 15:00, pablo sanchez <ptsan...@gmail.com> wrote:
> Hi,
>
> I need to know how to use user defined variables in a query in
> Informix sql. For instance:
>
> set @var1 = "hello";
>
> select * from table1 where table1.column2 = @var1;>
> I know that it is possible in mysql (http://dev.mysql.com/doc/refman/
> 5.0/en/user-variables.html) but i dont know how to do it in informix
> sql.
>
> Thanks in advance.
http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.sqlt.doc/sqltmst265.htm
HTH
On Mar 13, 12:42 pm, Rich or Kristín <informix.databa...@geos.com>
wrote:
> On 13 Mar, 15:00, pablo sanchez <ptsan...@gmail.com> wrote:
>
> > Hi,
>
> > I need to know how to use user defined variables in a query in
> > Informix sql. For instance:
>
> > set @var1 = "hello";
>
> > select * from table1 where table1.column2 = @var1;>
> > I know that it is possible in mysql (http://dev.mysql.com/doc/refman/
> > 5.0/en/user-variables.html) but i dont know how to do it in informix
> > sql.
>
> > Thanks in advance.
>
> http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=...
>
> HTH
Thanks, but I ment to define a variable in a simple query, not in a
SPL Routine.
pablo sanchez wrote:
> On Mar 13, 12:42 pm, Rich or Kristín <informix.databa...@geos.com>
> wrote:
>
>> On 13 Mar, 15:00, pablo sanchez <ptsan...@gmail.com> wrote:
>>
>>
>>> Hi,
>>>
>>> I need to know how to use user defined variables in a query in
>>> Informix sql. For instance:
>>>
>>> set @var1 = "hello";
>>>
>>> select * from table1 where table1.column2 = @var1;>>>
>>> I know that it is possible in mysql (http://dev.mysql.com/doc/refman/
>>> 5.0/en/user-variables.html) but i dont know how to do it in informix
>>> sql.
>>>
>>> Thanks in advance.
>>>
>> http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=...
>>
>> HTH
>>
>
> Thanks, but I ment to define a variable in a simple query, not in a
> SPL Routine.
>
Why do you think that you need to do that? If you can write:
set @vr1= "hello";
Then you can certainly write:
select * from table1 where tabe1.column2 = 'hello';
in the same script, no? If you need to make the script commandline
configurable, wrap it in a shell, awk, or Perl script and supply the
commandline or environment values that way.
Art S. Kagel
Oninit
"When all you have is a hammer, everything starts to look like a nail!"
===========================================================================================
Please access the attached hyperlink for an important electronic communications disclaimer:
http://www.oninit.com/home/disclaimer.php
===========================================================================================
Thanks for your answer, but i dont need to make an script commandline
configurable.
I just want to know if is it possible to use user defined variables
(like in mysql) in a simple query in informix sql.
I would like to parametrize a query defining the parameters at the
begining. I know that you can do it with an spl or with a script but I
just want to know if is it possible to do it that way.
On 13 mar, 15:33, "Art S. Kagel (Oninit)" <a...@oninit.com> wrote:
> pablo sanchez wrote:
> > On Mar 13, 12:42 pm, Rich or Kristín <informix.databa...@geos.com>
> > wrote:
>
> >> On 13 Mar, 15:00, pablo sanchez <ptsan...@gmail.com> wrote:
>
> >>> Hi,
>
> >>> I need to know how to use user defined variables in a query in
> >>> Informix sql. For instance:
>
> >>> set @var1 = "hello";
>
> >>> select * from table1 where table1.column2 = @var1;>
> >>> I know that it is possible in mysql (http://dev.mysql.com/doc/refman/
> >>> 5.0/en/user-variables.html) but i dont know how to do it in informix
> >>> sql.
>
> >>> Thanks in advance.
>
> >>http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=...
>
> >> HTH
>
> > Thanks, but I ment to define a variable in a simple query, not in a
> > SPL Routine.
>
> Why do you think that you need to do that? If you can write:
>
> set @vr1= "hello";
>
> Then you can certainly write:
>
> select * from table1 where tabe1.column2 = 'hello';>
> in the same script, no? If you need to make the script commandline
> configurable, wrap it in a shell, awk, or Perl script and supply the
> commandline or environment values that way.
>
> Art S. Kagel
> Oninit
>
> "When all you have is a hammer, everything starts to look like a nail!"
>
> ===========================================================================================
> Please access the attached hyperlink for an important electronic communications disclaimer:
>
> http://www.oninit.com/home/disclaimer.php
>
> ===========================================================================================- Ocultar texto de la cita -
>
> - Mostrar texto de la cita -
pablo sanchez wrote:
> Thanks for your answer, but i dont need to make an script commandline
> configurable.
> I just want to know if is it possible to use user defined variables
> (like in mysql) in a simple query in informix sql.
> I would like to parametrize a query defining the parameters at the
> begining. I know that you can do it with an spl or with a script but I
> just want to know if is it possible to do it that way.
>
> On 13 mar, 15:33, "Art S. Kagel (Oninit)" <a...@oninit.com> wrote:
>> pablo sanchez wrote:
>>> On Mar 13, 12:42 pm, Rich or Krist'n <informix.databa...@geos.com>
>>> wrote:
>>>> On 13 Mar, 15:00, pablo sanchez <ptsan...@gmail.com> wrote:
>>>>> Hi,
>>>>> I need to know how to use user defined variables in a query in
>>>>> Informix sql. For instance:
>>>>> set @var1 = "hello";
>>>>> select * from table1 where table1.column2 = @var1;>>>>> I know that it is possible in mysql (http://dev.mysql.com/doc/refman/
>>>>> 5.0/en/user-variables.html) but i dont know how to do it in informix
>>>>> sql.
>>>>> Thanks in advance.
>>>> http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=...
>>>> HTH
>>> Thanks, but I ment to define a variable in a simple query, not in a
>>> SPL Routine.
>> Why do you think that you need to do that? If you can write:
>>
>> set @vr1= "hello";
>>
>> Then you can certainly write:
>>
>> select * from table1 where tabe1.column2 = 'hello';>>
>> in the same script, no? If you need to make the script commandline
>> configurable, wrap it in a shell, awk, or Perl script and supply the
>> commandline or environment values that way.
>>
>> Art S. Kagel
>> Oninit
>>
>> "When all you have is a hammer, everything starts to look like a nail!"
>>
>> ==========================================================================='================
>> Please access the attached hyperlink for an important electronic communications disclaimer:
>>
>> http://www.oninit.com/home/disclaimer.php
>>
>> ==========================================================================='================- Ocultar texto de la cita -
>>
>> - Mostrar texto de la cita -
>
No... But if you get this into the standard you'll have better chances to see
IBM implementing it...
You can use SPL OUT parameters as SLVs, you can use temporary tables (which do
the same), you can do it in a script... Or you can even use mysql :)
Regards.
--
Fernando Nunes
Portugal
http://informix-technology.blogspot.com
My email works... but I don't check it frequently...