SlideShare a Scribd company logo
3
Most read
4
Most read
5
Most read
STRING FUNCTION
        IN
       MYSQL
STRING TYPES


 CHAR(M) - A fixed-length string between 1 and 255 characters in
  length (for example CHAR(5)), right-padded with spaces to the
  specified length when stored. Defining a length is not required, but
  the default is 1.

 VARCHAR(M) - A variable-length string between 1 and 255
  characters in length; for example VARCHAR(25). You must define a
  length when creating a VARCHAR field.
String Functions
 CONCAT()      Return concatenated string
 INSTR()       Return the index of the first occurrence of substring
 LCASE()       Synonym for LOWER()
 LEFT()        Return the leftmost number of characters as specified
 LENGTH()      Return the length of a string in bytes
 LOWER()       Return the argument in lowercase
 LTRIM()       Remove leading spaces
 MID()         Return a substring starting from the specified position
 RIGHT()       Return the specified rightmost number of characters
 RTRIM()       Remove trailing spaces
 SUBSTRING(),
              Return the substring as specified
 SUBSTR()
 TRIM()        Remove leading and trailing spaces
 UCASE()       Synonym for UPPER()
 UPPER()       Convert to uppercase
CONCAT(str1,str2,...)

  Returns the string that results from concatenating
  the arguments. May have one or more arguments.
  If all arguments are non-binary strings, the result is
  a non-binary string. If the arguments include any
  binary strings, the result is a binary string. A
  numeric argument is converted to its equivalent
  binary string form; if you want to avoid that, you
  can use an explicit type cast, as in this example:

    mysql> SELECT CONCAT('My', 'S', 'QL');
    +-----------------------------------------------------------------------------+
    | CONTACT (‘My’, ‘S’, ‘QL’)                                                    |
    +-----------------------------------------------------------------------------+
    | MySQL                                                                        |
    +-----------------------------------------------------------------------------+
    1 row in set (0.00 sec)
INSERT(str,pos,len,newstr)

  Returns the string str, with the substring
  beginning at position pos and len characters
  long replaced by the string newstr. Returns the
  original string if pos is not within the length of
  the string. Replaces the rest of the string from
  position pos if len is not within the length of the
  rest of the string. Returns NULL if any argument
  is NULL.

    mysql> SELECT INSERT('Quadratic', 3, 4, 'What');
    +-----------------------------------------------------------------------------+
    | INSERT('Quadratic', 3, 4, 'What')                                            |
    +-----------------------------------------------------------------------------+
    | QuaWhatic                                                                      |
    +-----------------------------------------------------------------------------+
    1 row in set (0.00 sec)
LCASE(str)

  LCASE() is a synonym for LOWER().
  LEFT(str,len)

  Returns the leftmost len characters from the
  string str, or NULL if any argument is NULL.




   mysql> SELECT LEFT('foobarbar', 5);
   +-----------------------------------------------------------------------------+
   | LEFT('foobarbar', 5)                                                        |
   +-----------------------------------------------------------------------------+
   | fooba                                                                        |
   +-----------------------------------------------------------------------------+
   1 row in set (0.00 sec)
LENGTH(str)

  Returns the length of the string str, measured in
  bytes. A multi-byte character counts as
  multiple bytes. This means that for a string
  containing five two-byte characters, LENGTH()
  returns 10, whereas CHAR_LENGTH() returns 5.




                      LENGTH('text');

     LENGTH('text')

     4
LOWER(str)

  Returns the string str with all characters
  changed to lowercase according to the
  current character set mapping.




                     LOWER(‘QUADRATICALLY');

     LOWER(‘QUADRATICALLY')

     quadratically
LTRIM(str)

   Returns the string str with leading space
   characters removed.




                  LTRIM(‘ barbar’);

     LTRIM(‘ barbar')

      barbar
RIGHT(str,len)

  Returns the rightmost len characters from the
  string str, or NULL if any argument is NULL.




                  RIGHT (‘foobarbar’);

     RIGHT(‘foobarbar')

     rbar
MID(str,pos,len) and
  SUBSTRING(str , pos, len)
The forms without a len argument return a substring from
string str starting at position pos. The forms with a len
argument return a substring len characters long from string
str, starting at position pos. The forms that use FROM are
standard SQL syntax. It is also possible to use a negative
value for pos. In this case, the beginning of the substring is
pos characters from the end of the string, rather than the
beginning. A negative value may be used for pos in any of
the forms of this function.
                        SUBSTRING(‘quadratically’, 5, 6);

          SUBSTRING(‘quadratically’, 5, 6)

          ratica
TRIM([remstr FROM] str)

  Returns the string str with all remstr prefixes or
  suffixes removed. If none of the specifiers BOTH,
  LEADING, or TRAILING is given, BOTH is
  assumed. remstr is optional and, if not
  specified, spaces are removed.




                 TRIM(‘ bar ‘);

     TRIM(‘ bar ‘)

     bar
UCASE(str) and UPPER(str)

  • UCASE() is a synonym for UPPER().

  • Returns the string str with all characters
    changed to uppercase according to the
    current character set mapping.




                  UPPER('Allah-hus-samad');

     UPPER('Allah-hus-samad')

     ALLAH-HUS-SAMAD
THANK YOU

More Related Content

What's hot (20)

PPT
Aggregate functions
sinhacp
 
PPTX
introdution to SQL and SQL functions
farwa waqar
 
PPTX
SUBQUERIES.pptx
RenugadeviR5
 
PPTX
Functions in c++
Rokonuzzaman Rony
 
PDF
Set methods in python
deepalishinkar1
 
ODP
Python Modules
Nitin Reddy Katkam
 
PPTX
5. stored procedure and functions
Amrit Kaur
 
PPTX
Triggers
Pooja Dixit
 
PPT
Databases: Normalisation
Damian T. Gordon
 
PPTX
Tuple in python
Sharath Ankrajegowda
 
PPTX
STRUCTURE OF SQL QUERIES
VENNILAV6
 
PPTX
DATABASE CONSTRAINTS
sunanditaAnand
 
PDF
Python list
Mohammed Sikander
 
PPTX
Database : Relational Data Model
Smriti Jain
 
PPTX
1.2 sql create and drop table
MLG College of Learning, Inc
 
PDF
Strings in python
Prabhakaran V M
 
PPTX
Datatype in c++ unit 3 -topic 2
MOHIT TOMAR
 
PPTX
java interface and packages
VINOTH R
 
PDF
Python programming : Files
Emertxe Information Technologies Pvt Ltd
 
Aggregate functions
sinhacp
 
introdution to SQL and SQL functions
farwa waqar
 
SUBQUERIES.pptx
RenugadeviR5
 
Functions in c++
Rokonuzzaman Rony
 
Set methods in python
deepalishinkar1
 
Python Modules
Nitin Reddy Katkam
 
5. stored procedure and functions
Amrit Kaur
 
Triggers
Pooja Dixit
 
Databases: Normalisation
Damian T. Gordon
 
Tuple in python
Sharath Ankrajegowda
 
STRUCTURE OF SQL QUERIES
VENNILAV6
 
DATABASE CONSTRAINTS
sunanditaAnand
 
Python list
Mohammed Sikander
 
Database : Relational Data Model
Smriti Jain
 
1.2 sql create and drop table
MLG College of Learning, Inc
 
Strings in python
Prabhakaran V M
 
Datatype in c++ unit 3 -topic 2
MOHIT TOMAR
 
java interface and packages
VINOTH R
 
Python programming : Files
Emertxe Information Technologies Pvt Ltd
 

Similar to String function in my sql (20)

PPTX
MySQL String Functions.pptx
MayankSharma867296
 
PPTX
MySQL 5.7 String Functions
Francesco Marino
 
PPT
Character function in MySQL | Oracle
Vimal Raj
 
DOCX
Mysql Functions with examples CBSE INDIA 11th class NCERT
Harish Gyanani
 
DOCX
MySQL String Functions.docx
RUBAB79
 
PDF
6-Final MySQL Library Functions.pdf
Surendrasingh211500
 
PPTX
string functions in SQL ujjwal matoliya.pptx
ujjwalmatoliya
 
PPTX
character function in database managemnet system
anjanasharma77573
 
ODP
Mysql1
rajikaa
 
PPT
Sql operators & functions 3
Dr. C.V. Suresh Babu
 
ODP
Mysql
merlin deepika
 
PPT
Mysql
HAINIRMALRAJ
 
PPTX
String functions
Kumar Krishnan
 
PPTX
Structured query language functions
Vineeta Garg
 
PPTX
SQL python for beginners easy explanation with concepts and output .pptx
harshitagrawal2608
 
PPTX
V23 function-2
Dhirendra Chauhan
 
PPTX
MYSQL single rowfunc-multirowfunc-groupby-having
Ahmed Farag
 
PDF
Mysqlfunctions
N13M
 
PDF
sql functions3 (1).pdf
Usha570012
 
MySQL String Functions.pptx
MayankSharma867296
 
MySQL 5.7 String Functions
Francesco Marino
 
Character function in MySQL | Oracle
Vimal Raj
 
Mysql Functions with examples CBSE INDIA 11th class NCERT
Harish Gyanani
 
MySQL String Functions.docx
RUBAB79
 
6-Final MySQL Library Functions.pdf
Surendrasingh211500
 
string functions in SQL ujjwal matoliya.pptx
ujjwalmatoliya
 
character function in database managemnet system
anjanasharma77573
 
Mysql1
rajikaa
 
Sql operators & functions 3
Dr. C.V. Suresh Babu
 
String functions
Kumar Krishnan
 
Structured query language functions
Vineeta Garg
 
SQL python for beginners easy explanation with concepts and output .pptx
harshitagrawal2608
 
V23 function-2
Dhirendra Chauhan
 
MYSQL single rowfunc-multirowfunc-groupby-having
Ahmed Farag
 
Mysqlfunctions
N13M
 
sql functions3 (1).pdf
Usha570012
 
Ad

Recently uploaded (20)

PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PDF
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PDF
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
Council of Chalcedon Re-Examined
Smiling Lungs
 
PPTX
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Horarios de distribución de agua en julio
pegazohn1978
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Council of Chalcedon Re-Examined
Smiling Lungs
 
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
Controller Request and Response in Odoo18
Celine George
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Ad

String function in my sql

  • 1. STRING FUNCTION IN MYSQL
  • 2. STRING TYPES  CHAR(M) - A fixed-length string between 1 and 255 characters in length (for example CHAR(5)), right-padded with spaces to the specified length when stored. Defining a length is not required, but the default is 1.  VARCHAR(M) - A variable-length string between 1 and 255 characters in length; for example VARCHAR(25). You must define a length when creating a VARCHAR field.
  • 3. String Functions CONCAT() Return concatenated string INSTR() Return the index of the first occurrence of substring LCASE() Synonym for LOWER() LEFT() Return the leftmost number of characters as specified LENGTH() Return the length of a string in bytes LOWER() Return the argument in lowercase LTRIM() Remove leading spaces MID() Return a substring starting from the specified position RIGHT() Return the specified rightmost number of characters RTRIM() Remove trailing spaces SUBSTRING(), Return the substring as specified SUBSTR() TRIM() Remove leading and trailing spaces UCASE() Synonym for UPPER() UPPER() Convert to uppercase
  • 4. CONCAT(str1,str2,...) Returns the string that results from concatenating the arguments. May have one or more arguments. If all arguments are non-binary strings, the result is a non-binary string. If the arguments include any binary strings, the result is a binary string. A numeric argument is converted to its equivalent binary string form; if you want to avoid that, you can use an explicit type cast, as in this example: mysql> SELECT CONCAT('My', 'S', 'QL'); +-----------------------------------------------------------------------------+ | CONTACT (‘My’, ‘S’, ‘QL’) | +-----------------------------------------------------------------------------+ | MySQL | +-----------------------------------------------------------------------------+ 1 row in set (0.00 sec)
  • 5. INSERT(str,pos,len,newstr) Returns the string str, with the substring beginning at position pos and len characters long replaced by the string newstr. Returns the original string if pos is not within the length of the string. Replaces the rest of the string from position pos if len is not within the length of the rest of the string. Returns NULL if any argument is NULL. mysql> SELECT INSERT('Quadratic', 3, 4, 'What'); +-----------------------------------------------------------------------------+ | INSERT('Quadratic', 3, 4, 'What') | +-----------------------------------------------------------------------------+ | QuaWhatic | +-----------------------------------------------------------------------------+ 1 row in set (0.00 sec)
  • 6. LCASE(str) LCASE() is a synonym for LOWER(). LEFT(str,len) Returns the leftmost len characters from the string str, or NULL if any argument is NULL. mysql> SELECT LEFT('foobarbar', 5); +-----------------------------------------------------------------------------+ | LEFT('foobarbar', 5) | +-----------------------------------------------------------------------------+ | fooba | +-----------------------------------------------------------------------------+ 1 row in set (0.00 sec)
  • 7. LENGTH(str) Returns the length of the string str, measured in bytes. A multi-byte character counts as multiple bytes. This means that for a string containing five two-byte characters, LENGTH() returns 10, whereas CHAR_LENGTH() returns 5. LENGTH('text'); LENGTH('text') 4
  • 8. LOWER(str) Returns the string str with all characters changed to lowercase according to the current character set mapping. LOWER(‘QUADRATICALLY'); LOWER(‘QUADRATICALLY') quadratically
  • 9. LTRIM(str) Returns the string str with leading space characters removed. LTRIM(‘ barbar’); LTRIM(‘ barbar') barbar
  • 10. RIGHT(str,len) Returns the rightmost len characters from the string str, or NULL if any argument is NULL. RIGHT (‘foobarbar’); RIGHT(‘foobarbar') rbar
  • 11. MID(str,pos,len) and SUBSTRING(str , pos, len) The forms without a len argument return a substring from string str starting at position pos. The forms with a len argument return a substring len characters long from string str, starting at position pos. The forms that use FROM are standard SQL syntax. It is also possible to use a negative value for pos. In this case, the beginning of the substring is pos characters from the end of the string, rather than the beginning. A negative value may be used for pos in any of the forms of this function. SUBSTRING(‘quadratically’, 5, 6); SUBSTRING(‘quadratically’, 5, 6) ratica
  • 12. TRIM([remstr FROM] str) Returns the string str with all remstr prefixes or suffixes removed. If none of the specifiers BOTH, LEADING, or TRAILING is given, BOTH is assumed. remstr is optional and, if not specified, spaces are removed. TRIM(‘ bar ‘); TRIM(‘ bar ‘) bar
  • 13. UCASE(str) and UPPER(str) • UCASE() is a synonym for UPPER(). • Returns the string str with all characters changed to uppercase according to the current character set mapping. UPPER('Allah-hus-samad'); UPPER('Allah-hus-samad') ALLAH-HUS-SAMAD