0% found this document useful (0 votes)
6 views

MYSQL warnings, string functions

The document contains a series of MySQL commands executed in a Windows environment, showcasing database operations such as creating databases and tables, inserting data, and performing queries. It includes examples of error handling, data type casting, and string manipulation functions. The document also demonstrates the use of SQL modes and the display of warnings and errors during the execution of commands.

Uploaded by

v.manohar792
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

MYSQL warnings, string functions

The document contains a series of MySQL commands executed in a Windows environment, showcasing database operations such as creating databases and tables, inserting data, and performing queries. It includes examples of error handling, data type casting, and string manipulation functions. The document also demonstrates the use of SQL modes and the display of warnings and errors during the execution of commands.

Uploaded by

v.manohar792
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

Microsoft Windows [Version 10.0.22621.

2861]
(c) Microsoft Corporation. All rights reserved.

C:\Users\V.MANOHAR>mysql -u root -p
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.34 MySQL Community Server - GPL

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SELECT 10/2;


+--------+
| 10/2 |
+--------+
| 5.0000 |
+--------+
1 row in set (0.01 sec)

mysql> SELECT 10/0;


+------+
| 10/0 |
+------+
| NULL |
+------+
1 row in set, 1 warning (0.05 sec)

mysql> SHOW WARNINGS;


+---------+------+---------------+
| Level | Code | Message |
+---------+------+---------------+
| Warning | 1365 | Division by 0 |
+---------+------+---------------+
1 row in set (0.00 sec)

mysql> SHOW DATABASES;


+--------------------+
| Database |
+--------------------+
| codegnan |
| information_schema |
| librarydb |
| mysql |
| performance_schema |
| sys |
+--------------------+
6 rows in set (0.07 sec)

mysql> USE CODEGNAN;


Database changed
mysql> CREATE TABLE MYTABLE(
-> ID INT PRIMARY KEY,
-> NAME VARCHAR(5)
-> );
Query OK, 0 rows affected (0.07 sec)

mysql> SELECT * FROM MYTABLE;


Empty set (0.01 sec)

mysql> DESC MYTABLE;


+-------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------+------+-----+---------+-------+
| ID | int | NO | PRI | NULL | |
| NAME | varchar(5) | YES | | NULL | |
+-------+------------+------+-----+---------+-------+
2 rows in set (0.06 sec)

mysql> INSERT INTO MYTABLE (ID, NAME)


-> VALUES(1,"THISISLONGSTRING");
ERROR 1406 (22001): Data too long for column 'NAME' at row 1
mysql> SHOW ERRORS;
+-------+------+------------------------------------------+
| Level | Code | Message |
+-------+------+------------------------------------------+
| Error | 1406 | Data too long for column 'NAME' at row 1 |
+-------+------+------------------------------------------+
1 row in set (0.00 sec)

mysql> SHOW WARNINGS;


+-------+------+------------------------------------------+
| Level | Code | Message |
+-------+------+------------------------------------------+
| Error | 1406 | Data too long for column 'NAME' at row 1 |
+-------+------+------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT '123ABC'+1;


+------------+
| '123ABC'+1 |
+------------+
| 124 |
+------------+
1 row in set, 1 warning (0.01 sec)

mysql> SHOW WARNINGS;


+---------+------+--------------------------------------------+
| Level | Code | Message |
+---------+------+--------------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: '123ABC' |
+---------+------+--------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT CONCAT('123ABC', 1);


+---------------------+
| CONCAT('123ABC', 1) |
+---------------------+
| 123ABC1 |
+---------------------+
1 row in set (0.01 sec)

mysql> SHOW WARNINGS;


Empty set (0.00 sec)

mysql> SET SQL_MODE = 'STRICT_ALL_TABLES';


Query OK, 0 rows affected, 1 warning (0.05 sec)

mysql> SHOW WARTNINGS;


ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'WARTNINGS' at line 1
mysql> SHOW WARNINGS;
+-------+------
+----------------------------------------------------------------------------------
---------------------------------------------------------------------------+
| Level | Code | Message
|
+-------+------
+----------------------------------------------------------------------------------
---------------------------------------------------------------------------+
| Error | 1064 | You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'WARTNINGS' at line 1 |
+-------+------
+----------------------------------------------------------------------------------
---------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> SET SQL_MODE = 'STRICT_ALL_TABLES';


Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> SELECT CAST('2022-02-25' AS DATE);


+----------------------------+
| CAST('2022-02-25' AS DATE) |
+----------------------------+
| 2022-02-25 |
+----------------------------+
1 row in set (0.01 sec)

mysql> SELECT CAST('2022-02-30' AS DATE);


+----------------------------+
| CAST('2022-02-30' AS DATE) |
+----------------------------+
| NULL |
+----------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> SHOW WARNINGS;


+---------+------+----------------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------------+
| Warning | 1292 | Incorrect datetime value: '2022-02-30' |
+---------+------+----------------------------------------+
1 row in set (0.00 sec)

mysql> -- CREATE THE DATABASE


mysql> CREATE DATABASE PRODUCT_DETAILS;
Query OK, 1 row affected (0.00 sec)

mysql> SHOW DATABASES;


+--------------------+
| Database |
+--------------------+
| codegnan |
| information_schema |
| librarydb |
| mysql |
| performance_schema |
| product_details |
| sys |
+--------------------+
7 rows in set (0.00 sec)

mysql> USE PRODUCT_DETAILS;


Database changed
mysql> CREATE TABLE PRODUCTS(
-> PRODUCT_ID INT PRIMARY KEY,
-> PRODUCT_NAME VARCHAR(100),
-> CATEGORY VARCHAR(50),
-> PRICE DECIMAL(8,2)
-> );
Query OK, 0 rows affected (0.01 sec)

mysql> DESC PRODUCTS;


+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| PRODUCT_ID | int | NO | PRI | NULL | |
| PRODUCT_NAME | varchar(100) | YES | | NULL | |
| CATEGORY | varchar(50) | YES | | NULL | |
| PRICE | decimal(8,2) | YES | | NULL | |
+--------------+--------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> -- INSERT DATA


mysql> INSERT INTO PRODUCTS(PRODUCT_ID,PRODUCT_NAME,CATEGORY,PRICE)VALUES
-> (1,'LAPTOP','ELECTRONICS',1200.00),
-> (2,'HEADPHONES','ELECTRONICS',99.99),
-> (3,'T-SHIRT','APPAREL',19.99),
-> (4,'COFFEE MAKER','APPLIANCES',49.99);
Query OK, 4 rows affected (0.01 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> SELECT * FROM PRODUCTS;


+------------+--------------+-------------+---------+
| PRODUCT_ID | PRODUCT_NAME | CATEGORY | PRICE |
+------------+--------------+-------------+---------+
| 1 | LAPTOP | ELECTRONICS | 1200.00 |
| 2 | HEADPHONES | ELECTRONICS | 99.99 |
| 3 | T-SHIRT | APPAREL | 19.99 |
| 4 | COFFEE MAKER | APPLIANCES | 49.99 |
+------------+--------------+-------------+---------+
4 rows in set (0.00 sec)

mysql> -- ALIAS
mysql> SELECT * FROM PRODUCTS;
+------------+--------------+-------------+---------+
| PRODUCT_ID | PRODUCT_NAME | CATEGORY | PRICE |
+------------+--------------+-------------+---------+
| 1 | LAPTOP | ELECTRONICS | 1200.00 |
| 2 | HEADPHONES | ELECTRONICS | 99.99 |
| 3 | T-SHIRT | APPAREL | 19.99 |
| 4 | COFFEE MAKER | APPLIANCES | 49.99 |
+------------+--------------+-------------+---------+
4 rows in set (0.00 sec)

mysql> SELECT PRODUCT_NAME AS 'PRODUCT', CATEGORY AS 'PRODUCT CATEGORY',PRICE AS


'PRODUCT PRICE'
-> FROM PRODUCTS;
+--------------+------------------+---------------+
| PRODUCT | PRODUCT CATEGORY | PRODUCT PRICE |
+--------------+------------------+---------------+
| LAPTOP | ELECTRONICS | 1200.00 |
| HEADPHONES | ELECTRONICS | 99.99 |
| T-SHIRT | APPAREL | 19.99 |
| COFFEE MAKER | APPLIANCES | 49.99 |
+--------------+------------------+---------------+
4 rows in set (0.05 sec)

mysql> SELECT * FROM PRODUCTS;


+------------+--------------+-------------+---------+
| PRODUCT_ID | PRODUCT_NAME | CATEGORY | PRICE |
+------------+--------------+-------------+---------+
| 1 | LAPTOP | ELECTRONICS | 1200.00 |
| 2 | HEADPHONES | ELECTRONICS | 99.99 |
| 3 | T-SHIRT | APPAREL | 19.99 |
| 4 | COFFEE MAKER | APPLIANCES | 49.99 |
+------------+--------------+-------------+---------+
4 rows in set (0.00 sec)

mysql> -- CONCAT
mysql> SELECT CONCAT(PRODUCT_NAME,CATEGORY) AS 'CONCACTENATED' FROM PRODUCTS;
+------------------------+
| CONCACTENATED |
+------------------------+
| LAPTOPELECTRONICS |
| HEADPHONESELECTRONICS |
| T-SHIRTAPPAREL |
| COFFEE MAKERAPPLIANCES |
+------------------------+
4 rows in set (0.00 sec)

mysql> SELECT CONCAT_WS(', ' ,PRODUCT_NAME,CATEGORY) AS 'CONCACTENATED WITH


SEPERATOR' FROM PRODUCTS;
+------------------------------+
| CONCACTENATED WITH SEPERATOR |
+------------------------------+
| LAPTOP, ELECTRONICS |
| HEADPHONES, ELECTRONICS |
| T-SHIRT, APPAREL |
| COFFEE MAKER, APPLIANCES |
+------------------------------+
4 rows in set (0.00 sec)

mysql> SELECT LOWER(PRODUCT_NAME) AS 'LOWECASE',


-> UPPER(CATEGORY) AS 'UPPERCASE'
-> FROM PRODUCTS;
+--------------+-------------+
| LOWECASE | UPPERCASE |
+--------------+-------------+
| laptop | ELECTRONICS |
| headphones | ELECTRONICS |
| t-shirt | APPAREL |
| coffee maker | APPLIANCES |
+--------------+-------------+
4 rows in set (0.06 sec)

mysql> -- LENGTH AND SUBSTRING


mysql> SELECT PRODUCT_NAME,
-> LENGTH(PRODUCT_NAME) AS 'LENGTH',
-> SUBSTRING(PRODUCT_NAME, 2, 3) AS 'SUBSTRING'
-> FROM PRODUCTS;
+--------------+--------+-----------+
| PRODUCT_NAME | LENGTH | SUBSTRING |
+--------------+--------+-----------+
| LAPTOP | 6 | APT |
| HEADPHONES | 10 | EAD |
| T-SHIRT | 7 | -SH |
| COFFEE MAKER | 12 | OFF |
+--------------+--------+-----------+
4 rows in set (0.00 sec)

mysql> -- REVERSE AND REPLACE


mysql> SELECT REVERSE(PRODUCT_NAME) AS 'REVERSED',
-> REPLACE(CATEGORY, 'ELECTRONICS','GADGETS') AS 'REPLACED'
-> FROM PRODUCTS;
+--------------+------------+
| REVERSED | REPLACED |
+--------------+------------+
| POTPAL | GADGETS |
| SENOHPDAEH | GADGETS |
| TRIHS-T | APPAREL |
| REKAM EEFFOC | APPLIANCES |
+--------------+------------+
4 rows in set (0.06 sec)

mysql> -- LEFT AND RIGHT


mysql> SELECT PRODUCT_NAME,
-> LEFT(PRODUCT_NAME, 3) AS 'LEFT',
-> RIGHT(CATEGORY, 2) AS 'RIGHT'
-> FROM PRODUCTS;
+--------------+------+-------+
| PRODUCT_NAME | LEFT | RIGHT |
+--------------+------+-------+
| LAPTOP | LAP | CS |
| HEADPHONES | HEA | CS |
| T-SHIRT | T-S | EL |
| COFFEE MAKER | COF | ES |
+--------------+------+-------+
4 rows in set (0.00 sec)

mysql> SELECT PRODUCT_NAME,


-> LEFT(PRODUCT_NAME, 3) AS 'LEFT'
-> FROM PRODUCTS;
+--------------+------+
| PRODUCT_NAME | LEFT |
+--------------+------+
| LAPTOP | LAP |
| HEADPHONES | HEA |
| T-SHIRT | T-S |
| COFFEE MAKER | COF |
+--------------+------+
4 rows in set (0.00 sec)

mysql> SELECT CATEGORY,


-> RIGHT(CATEGORY, 2) AS 'RIGHT'
-> FROM PRODUCTS;
+-------------+-------+
| CATEGORY | RIGHT |
+-------------+-------+
| ELECTRONICS | CS |
| ELECTRONICS | CS |
| APPAREL | EL |
| APPLIANCES | ES |
+-------------+-------+
4 rows in set (0.00 sec)

mysql>

You might also like