Get cases name and length in the production dept : LENGTH « String « SQL / MySQL






Get cases name and length in the production dept

       
mysql>
mysql> CREATE TABLE IF NOT EXISTS party
    -> (
    ->   id     INT     AUTO_INCREMENT PRIMARY KEY,
    ->   dept CHAR(10), name CHAR(25)
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> # insert 3 records into the "party" table
mysql> INSERT INTO party (dept, name)   VALUES ("accounts", "Graham Miller");
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO party (dept, name)   VALUES ("sales", "Gary Miller");
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO party (dept, name)   VALUES ("production", "Graham Wallace");
Query OK, 1 row affected (0.00 sec)

mysql>
mysql> # get cases name and length in the production dept
mysql> SELECT UPPER(name), LOWER(name), LENGTH(name) FROM party
    -> WHERE dept = "production";
+----------------+----------------+--------------+
| UPPER(name)    | LOWER(name)    | LENGTH(name) |
+----------------+----------------+--------------+
| GRAHAM WALLACE | graham wallace |           14 |
+----------------+----------------+--------------+
1 row in set (0.00 sec)

mysql>
mysql> # delete this sample table
mysql> DROP TABLE IF EXISTS party;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>

   
    
    
    
    
    
    
  








Related examples in the same category

1.LENGTH Function
2.LENGTH(RTRIM(SPACE(8)))
3.LENGTH(CONCAT(CAST(100000 AS CHAR(6)),'000'))
4.Length of trimmed varchar value
5.The length of the shortest verse in the King James Version, that's easy to find
6.Preserving Trailing Spaces in String Columns
7.Determine how many bytes are necessary for storing the data.
8.Lists names from the names table with the longest names first