Home > Ask the Oracle Experts > SQL Questions & Answers > Substring function
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Substring function

Rudy Limeback EXPERT RESPONSE FROM: Rudy Limeback

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 06 September 2002
I want to get the first eight characters of a text field, but I also need to get more values for other fields of three tables. I don't know what form of the "substring" function is correct to use. Or is there another function that I could use?

>
EXPERT RESPONSE

The standard SQL substring function is

SUBSTRING(string FROM start FOR length)

Microsoft SQL/Server, Sybase, MySQL and PostgreSQL all support this syntax. Other databases may also support it (I have not done an exhaustive survey). Double-check by looking it up in your database documentation.

In Microsoft SQL/Server, Sybase, and MySQL, you can also use

SUBSTRING(string, start, length)

In Microsoft Access and MySQL, you can use


MID(string, start, length)

In Oracle, use

SUBSTR(string, start, length)

A good reference for SQL functions is Chapter 4, SQL Functions, the sample chapter of O'Reilly's book SQL in a Nutshell by Kevin Kline and Daniel Kline (ISBN 1-56592-744-3).

For your specific requirement, you would write

SUBSTRING(string FROM 1 FOR 8)

Depending on your database, you might also be able to write


LEFT(string, 8)

because the LEFT function, in those databases that support it, starts at position 1.

For More Information


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
SQL
IN list or series of OR conditions?
Connecting tables in a database
SQL query for co-authored books
Querying complex derived tables
SQL string functions
Changing a NULL column to NOT NULL
SQL for hourly totals for the last 48 hours
LEFT OUTER JOIN to a MIN/MAX row
Normalizing a crosstab table
Querying metadata and data at the same time

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2003 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts