Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

Calling a function by using a variable containing the name of the function

6 posts in General Discussion Last posting was on 2003-07-24 09:31:35.0Z
Peter Quick Posted on 2003-07-17 07:59:09.0Z
From: "Peter Quick" <PeterQ@InforIT.nl>
Subject: Calling a function by using a variable containing the name of the function
Date: Thu, 17 Jul 2003 09:59:09 +0200
Lines: 22
Organization: InforIT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#eGK#pDTDHA.298@forums-2-dub>
Newsgroups: ianywhere.public.general
NNTP-Posting-Host: 62.58.186.102
Path: forums-1-dub!forums-master.sybase.com!forums-2-dub.sybase.com
Xref: forums-1-dub ianywhere.public.general:1366
Article PK: 3600

Hi all,


how can I call a function, when its name is in a variabele?

//Get and construct ProductQueryand
select TBBConstructProductQueryFromMacro(pMCTAddressId, tempOrderId,
tempOrdProductId, tempEuteltracsText) into tempProductQuery;

//Call ProductQuery if found
if tempProductQuery <> '' then
select tempProductQuery into ReturnValue <= how can I do this?
end if;





Thanks in advance,
Peter


Breck Carter [TeamSybase] Posted on 2003-07-17 11:45:31.0Z
From: "Breck Carter [TeamSybase]" <NOSPAM__bcarter@risingroad.com>
Subject: Re: Calling a function by using a variable containing the name of the function
Date: Thu, 17 Jul 2003 07:45:31 -0400
Organization: RisingRoad Professional Services
Reply-To: NOSPAM__bcarter@risingroad.com
Message-ID: <f13dhvon2jd5dcn9jugp5tofmrgv45pcvl@4ax.com>
References: <#eGK#pDTDHA.298@forums-2-dub>
X-Newsreader: Forte Agent 1.8/32.548
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: ianywhere.public.general
NNTP-Posting-Host: bcarter.sentex.ca 64.7.134.118
Lines: 28
Path: forums-1-dub!forums-master.sybase.com!forums-2-dub.sybase.com
Xref: forums-1-dub ianywhere.public.general:1367
Article PK: 3599

Use EXECUTE IMMEDIATE:

CREATE FUNCTION f ( IN @p INTEGER )
RETURNS INTEGER
BEGIN
RETURN @p * 10;
END;

CREATE FUNCTION g ( IN @p INTEGER )
RETURNS INTEGER
BEGIN
RETURN @p * 100;
END;

BEGIN
DECLARE @x INTEGER;
DECLARE @y INTEGER;
DECLARE @a INTEGER;
DECLARE @b INTEGER;
SET @x = 2;
SET @a = 3;
EXECUTE IMMEDIATE 'SET @y = f ( @x )';
EXECUTE IMMEDIATE 'SET @b = g ( @a )';
SELECT @y, @b;
END;

Breck

On Thu, 17 Jul 2003 09:59:09 +0200, "Peter Quick" <PeterQ@InforIT.nl>

wrote:

>Hi all,
>
>
>how can I call a function, when its name is in a variabele?
>
> //Get and construct ProductQueryand
> select TBBConstructProductQueryFromMacro(pMCTAddressId, tempOrderId,
>tempOrdProductId, tempEuteltracsText) into tempProductQuery;
>
> //Call ProductQuery if found
> if tempProductQuery <> '' then
> select tempProductQuery into ReturnValue <= how can I do this?
> end if;
>
>
>
>
>
>Thanks in advance,
>Peter
>

bcarter@risingroad.com
Mobile and Distributed Enterprise Database Applications
http://www.risingroad.com


Peter Quick Posted on 2003-07-17 14:53:25.0Z
From: "Peter Quick" <PeterQ@InforIT.nl>
References: <#eGK#pDTDHA.298@forums-2-dub> <f13dhvon2jd5dcn9jugp5tofmrgv45pcvl@4ax.com>
Subject: Re: Calling a function by using a variable containing the name of the function
Date: Thu, 17 Jul 2003 16:53:25 +0200
Lines: 70
Organization: InforIT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <OR#pdRHTDHA.145@forums-2-dub>
Newsgroups: ianywhere.public.general
NNTP-Posting-Host: 62.58.186.102
Path: forums-1-dub!forums-master.sybase.com!forums-2-dub.sybase.com
Xref: forums-1-dub ianywhere.public.general:1378
Article PK: 3612

Breck,

what if ProductQuery contains a complete statement,
like "select TBBUpdateOrdProductLoading(658,123,'04062003','1640','x')" ??

Thanks in advance,
Peter

"Breck Carter [TeamSybase]" <NOSPAM__bcarter@risingroad.com> wrote in
message news:f13dhvon2jd5dcn9jugp5tofmrgv45pcvl@4ax.com...
> Use EXECUTE IMMEDIATE:
>
> CREATE FUNCTION f ( IN @p INTEGER )
> RETURNS INTEGER
> BEGIN
> RETURN @p * 10;
> END;
>
> CREATE FUNCTION g ( IN @p INTEGER )
> RETURNS INTEGER
> BEGIN
> RETURN @p * 100;
> END;
>
> BEGIN
> DECLARE @x INTEGER;
> DECLARE @y INTEGER;
> DECLARE @a INTEGER;
> DECLARE @b INTEGER;
> SET @x = 2;
> SET @a = 3;
> EXECUTE IMMEDIATE 'SET @y = f ( @x )';
> EXECUTE IMMEDIATE 'SET @b = g ( @a )';
> SELECT @y, @b;
> END;
>
> Breck
>
> On Thu, 17 Jul 2003 09:59:09 +0200, "Peter Quick" <PeterQ@InforIT.nl>
> wrote:
>
> >Hi all,
> >
> >
> >how can I call a function, when its name is in a variabele?
> >
> > //Get and construct ProductQueryand
> > select TBBConstructProductQueryFromMacro(pMCTAddressId, tempOrderId,
> >tempOrdProductId, tempEuteltracsText) into tempProductQuery;
> >
> > //Call ProductQuery if found
> > if tempProductQuery <> '' then
> > select tempProductQuery into ReturnValue <= how can I do this?
> > end if;
> >
> >
> >
> >
> >
> >Thanks in advance,
> >Peter
> >
>
> bcarter@risingroad.com
> Mobile and Distributed Enterprise Database Applications
> http://www.risingroad.com


Breck Carter [TeamSybase] Posted on 2003-07-17 15:21:00.0Z
From: "Breck Carter [TeamSybase]" <NOSPAM__bcarter@risingroad.com>
Subject: Re: Calling a function by using a variable containing the name of the function
Date: Thu, 17 Jul 2003 11:21:00 -0400
Organization: RisingRoad Professional Services
Reply-To: NOSPAM__bcarter@risingroad.com
Message-ID: <bmfdhvsdjpco1moa3is1otp20bmsca8hs8@4ax.com>
References: <#eGK#pDTDHA.298@forums-2-dub> <f13dhvon2jd5dcn9jugp5tofmrgv45pcvl@4ax.com> <OR#pdRHTDHA.145@forums-2-dub>
X-Newsreader: Forte Agent 1.8/32.548
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: ianywhere.public.general
NNTP-Posting-Host: bcarter.sentex.ca 64.7.134.118
Lines: 49
Path: forums-1-dub!forums-master.sybase.com!forums-2-dub.sybase.com
Xref: forums-1-dub ianywhere.public.general:1379
Article PK: 3613

Version 9... EXECUTE IMMEDIATE supports queries that return result
sets This new feature allows more dynamic construction of
statements inside stored procedures.

Breck

On Thu, 17 Jul 2003 16:53:25 +0200, "Peter Quick" <PeterQ@InforIT.nl>

wrote:

>Breck,
>
>what if ProductQuery contains a complete statement,
>like "select TBBUpdateOrdProductLoading(658,123,'04062003','1640','x')" ??
>
>Thanks in advance,
>Peter
>
>
>
>"Breck Carter [TeamSybase]" <NOSPAM__bcarter@risingroad.com> wrote in
>message news:f13dhvon2jd5dcn9jugp5tofmrgv45pcvl@4ax.com...
>> Use EXECUTE IMMEDIATE:
>>
>> CREATE FUNCTION f ( IN @p INTEGER )
>> RETURNS INTEGER
>> BEGIN
>> RETURN @p * 10;
>> END;
>>
>> CREATE FUNCTION g ( IN @p INTEGER )
>> RETURNS INTEGER
>> BEGIN
>> RETURN @p * 100;
>> END;
>>
>> BEGIN
>> DECLARE @x INTEGER;
>> DECLARE @y INTEGER;
>> DECLARE @a INTEGER;
>> DECLARE @b INTEGER;
>> SET @x = 2;
>> SET @a = 3;
>> EXECUTE IMMEDIATE 'SET @y = f ( @x )';
>> EXECUTE IMMEDIATE 'SET @b = g ( @a )';
>> SELECT @y, @b;
>> END;
>>
>> Breck
>>
>> On Thu, 17 Jul 2003 09:59:09 +0200, "Peter Quick" <PeterQ@InforIT.nl>
>> wrote:
>>
>> >Hi all,
>> >
>> >
>> >how can I call a function, when its name is in a variabele?
>> >
>> > //Get and construct ProductQueryand
>> > select TBBConstructProductQueryFromMacro(pMCTAddressId, tempOrderId,
>> >tempOrdProductId, tempEuteltracsText) into tempProductQuery;
>> >
>> > //Call ProductQuery if found
>> > if tempProductQuery <> '' then
>> > select tempProductQuery into ReturnValue <= how can I do this?
>> > end if;
>> >
>> >
>> >
>> >
>> >
>> >Thanks in advance,
>> >Peter
>> >
>>
>> bcarter@risingroad.com
>> Mobile and Distributed Enterprise Database Applications
>> http://www.risingroad.com
>

bcarter@risingroad.com
Mobile and Distributed Enterprise Database Applications
http://www.risingroad.com


philb Posted on 2003-07-17 21:39:00.0Z
From: philb
Date: Thu, 17 Jul 2003 17:39:00 -0400
Newsgroups: ianywhere.public.general
Subject: Re: Calling a function by using a variable containing the name of the function
Message-ID: <EF660882EDD76C260076ED6A85256D66.005704E785256D66@webforums>
References: <#eGK#pDTDHA.298@forums-2-dub> <f13dhvon2jd5dcn9jugp5tofmrgv45pcvl@4ax.com> <OR#pdRHTDHA.145@forums-2-dub>
Lines: 33
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Path: forums-1-dub!forums-master.sybase.com!webforums.sybase.com!news
Xref: forums-1-dub ianywhere.public.general:1390
Article PK: 3624

We do something similar by opening a cursor. this is an example. set sSql
to be yours and see what happens

===

begin
/*
find all tables that start with the given prefix (like 'xxx%')
*/
declare @sSql long varchar;
set @sSql = 'select table_name from systable where table_name like ' ;
set @sSql = @sSql + '''' + arcPrefix + '%' + '''';

// nested inner cursor
begin
declare @tableName char ( 40 );

declare curs1 cursor using @sSql;

open curs1;

mainloop: loop
fetch curs1 into @tableName;
if SQLCODE <> 0 then leave mainloop end if;
message 'tablename = ' + @tableName ;
end loop;

close curs1;

end;
// end of nested inner cursor

end;


Peter Quick Posted on 2003-07-24 09:31:35.0Z
From: "Peter Quick" <PeterQ@InforIT.nl>
References: <#eGK#pDTDHA.298@forums-2-dub> <f13dhvon2jd5dcn9jugp5tofmrgv45pcvl@4ax.com> <OR#pdRHTDHA.145@forums-2-dub> <EF660882EDD76C260076ED6A85256D66.005704E785256D66@webforums>
Subject: Re: Calling a function by using a variable containing the name of the function
Date: Thu, 24 Jul 2003 11:31:35 +0200
Lines: 43
Organization: InforIT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#zu59fcUDHA.280@forums-2-dub>
Newsgroups: ianywhere.public.general
NNTP-Posting-Host: 62.58.186.102
Path: forums-1-dub!forums-master.sybase.com!forums-2-dub.sybase.com
Xref: forums-1-dub ianywhere.public.general:1451
Article PK: 3684

Thanks, did does the job wonderfully.

Regards,
Peter

<philb> wrote in message
news:EF660882EDD76C260076ED6A85256D66.005704E785256D66@webforums...
> We do something similar by opening a cursor. this is an example. set
sSql
> to be yours and see what happens
>
> ===
>
> begin
> /*
> find all tables that start with the given prefix (like 'xxx%')
> */
> declare @sSql long varchar;
> set @sSql = 'select table_name from systable where table_name like ' ;
> set @sSql = @sSql + '''' + arcPrefix + '%' + '''';
>
> // nested inner cursor
> begin
> declare @tableName char ( 40 );
>
> declare curs1 cursor using @sSql;
>
> open curs1;
>
> mainloop: loop
> fetch curs1 into @tableName;
> if SQLCODE <> 0 then leave mainloop end if;
> message 'tablename = ' + @tableName ;
> end loop;
>
> close curs1;
>
> end;
> // end of nested inner cursor
>
> end;