💻
notes
  • Initial page
  • sql
    • date-and-time
    • Ordering Columns
    • Replacing Portions of Text
    • count-rows
    • Changing the Case of Strings
    • Create Excerpts with Substring
    • Transactions
    • removing-data
    • Finding Length of Strings
    • add-row-to-a-table
    • limit-and-paginate-results
    • Concatenating Strings
    • SQL JOINs
    • basic-math
    • updating-rows-in-a-table
    • Subqueries
    • Set Operations
    • SQL Basics Cheatsheet
  • ruby
    • gems
      • Auto use Ruby version with gemset
      • Must Have Gems
      • Create Devise user without any validation
    • rails
      • What are the differences between #where and #find?
  • postgresql
    • Export database dump from Heroku and import to local database
  • glossary
  • vim
    • Edit Recorded Macros
    • Sort Multiple Lines
    • Search and Replace
    • Folding
  • iTerm
  • git
    • Git
  • Command Line Utilities
  • How To Use Notes
  • Terminal Cheatsheet for Mac
Powered by GitBook
On this page

Was this helpful?

  1. sql

Create Excerpts with Substring

To create smaller strings from larger piece of text you can use the SUBSTR() funciton or the substring function.

SELECT SUBSTR(<value or column>, <start>, <length>) FROM <table>;
  • \ : Specifies where to start in the string

    • if is 0 (zero), then it is treated as 1.

    • if is positive, then the function counts from the beginning of string to find the first character.

    • if is negative, then the function counts backward from the end of string.

  • \ : length of the desired substring

SELECT SUBSTR('abcdefg', 3,4);

OUTPUT: cdef

SELECT SUBSTR('abcdefg', -5,4);

OUTPUT: cdef

PreviousChanging the Case of StringsNextTransactions

Last updated 5 years ago

Was this helpful?