mysql> select
lower(name) from donor;
+-----------------+
| lower(name) |
+-----------------+
| stephen daniels |
| jennifer ames |
| carl hersey |
| susan ash |
| nancy taylor |
| robert brooks |
| al richards |
| sarah grove |
| dick stretton |
| john doe |
+-----------------+
10 rows in set (0.00
sec)
mysql> select
max(name) from donor;
+-----------+
| max(name) |
+-----------+
| Susan Ash |
+-----------+
1 row in set (0.00
sec)
http://www.tutorialspoint.com/mysql/mysql-string-functions.htm
mysql> desc
donor;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| idno | varchar(5) | | PRI | | |
| name | varchar(15) | YES |
| NULL | |
| stadr | varchar(15) | YES |
| NULL | |
| city | varchar(10) | YES |
| NULL | |
| state | varchar(2) | YES | | NULL
| |
| zip | varchar(5) | YES | | NULL
| |
| datefst |
date | YES |
| NULL | |
| yrgoal | float(7,2) | YES | | NULL
| |
| contact | varchar(12)
| YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
9 rows in set (0.00
sec)
mysql> select
instr('whatever','ever');
+--------------------------+
|
instr('whatever','ever') |
+--------------------------+
| 5 |
+--------------------------+
1 row in set (0.00
sec)
mysql> select *
from donor;
+-------+-----------------+---------------+------------+-------+-------+------------+---------+-------------+
| idno | name | stadr | city | state | zip |
datefst | yrgoal | contact |
+-------+-----------------+---------------+------------+-------+-------+------------+---------+-------------+
| 11111 | Stephen
Daniels | 123 Elm St | Seekonk | MA
| 02345 | 2002-08-09 | 500.00
| |
| 12121 | Jennifer
Ames | 24 Benefit St | Providence |
RI | 02045 | 2000-11-09 | 400.00 | Susan Jones |
| 22222 | Carl
Hersey | 24 Benefit St | Providence
| RI | 02045 | 2002-09-30 | NULL | Susan Jones |
| 23456 | Susan
Ash | 21 Main St | Fall River | MA | 02720 | 2000-03-04 | 50.00 | Amy Costa |
| 33333 | Nancy
Taylor | 111 North St | Fall River | MA | 02720 | 2004-10-30 |
150.00 | John Adams |
| 34567 | Robert
Brooks | 36 Pine St | Fall River | MA | 02720 | 2003-09-08 | 250.00 | Amy Costa |
| 44444 | Al
Richards | 111 East St | Braintree | MA | 02184 |
2002-10-10 | 300.00 | John Smith |
| 55555 | Sarah
Grove | 123 Elm St | Seekonk | MA | 02345 |
2001-10-12 | 300.00 | John Smith |
| 88888 | Dick
Stretton | 3 South St | Braintree | MA | 02184 |
2002-02-20 | 1000.00 | John Adams |
| 45654 | John
Doe | 123 Elm St | Swansea | MA | 02345 |
2001-10-12 | 300.00 | John Smith |
+-------+-----------------+---------------+------------+-------+-------+------------+---------+-------------+
10 rows in set (0.00
sec)
mysql> select
instr(city,'ee') from donor;
+------------------+
| instr(city,'ee') |
+------------------+
| 2 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 8 |
| 2 |
| 8 |
| 0 |
+------------------+
10 rows in set (0.00
sec)
mysql> select
city, instr(city,'ee') from donor;
+------------+------------------+
| city | instr(city,'ee') |
+------------+------------------+
| Seekonk | 2 |
| Providence | 0 |
| Providence | 0 |
| Fall River | 0 |
| Fall River | 0 |
| Fall River | 0 |
| Braintree | 8 |
| Seekonk | 2 |
| Braintree | 8 |
| Swansea | 0 |
+------------+------------------+
10 rows in set (0.00
sec)
mysql> select
city, left(city,4) from donor;
+------------+--------------+
| city | left(city,4) |
+------------+--------------+
| Seekonk | Seek |
| Providence |
Prov |
| Providence |
Prov |
| Fall River |
Fall |
| Fall River |
Fall |
| Fall River |
Fall |
| Braintree | Brai |
| Seekonk | Seek |
| Braintree | Brai |
| Swansea | Swan |
+------------+--------------+
10 rows in set (0.31
sec)
mysql> select
city, right(city,4) from donor;
+------------+---------------+
| city | right(city,4) |
+------------+---------------+
| Seekonk | konk |
| Providence |
ence |
| Providence |
ence |
| Fall River |
iver |
| Fall River |
iver |
| Fall River |
iver |
| Braintree | tree |
| Seekonk | konk |
| Braintree | tree |
| Swansea | nsea |
+------------+---------------+
10 rows in set (0.00
sec)
mysql> select
city, length(city) from donor;
+------------+--------------+
| city | length(city) |
+------------+--------------+
| Seekonk | 7 |
| Providence | 10 |
| Providence | 10 |
| Fall River | 10 |
| Fall River | 10 |
| Fall River | 10 |
| Braintree |
9 |
| Seekonk | 7 |
| Braintree |
9 |
| Swansea | 7 |
+------------+--------------+
10 rows in set (0.00
sec)
mysql> select
lpad(city,4,'**') from donor;
+-------------------+
| lpad(city,4,'**')
|
+-------------------+
| Seek |
| Prov |
| Prov |
| Fall |
| Fall |
| Fall |
| Brai |
| Seek |
| Brai |
| Swan |
+-------------------+
10 rows in set (0.00
sec)
mysql> select
lpad(city,20,'**') from donor;
+----------------------+
|
lpad(city,20,'**') |
+----------------------+
|
*************Seekonk |
|
**********Providence |
|
**********Providence |
| **********Fall
River |
| **********Fall
River |
| **********Fall
River |
|
***********Braintree |
|
*************Seekonk |
|
***********Braintree |
|
*************Swansea |
+----------------------+
10 rows in set (0.00
sec)
mysql> select
lpad(city,20,'*') from donor;
+----------------------+
|
lpad(city,20,'*') |
+----------------------+
|
*************Seekonk |
|
**********Providence |
|
**********Providence |
| **********Fall
River |
| **********Fall River
|
| **********Fall
River |
|
***********Braintree |
|
*************Seekonk |
|
***********Braintree |
|
*************Swansea |
+----------------------+
10 rows in set (0.00
sec)
Database changed
mysql> select
ltrim(' mine');
+------------------+
| ltrim(' mine') |
+------------------+
| mine |
+------------------+
1 row in set (0.00
sec)
mysql> select
city, mid(city, 2, 3) from donor;
+------------+-----------------+
| city | mid(city, 2, 3) |
+------------+-----------------+
| Seekonk | eek |
| Providence |
rov |
| Providence |
rov |
| Fall River |
all |
| Fall River |
all |
| Fall River |
all |
| Braintree | rai |
| Seekonk | eek |
| Braintree | rai |
| Swansea | wan |
+------------+-----------------+
10 rows in set (0.36
sec)
mysql> select
city, position('ee' in city) from donor;
+------------+------------------------+
| city | position('ee' in city) |
+------------+------------------------+
| Seekonk | 2 |
| Providence | 0 |
| Providence | 0 |
| Fall River | 0 |
| Fall River | 0 |
| Fall River | 0 |
| Braintree | 8 |
| Seekonk | 2 |
| Braintree | 8 |
| Swansea | 0 |
+------------+------------------------+
10 rows in set (0.00
sec)
mysql> select
city, locate('ee',city) from donor;
+------------+-------------------+
| city | locate('ee',city) |
+------------+-------------------+
| Seekonk | 2 |
| Providence | 0 |
| Providence | 0 |
| Fall River | 0 |
| Fall River | 0 |
| Fall River | 0 |
| Braintree | 8 |
| Seekonk | 2 |
| Braintree | 8 |
| Swansea | 0 |
+------------+-------------------+
10 rows in set (0.00
sec)
mysql> select
state, repeat(state,5) from donor;
+-------+-----------------+
| state |
repeat(state,5) |
+-------+-----------------+
| MA | MAMAMAMAMA |
| RI | RIRIRIRIRI |
| RI | RIRIRIRIRI |
| MA | MAMAMAMAMA |
| MA | MAMAMAMAMA |
| MA | MAMAMAMAMA |
| MA | MAMAMAMAMA |
| MA | MAMAMAMAMA |
| MA | MAMAMAMAMA |
| MA | MAMAMAMAMA |
+-------+-----------------+
10 rows in set (0.00
sec)
mysql> select
city, replace(city,'ee','EE') from donor;
+------------+-------------------------+
| city | replace(city,'ee','EE') |
+------------+-------------------------+
| Seekonk | SEEkonk |
| Providence | Providence |
| Providence |
Providence |
| Fall River | Fall
River |
| Fall River | Fall
River |
| Fall River | Fall
River |
| Braintree | BraintrEE |
| Seekonk | SEEkonk |
| Braintree | BraintrEE |
| Swansea | Swansea |
+------------+-------------------------+
10 rows in set (0.00
sec)
mysql> select
city from donor;
+------------+
| city |
+------------+
| Seekonk |
| Providence |
| Providence |
| Fall River |
| Fall River |
| Fall River |
| Braintree |
| Seekonk |
| Braintree |
| Swansea |
+------------+
10 rows in set (0.00
sec)
mysql> select
city, reverse(city) from donor;
+------------+---------------+
| city | reverse(city) |
+------------+---------------+
| Seekonk | knokeeS |
| Providence |
ecnedivorP |
| Providence |
ecnedivorP |
| Fall River | reviR
llaF |
| Fall River | reviR
llaF |
| Fall River | reviR
llaF |
| Braintree | eertniarB |
| Seekonk | knokeeS |
| Braintree | eertniarB |
| Swansea | aesnawS |
+------------+---------------+
10 rows in set (0.00
sec)
mysql> select
city, right(city,2) from donor;
+------------+---------------+
| city | right(city,2) |
+------------+---------------+
| Seekonk | nk |
| Providence |
ce |
| Providence |
ce |
| Fall River |
er |
| Fall River |
er |
| Fall River |
er |
| Braintree | ee |
| Seekonk | nk |
| Braintree | ee |
| Swansea | ea |
+------------+---------------+
10 rows in set (0.00
sec)
mysql> select
substring(city,3) from donor;
+-------------------+
| substring(city,3)
|
+-------------------+
| ekonk |
| ovidence |
| ovidence |
| ll River |
| ll River |
| ll River |
| aintree |
| ekonk |
| aintree |
| ansea |
+-------------------+
10 rows in set (0.00
sec)
mysql> select
city, substring(city,3,4) from donor;
+------------+---------------------+
| city | substring(city,3,4) |
+------------+---------------------+
| Seekonk | ekon |
| Providence |
ovid |
| Providence |
ovid |
| Fall River | ll
R |
| Fall River | ll
R |
| Fall River | ll
R |
| Braintree | aint |
| Seekonk | ekon |
| Braintree | aint
|
| Swansea | anse |
+------------+---------------------+
10 rows in set (0.00
sec)
mysql>