Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old May 19th, 2006, 11:05 AM
4.spam@mail.ru
Guest
 
Posts: n/a
Default LIKE WITH HOST VARIABLE IN SQL UDF

Hello.

UDB DB2 v8.2.1 for LUW.
Why this function can't be compiled?
---
CREATE FUNCTION MYLIKE(NM VARCHAR(128))
LANGUAGE SQL
RETURNS INTEGER
BEGIN ATOMIC
RETURN
(
SELECT COUNT(1)
FROM SYSCAT.TABLES
WHERE TABNAME LIKE MYLIKE.NM
);
END@
---
SP with like with host variable is compiled successfully.
I think it is a bug.

Sincerely,
Mark B.
Mark B.

  #2  
Old May 19th, 2006, 02:05 PM
Rhino
Guest
 
Posts: n/a
Default Re: LIKE WITH HOST VARIABLE IN SQL UDF


<4.spam@mail.ru> wrote in message
news:1148032926.171923.113140@i40g2000cwc.googlegr oups.com...[color=blue]
> Hello.
>
> UDB DB2 v8.2.1 for LUW.
> Why this function can't be compiled?
> ---
> CREATE FUNCTION MYLIKE(NM VARCHAR(128))
> LANGUAGE SQL
> RETURNS INTEGER
> BEGIN ATOMIC
> RETURN
> (
> SELECT COUNT(1)
> FROM SYSCAT.TABLES
> WHERE TABNAME LIKE MYLIKE.NM
> );
> END@
> ---
> SP with like with host variable is compiled successfully.
> I think it is a bug.
>[/color]
I think it would be easier to guess the problem if you told us the error
message from the compiler.

The only obvious problem I see is 'select count(1)' instead of 'select
count(*)' but 'count(1)' may be a valid expression, even if it doesn't do
what you want, so I'm not sure if it would cause the compile to fail.

--
Rhino


  #3  
Old May 20th, 2006, 04:15 PM
Serge Rielau
Guest
 
Posts: n/a
Default Re: LIKE WITH HOST VARIABLE IN SQL UDF

Rhino wrote:[color=blue]
> <4.spam@mail.ru> wrote in message
> news:1148032926.171923.113140@i40g2000cwc.googlegr oups.com...[color=green]
>> Hello.
>>
>> UDB DB2 v8.2.1 for LUW.
>> Why this function can't be compiled?
>> ---
>> CREATE FUNCTION MYLIKE(NM VARCHAR(128))
>> LANGUAGE SQL
>> RETURNS INTEGER
>> BEGIN ATOMIC
>> RETURN
>> (
>> SELECT COUNT(1)
>> FROM SYSCAT.TABLES
>> WHERE TABNAME LIKE MYLIKE.NM
>> );
>> END@
>> ---
>> SP with like with host variable is compiled successfully.
>> I think it is a bug.[/color][/color]
It a known limitation.
Local variables and parameters cannot be used in LIKE patterns in
"inline" SQL PL (That is SQL functions and triggers).

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
  #4  
Old May 22nd, 2006, 07:25 AM
4.spam@mail.ru
Guest
 
Posts: n/a
Default Re: LIKE WITH HOST VARIABLE IN SQL UDF

Is it described somewhere in documentation?
I'd like to read about other SQL UDF limitations.
[color=blue]
> It a known limitation.
> Local variables and parameters cannot be used in LIKE patterns in
> "inline" SQL PL (That is SQL functions and triggers).[/color]

  #5  
Old May 22nd, 2006, 04:25 PM
Serge Rielau
Guest
 
Posts: n/a
Default Re: LIKE WITH HOST VARIABLE IN SQL UDF

4.spam@mail.ru wrote:[color=blue]
> Is it described somewhere in documentation?
> I'd like to read about other SQL UDF limitations.[/color]
Yes and no. The explanation for LIKE says that the pattern must be a
"constant expression". That expression includes host-variables.
Host-variables are equated with SQL Variables in SQL Procedures (but not
- in this case - functions).
This limitation is really special and teh only on eof its kind.
In general "inline" SQL PL is described in "compound statement (dynamic)".

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,338 network members.