| Author |
SQL return substrings
|
Grazia Lassner
Greenhorn
Joined: Apr 26, 2010
Posts: 19
|
|
Does anyone know how to
select the first substring before a given character with SQL ?
For instance, if my column ID contains data like ABC_XYZ or BC_Z, how could I select the 'ABC' or 'BC' occurring before the '_' ?
Thanks !
|
 |
Martin Vanyavchich
Ranch Hand
Joined: Sep 16, 2008
Posts: 241
|
|
Given that your ABC_XYZ is a String, and you're looking for a Java solution ...
|
SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
|
 |
Grazia Lassner
Greenhorn
Joined: Apr 26, 2010
Posts: 19
|
|
|
Sorry, I meant a way with a SQL select statement
|
 |
Martin Vanyavchich
Ranch Hand
Joined: Sep 16, 2008
Posts: 241
|
|
|
Well I think that greatly depends on the database that you're using. So this probably isn't the right forum for your question. Try finding the forum for the database you're using.
|
 |
Grazia Lassner
Greenhorn
Joined: Apr 26, 2010
Posts: 19
|
|
|
I was trying to find an Oracle forum here, but I guess it does not exist
|
 |
Tom Reilly
Rancher
Joined: Jun 01, 2010
Posts: 618
|
|
|
Try instr function
|
 |
Peter Taucher
Ranch Hand
Joined: Nov 18, 2006
Posts: 174
|
|
On MS SQL Server:
On PostgreSQL:
String functions seem to differ largely between vendors...
|
Censorship is the younger of two shameful sisters, the older one bears the name inquisition.
-- Johann Nepomuk Nestroy
|
 |
Martin Vanyavchich
Ranch Hand
Joined: Sep 16, 2008
Posts: 241
|
|
|
Link to Oracle forum, try in the 'SQL and PL/SQL' section
|
 |
Grazia Lassner
Greenhorn
Joined: Apr 26, 2010
Posts: 19
|
|
|
select distinct Substr(column,1,instr(column,'_')) from ....
|
 |
 |
|
|
subject: SQL return substrings
|
|
|