This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes SQL return substrings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL return substrings" Watch "SQL return substrings" New topic
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 ....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL return substrings
 
Similar Threads
SQL Statements in XML document
Calling a stored procedure for MSSQL 2000?
wierd exception from hibernate
JDBC and Stored Procedure
Informix Prepared Statement