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 > <text> LIKE <column> || '%' or "startswith" function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-17-05, 08:02
aion aion is offline
Registered User
 
Join Date: Sep 2003
Location: Riga, Latvia
Posts: 6
<text> LIKE <column> || '%' or "startswith" function

Hello,

I tried to do folliwing:
db2 => select name from test where 'Super tester' like name || '%'

But..
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. SQLSTATE=42824

Is it possible to implement it in SQL manner w/o UDF?
Thanks a lot.

P.S.
DB2 version 8.2

db2 => select name from test

NAME
--------------------------------
Super

1 record(s) selected.

db2 => describe table test

Column Type Type
name schema name Length Scale Nulls
------------------------------ --------- ------------------ -------- ----- ------
NAME SYSIBM VARCHAR 32 0 No

1 record(s) selected.
Reply With Quote
  #2 (permalink)  
Old 02-17-05, 09:25
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
have you tried locate function ?

with temp1(col1) as
(
values('Super'),
('per'),
('Test'),
('XYZ')
)
select col1,locate(col1,'Super Tester')
from
temp1

COL1 2
Super 1
per 3
Test 7
XYZ 0
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 02-17-05, 09:59
aion aion is offline
Registered User
 
Join Date: Sep 2003
Location: Riga, Latvia
Posts: 6
Hello sathyaram_s,

location function, how I understood, simular to "".indexOf("" so, but for me required "".startsWith(" (in java world)

At current moment I resolved it problem in one way only (udf implementation)
Simple to define java function, like following:
public short startsWith( String str1, String str2 ) {
if( str1.startsWith(str2) )
return 1;
else
return 0;
}
and all.

Thanks a lot for advice.
Reply With Quote
  #4 (permalink)  
Old 02-17-05, 21:18
jacampbell jacampbell is offline
Registered User
 
Join Date: Jan 2005
Posts: 191
where left('Super Tester' ,length(name)) = name

James Campbell
Reply With Quote
  #5 (permalink)  
Old 02-18-05, 02:19
aion aion is offline
Registered User
 
Join Date: Sep 2003
Location: Riga, Latvia
Posts: 6
2 jacampbell
Yep, it's work.
Thanks a lot for advice.
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