If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Like predicate in UDF

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-05-03, 05:36
alenf alenf is offline
Registered User
 
Join Date: Nov 2003
Posts: 2
Like predicate in UDF

Hi!

I am trying to create following UDF in DB2 v7.1:

CREATE FUNCTION LASTPOLNR(POL CHAR(20))
RETURNS CHAR(20)

RETURN

SELECT A211.POLNR FROM A211 WHERE A211.POLNR LIKE LASTPOLNR.POL || '%';

DB2 returns following error: SQL0132N A LIKE predicate or POSSTR scalar function is not valid because the first operand is not a string expression or the second operand is not a string.

My question is: Is there any way to use function parameter in like predicate?

Thank you all!
Reply With Quote
  #2 (permalink)  
Old 11-06-03, 09:54
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
I think if you rewrite the UDF like this, it might work:

CREATE FUNCTION LASTPOLNR(POL CHAR(20))
RETURNS CHAR(20)
language SQL NOT deterministic NO EXTERNAL ACTION READS SQL DATA CALLED ON NULL INPUT
BEGIN ATOMIC
DECLARE value char(20)
DECLARE astring varchar(30);

SET astring = pol || '%';

SET (value) = (SELECT A211.POLNR FROM A211 WHERE A211.POLNR LIKE astring);
RETURN value;
END @

HTH

Andy
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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