0% found this document useful (0 votes)
10 views7 pages

STRING)

The document demonstrates how to create a database and table in MySQL, insert data, and perform various string functions like concatenation, upper/lower case conversion, substring, length, left, right, and trim. It creates a database called VIMAL and a table called SCHOOL to store student data, inserts sample records, and runs queries to select, manipulate and display the data.

Uploaded by

nihalparteti26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views7 pages

STRING)

The document demonstrates how to create a database and table in MySQL, insert data, and perform various string functions like concatenation, upper/lower case conversion, substring, length, left, right, and trim. It creates a database called VIMAL and a table called SCHOOL to store student data, inserts sample records, and runs queries to select, manipulate and display the data.

Uploaded by

nihalparteti26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

mysql> CREATE DATABASE VIMAL;

Query OK, 1 row affected (0.05 sec)

mysql> SHOW DATABASES;

+--------------------+

| Database |

+--------------------+

| vimal |

+--------------------+

8 rows in set (0.00 sec)

mysql> USE VIMAL;

Database changed

mysql> CREATE TABLE SCHOOL

-> (

-> SR_NO INT PRIMARY KEY,

-> S_NAME VARCHAR(20),

-> CLASS INT,

-> ROLL_NO INT,

-> MARKS INT);

Query OK, 0 rows affected (0.11 sec)

mysql> DESCRIBE SCHOOL;

+---------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+---------+-------------+------+-----+---------+-------+

| SR_NO | int | NO | PRI | NULL | |

| S_NAME | varchar(20) | YES | | NULL | |

| CLASS | int | YES | | NULL | |


| ROLL_NO | int | YES | | NULL | |

| MARKS | int | YES | | NULL | |

+---------+-------------+------+-----+---------+-------+

5 rows in set (0.01 sec)

mysql> INSERT SCHOOL

-> VALUES(1,'VIMAL',12,5,60),

-> (2,'OM',12,6,55),

-> (3,'SHIVA',12,8,65),

-> (4,'KARAN',11,9,45),

-> (5,'RAM',10,15,50);

Query OK, 5 rows affected (0.02 sec)

Records: 5 Duplicates: 0 Warnings: 0

mysql> SELECT* FROM SCHOOL;

+-------+--------+-------+---------+-------+

| SR_NO | S_NAME | CLASS | ROLL_NO | MARKS |

+-------+--------+-------+---------+-------+

| 1 | VIMAL | 12 | 5 | 60 |

| 2 | OM | 12 | 6 | 55 |

| 3 | SHIVA | 12 | 8 | 65 |

| 4 | KARAN | 11 | 9 | 45 |

| 5 | RAM | 10 | 15 | 50 |

+-------+--------+-------+---------+-------+

5 rows in set (0.00 sec)

mysql> SELECT S_NAME,CLASS, CONCAT(S_NAME,CLASS)FROM SCHOOL;

+---------+-------+----------------------+

| S_NAME | CLASS | CONCAT(S_NAME,CLASS) |


+---------+-------+----------------------+

| VIMAL | 12 | VIMAL12 |

| OM | 12 | OM12 |

| SHIVA | 12 | SHIVA12 |

| KARAN | 11 | KARAN11 |

| RAM | 10 | RAM10 |

| SHYAM | 9 | SHYAM9 |

| MOHAN | 5 | MOHAN5 |

| KRISHNA | 7 | KRISHNA7 |

| hariom | 10 | hariom10 |

| SHYAM | 10 | SHYAM10 |

+---------+-------+----------------------+

10 rows in set (0.00 sec)

mysql> SELECT S_NAME, LOWER(S_NAME)FROM SCHOOL;

+---------+---------------+

| S_NAME | LOWER(S_NAME) |

+---------+---------------+

| VIMAL | vimal |

| OM | om |

| SHIVA | shiva |

| KARAN | karan |

| RAM | ram |

| SHYAM | shyam |

| MOHAN | mohan |

| KRISHNA | krishna |

| hariom | hariom |

| SHYAM | shyam |

+---------+---------------+

10 rows in set (0.01 sec)


mysql> SELECT S_NAME ,UCASE(S_NAME) FROM SCHOOL;

+---------+---------------+

| S_NAME | UCASE(S_NAME) |

+---------+---------------+

| VIMAL | VIMAL |

| OM | OM |

| SHIVA | SHIVA |

| KARAN | KARAN |

| RAM | RAM |

| SHYAM | SHYAM |

| MOHAN | MOHAN |

| KRISHNA | KRISHNA |

| hariom | HARIOM |

| SHYAM | SHYAM |

+---------+---------------+

10 rows in set (0.00 sec)

mysql> SELECT INSTR('HARIOMBAPUJI','B') FROM DUAL;

+---------------------------+

| INSTR('HARIOMBAPUJI','B') |

+---------------------------+

| 7|

+---------------------------+

1 row in set (0.00 sec)

mysql> SELECT S_NAME, LENGTH(S_NAME)FROM SCHOOL;

+---------+----------------+

| S_NAME | LENGTH(S_NAME) |

+---------+----------------+

| VIMAL | 5|
| OM | 2|

| SHIVA | 5|

| KARAN | 5|

| RAM | 3|

| SHYAM | 5|

| MOHAN | 5|

| KRISHNA | 7|

| hariom | 6|

| SHYAM | 5|

+---------+----------------+

10 rows in set (0.00 sec)

mysql> SELECT S_NAME, LENGTH(S_NAME),CLASS, LENGTH(CLASS)FROM SCHOOL;

+---------+----------------+-------+---------------+

| S_NAME | LENGTH(S_NAME) | CLASS | LENGTH(CLASS) |

+---------+----------------+-------+---------------+

| VIMAL | 5 | 12 | 2|

| OM | 2 | 12 | 2|

| SHIVA | 5 | 12 | 2|

| KARAN | 5 | 11 | 2|

| RAM | 3 | 10 | 2|

| SHYAM | 5| 9| 1|

| MOHAN | 5| 5| 1|

| KRISHNA | 7| 7| 1|

| hariom | 6 | 10 | 2|

| SHYAM | 5 | 10 | 2|

+---------+----------------+-------+---------------+

10 rows in set (0.00 sec)


mysql> SELECT RIGHT('VIMALKUMAR',5)AS 'VIMALKUMAR';

+------------+

| VIMALKUMAR |

+------------+

| KUMAR |

+------------+

1 row in set (0.00 sec)

mysql> SELECT LEFT('VIMALKUMAR',5)AS 'VIMALKUMAR';

+------------+

| VIMALKUMAR |

+------------+

| VIMAL |

+------------+

1 row in set (0.00 sec)

mysql> SELECT SUBSTR('VIMALKUMAR',1,5) AS 'VIMALKUMAR';

+------------+

| VIMALKUMAR |

+------------+

| VIMAL |

+------------+

1 row in set (0.00 sec)

mysql> SELECT LTRIM(' VIMALKUMAR ') AS ' VIMALKUMAR ';

+-----------------+

| VIMALKUMAR |

+-----------------+

| VIMALKUMAR |

+-----------------+

1 row in set, 1 warning (0.00 sec)


mysql> SELECT RTRIM(' VIMALKUMAR ') AS ' VIMALKUMAR ';

+-----------------+

| VIMALKUMAR |

+-----------------+

| VIMALKUMAR |

+-----------------+

1 row in set, 1 warning (0.00 sec)

You might also like