
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to cut only the first character in MySQL string?
To cut only the first character, use the substr() function with UPDATE command. The syntax is as follows.
UPDATE yourTableName set yourColumnName=substr(yourColumnName,2);
To understand the above syntax, let us first create a table. The query to create a table is as follows.
mysql> create table CutStringDemo -> ( -> Value varchar(100) -> ); Query OK, 0 rows affected (0.66 sec)
Now you can insert some records in the table using insert command. The query is as follows.
mysql> insert into CutStringDemo values(',12,3456'); Query OK, 1 row affected (0.14 sec) mysql> insert into CutStringDemo values(',23,9867'); Query OK, 1 row affected (0.16 sec) mysql> insert into CutStringDemo values(',20,3212'); Query OK, 1 row affected (0.12 sec) mysql> insert into CutStringDemo values(',23456,1234'); Query OK, 1 row affected (0.14 sec)
Now you can display all records from the table using select statement. The query is as follows.
mysql> select *from CutStringDemo;
The following is the output.
+-------------+ | Value | +-------------+ | ,12,3456 | | ,23,9867 | | ,20,3212 | | ,23456,1234 | +-------------+ 4 rows in set (0.00 sec)
Now let us cut the first character from the column Value. The query is as follows.
mysql> update CutStringDemo set Value=substr(Value,2); Query OK, 4 rows affected (0.20 sec) Rows matched: 4 Changed: 4 Warnings: 0
Now you can check that the first character has been removed from the column Value or not. To display all records from the table, use the SELECT statement. The query is as follows.
mysql> select *from CutStringDemo;
The following is the output displaying that the first character successfully removed.
+------------+ | Value | +------------+ | 12,3456 | | 23,9867 | | 20,3212 | | 23456,1234 | +------------+ 4 rows in set (0.00 sec)
- Related Articles
- How to replace only the first repeated value in a string in MySQL
- Select all except the first character in a string in MySQL?
- How to remove the first character of string in PHP?
- Remove all except the first character of a string in MySQL?
- How to find the first character of a string in C#?
- Perform search/replace for only the first occurrence of a character in MySQL table records?
- How to remove the first and last character in a string in R?
- Perform search/replace for only the first occurrence of a character with session variable in MySQL
- How to remove only last character from a string vector in R?
- How to print the first character of each word in a String in Java?
- Return only the first 15 characters from a column with string values in MySQL
- How to cut part of a string with a MySQL query?
- How to ORDER BY last 2 character string in MySQL?
- First Unique Character in a String in Python
- Filter column value by the first character in MySQL
