Page 173 - Informatics_Practices_Fliipbook_Class12
P. 173

SELECT UCASE("hello world");

               OR
               SELECT UPPER("hello world");
               Output: HELLO WORLD
            2. LCASE() / LOWER()

               The LCASE() and LOWER() functions are used to convert a string to lowercase.
               Example:
               SELECT LCASE("HELLO WORLD");

               OR
               SELECT LOWER("HELLO WORLD");
               Output: hello world
            3.  MID() / SUBSTRING() / SUBSTR()
               The MID(), SUBSTRING(), and SUBSTR()  functions are used to extract a  substring  of a string, given the
               specified starting position and length of the substring.
               Example:
               We extract the substring "world" from the string "hello world", as shown below:
               SELECT MID("hello world", 7, 5);

               OR
               SELECT SUBSTR("hello world", 7, 5);

               OR
               SELECT SUBSTRING("hello world", 7, 5);
               Output: world
            4.  LENGTH()
               The LENGTH() function returns the length of a string in terms of characters.
               SELECT LENGTH("Hello");
               Output: 5

            5.  LEFT()
               The LEFT() function extracts a specified number of characters from the left side of a string.
               Example:

               SELECT LEFT("MySQL", 2);
               Output: My

               In the above example, the LEFT() function extracts the first 2 characters from the string.
               "MySQL".

            6.  RIGHT()
               The RIGHT() function extracts a specified number of characters from the right side of a string.
               Example:
               SELECT RIGHT("MySQL", 3);
               Output: SQL

               In the above example, the RIGHT() function extracts the last 3 characters from the string "MySQL".
            7.  INSTR()
               The INSTR() function returns the position of the first occurrence of a substring within a string.

                                                                                        Database Query using SQL  159
   168   169   170   171   172   173   174   175   176   177   178