NellyIvanova29

CarsProcedures

Nov 23rd, 2021 (edited)
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 14.51 KB | None | 0 0
  1.  
  2. Setting environment for using XAMPP for Windows.
  3. nelly@NELLYIVANOVA c:\xampp
  4. # mysql -uroot
  5. Welcome to the MariaDB monitor.  Commands end with ; or \g.
  6. Your MariaDB connection id is 29
  7. Server version: 10.4.21-MariaDB mariadb.org binary distribution
  8.  
  9. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  10.  
  11. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  12.  
  13. MariaDB [(none)]> show databases;
  14. +--------------------+
  15. | Database           |
  16. +--------------------+
  17. | cars               |
  18. | clients2610        |
  19. | company            |
  20. | continents         |
  21. | datachanges        |
  22. | information_schema |
  23. | mysql              |
  24. | performance_schema |
  25. | personal           |
  26. | phpmyadmin         |
  27. | reservations       |
  28. | shoot              |
  29. | test               |
  30. | uni                |
  31. +--------------------+
  32. 14 rows in set (0.021 sec)
  33.  
  34. MariaDB [(none)]> use cars;
  35. Database changed
  36. MariaDB [cars]> INSERT INTO used_cars_data (model, year, price, transmission, mileage, fueltype, tax, mpg, enginesize) VALUES("mercedes benz", "2015", "80000", "automatic" ,"18" ,"gasoline",10, 20, 2.3);
  37. Query OK, 1 row affected (0.025 sec)
  38.  
  39. MariaDB [cars]> INSERT INTO used_cars_data (model, year, price, transmission, mileage, fueltype, tax, mpg, enginesize) VALUES("BMW G32", "2018", "80000", "automatic" ,"18" ,"gasoline",10, 20, 2.2);
  40. Query OK, 1 row affected (0.009 sec)
  41.  
  42. MariaDB [cars]> select* from used_cars_data;
  43. +-------------------+------+--------+--------------+---------+----------+------+------+------------+
  44. | model             | year | price  | transmission | mileage | fueltype | tax  | mpg  | enginesize |
  45. +-------------------+------+--------+--------------+---------+----------+------+------+------------+
  46. | volkswagen tiguan | 2010 |  12500 | manual       |  180000 | diesel   |    5 |    6 |          2 |
  47. | toyota taris      | 2019 | 125000 | automatic    |    1800 | hybrid   |    5 |   10 |          2 |
  48. | toyota hilux      | 2020 | 160000 | automatic    |     100 | hybrid   |    5 |   18 |        2.2 |
  49. | mercedes benz     | 2021 | 200000 | manual       |      20 | electric |   10 |   20 |        2.3 |
  50. | mercedes benz     | 2018 | 100000 | automatic    |      18 | diesel   |   10 |   20 |        2.3 |
  51. | mercedes benz     | 2015 |  80000 | automatic    |      18 | gasoline |   10 |   20 |        2.3 |
  52. | BMW G32           | 2018 |  80000 | automatic    |      18 | gasoline |   10 |   20 |        2.2 |
  53. +-------------------+------+--------+--------------+---------+----------+------+------+------------+
  54. 7 rows in set (0.010 sec)
  55.  
  56. MariaDB [cars]> DELIMITER |
  57. MariaDB [cars]>
  58. MariaDB [cars]> CREATE PROCEDURE Showcars()
  59.     -> BEGIN
  60.     -> SELECT model, year, price  FROM used_cars_data;
  61.     -> END |
  62. Query OK, 0 rows affected (0.027 sec)
  63.  
  64. MariaDB [cars]>
  65. MariaDB [cars]> DELIMITER ;
  66. MariaDB [cars]> select* from used_cars_data where model="toyota%";
  67. Empty set (0.011 sec)
  68.  
  69. MariaDB [cars]> select* from used_cars_data where model='toyota %';
  70. Empty set (0.001 sec)
  71.  
  72. MariaDB [cars]> SELECT * FROM table WHERE myword REGEXP '^.*toyota.*$
  73.    '> ;
  74.     '> ;
  75.    '> Bye
  76.  
  77. nelly@NELLYIVANOVA c:\xampp
  78. # mysql -uroot;
  79. ERROR 1045 (28000): Access denied for user 'root;'@'localhost' (using password: NO)
  80.  
  81. nelly@NELLYIVANOVA c:\xampp
  82. # mysql -uroot
  83. Welcome to the MariaDB monitor.  Commands end with ; or \g.
  84. Your MariaDB connection id is 31
  85. Server version: 10.4.21-MariaDB mariadb.org binary distribution
  86.  
  87. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  88.  
  89. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  90.  
  91. MariaDB [(none)]> use cars;
  92. Database changed
  93. MariaDB [cars]> SELECT * FROM table WHERE model REGEXP '[[:<:]]toyota[[:>:]]'
  94.     ->
  95.     -> ;
  96. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'table WHERE model REGEXP '[[:<:]]toyota[[:>:]]'' at line 1
  97. MariaDB [cars]> SELECT * FROM used_cars_data WHERE model REGEXP '[[:<:]]toyota[[:>:]]';
  98. +--------------+------+--------+--------------+---------+----------+------+------+------------+
  99. | model        | year | price  | transmission | mileage | fueltype | tax  | mpg  | enginesize |
  100. +--------------+------+--------+--------------+---------+----------+------+------+------------+
  101. | toyota taris | 2019 | 125000 | automatic    |    1800 | hybrid   |    5 |   10 |          2 |
  102. | toyota hilux | 2020 | 160000 | automatic    |     100 | hybrid   |    5 |   18 |        2.2 |
  103. +--------------+------+--------+--------------+---------+----------+------+------+------------+
  104. 2 rows in set (0.006 sec)
  105.  
  106. MariaDB [cars]> DELIMITER |
  107. MariaDB [cars]>
  108. MariaDB [cars]> CREATE PROCEDURE showCarsModel()
  109.     -> BEGIN
  110.     -> SELECT * FROM used_cars_data WHERE model REGEXP '[[:<:]]toyota[[:>:]]'
  111.     -> END |
  112. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'END' at line 4
  113. MariaDB [cars]>
  114. MariaDB [cars]> DELIMITER ;
  115. MariaDB [cars]>
  116. MariaDB [cars]> SELECT * FROM used_cars_data ORDER BY fueltype ASC;
  117. +-------------------+------+--------+--------------+---------+----------+------+------+------------+
  118. | model             | year | price  | transmission | mileage | fueltype | tax  | mpg  | enginesize |
  119. +-------------------+------+--------+--------------+---------+----------+------+------+------------+
  120. | volkswagen tiguan | 2010 |  12500 | manual       |  180000 | diesel   |    5 |    6 |          2 |
  121. | mercedes benz     | 2018 | 100000 | automatic    |      18 | diesel   |   10 |   20 |        2.3 |
  122. | mercedes benz     | 2021 | 200000 | manual       |      20 | electric |   10 |   20 |        2.3 |
  123. | mercedes benz     | 2015 |  80000 | automatic    |      18 | gasoline |   10 |   20 |        2.3 |
  124. | BMW G32           | 2018 |  80000 | automatic    |      18 | gasoline |   10 |   20 |        2.2 |
  125. | toyota taris      | 2019 | 125000 | automatic    |    1800 | hybrid   |    5 |   10 |          2 |
  126. | toyota hilux      | 2020 | 160000 | automatic    |     100 | hybrid   |    5 |   18 |        2.2 |
  127. +-------------------+------+--------+--------------+---------+----------+------+------+------------+
  128. 7 rows in set (0.009 sec)
  129.  
  130. MariaDB [cars]> DELIMITER |
  131. MariaDB [cars]>
  132. MariaDB [cars]> CREATE PROCEDURE showCarsModel()
  133.     -> BEGIN
  134.     -> SELECT * FROM used_cars_data ORDER BY fueltype ASC;
  135.     -> END |
  136. Query OK, 0 rows affected (0.006 sec)
  137.  
  138. MariaDB [cars]>
  139. MariaDB [cars]> DELIMITER ;
  140. MariaDB [cars]>  CREATE PROCEDURE priceUpdate (money DOUBLE)
  141.     ->        BEGIN
  142.     ->               START priceUpdate;
  143. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'priceUpdate' at line 3
  144. MariaDB [cars]>
  145. MariaDB [cars]>               UPDATE price
  146.     ->               SET price = amount - amount*money
  147.     ->
  148.     ->            COMMIT;
  149. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMMIT' at line 4
  150. MariaDB [cars]>
  151. MariaDB [cars]>        END       |
  152.     ->
  153.     -> mysql> DELIMITER ;
  154. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'END       |
  155.  
  156. mysql> DELIMITER' at line 1
  157. MariaDB [cars]>
  158. MariaDB [cars]> DELIMITER |
  159. MariaDB [cars]>
  160. MariaDB [cars]>  CREATE PROCEDURE priceUpdate (money DOUBLE)
  161.     ->        BEGIN
  162.     ->
  163.     ->               SET price = price - price*money
  164.     ->
  165.     ->        END       |
  166. ERROR 1193 (HY000): Unknown system variable 'price'
  167. MariaDB [cars]>
  168. MariaDB [cars]> mysql> DELIMITER ;
  169.     -> DELIMITER |
  170. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'mysql> DELIMITER ;
  171. DELIMITER' at line 1
  172. MariaDB [cars]>
  173. MariaDB [cars]>  CREATE PROCEDURE priceUpdate (money DOUBLE)
  174.     ->        BEGIN
  175.     ->               Update used_cars_data;
  176.     ->               SET price = price - price*money;
  177.     ->
  178.     ->        END       |
  179. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ';
  180.              SET price = price - price*money;
  181.  
  182.       END' at line 3
  183. MariaDB [cars]>
  184. MariaDB [cars]> mysql> DELIMITER ;
  185.     ->  DELIMITER // ;
  186.     ->  Create Procedure Update_carPrice ( IN p_price Double )
  187.     ->    -> BEGIN
  188.     ->    -> UPDATE used_cars_data
  189.     ->    -> SET
  190.     ->    -> price = price+price*p_price WHERE;
  191.     ->    -> END //
  192.     ->  DELIMITER ;
  193.     ->
  194.     ->
  195.     -> Bye
  196.  
  197. nelly@NELLYIVANOVA c:\xampp
  198. # mysql -uroot
  199. Welcome to the MariaDB monitor.  Commands end with ; or \g.
  200. Your MariaDB connection id is 32
  201. Server version: 10.4.21-MariaDB mariadb.org binary distribution
  202.  
  203. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  204.  
  205. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  206.  
  207. MariaDB [(none)]>  DELIMITER //
  208. MariaDB [(none)]>  Create Procedure Update_carPrice ( IN p_price Double )
  209.     ->    -> BEGIN
  210.     ->    -> UPDATE used_cars_data
  211.     ->    -> SET
  212.     ->    -> price = price+price*p_price WHERE;
  213.     ->    -> END //
  214. ERROR 1046 (3D000): No database selected
  215. MariaDB [(none)]>  DELIMITER ;
  216. MariaDB [(none)]> use cars;
  217. Database changed
  218. MariaDB [cars]>  DELIMITER //
  219. MariaDB [cars]>  Create Procedure Update_carPrice ( IN p_price Double )
  220.     ->    -> BEGIN
  221.     ->    -> UPDATE used_cars_data
  222.     ->    -> SET
  223.     ->    -> price = price+price*p_price WHERE;
  224.     ->    -> END //
  225. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-> BEGIN
  226.   -> UPDATE used_cars_data
  227.   -> SET
  228.   -> price = price+price*p_pr...' at line 2
  229. MariaDB [cars]>  DELIMITER ;
  230. MariaDB [cars]>  DELIMITER //
  231. MariaDB [cars]>  Create Procedure Update_carPrice ( IN p_price Double )
  232.     ->    -> BEGIN
  233.     ->    -> UPDATE used_cars_data
  234.     ->    -> SET
  235.     ->    -> price = price+price*p_price ;
  236.     ->    -> END //
  237. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-> BEGIN
  238.   -> UPDATE used_cars_data
  239.   -> SET
  240.   -> price = price+price*p_pr...' at line 2
  241. MariaDB [cars]>  DELIMITER ;
  242. MariaDB [cars]>  DELIMITER //
  243. MariaDB [cars]>  Create Procedure Update_carPrice ( IN p_price Double )
  244.     ->    -> BEGIN
  245.     ->    -> UPDATE used_cars_data
  246.     ->    -> SET price = price+price*p_price ;
  247.     ->    -> END //
  248. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-> BEGIN
  249.   -> UPDATE used_cars_data
  250.   -> SET price = price+price*p_price ;
  251. ...' at line 2
  252. MariaDB [cars]>  DELIMITER ;
  253. MariaDB [cars]>  DELIMITER //
  254. MariaDB [cars]>  Create Procedure Update_carPrice ( IN p_price Double )
  255.     ->    -> BEGIN
  256.     ->    -> UPDATE used_cars_data
  257.     ->    -> SET price = SUM(price)+SUM(price*p_price) ;
  258.     ->    -> END //
  259. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-> BEGIN
  260.   -> UPDATE used_cars_data
  261.   -> SET price = SUM(price)+SUM(price*p...' at line 2
  262. MariaDB [cars]>  DELIMITER ;
  263. MariaDB [cars]> DELIMITER //
  264. MariaDB [cars]>  Create Procedure Update_carPrice ( IN p_price Double )
  265.     ->    -> BEGIN
  266.     ->    -> UPDATE used_cars_data;
  267.     ->    -> SET price = SUM(price)+SUM(price*p_price) ;
  268.     ->    -> END //
  269. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-> BEGIN
  270.   -> UPDATE used_cars_data;
  271.   -> SET price = SUM(price)+SUM(price*...' at line 2
  272. MariaDB [cars]>  DELIMITER ;
  273. MariaDB [cars]> Call Showcars;
  274. +-------------------+------+--------+
  275. | model             | year | price  |
  276. +-------------------+------+--------+
  277. | volkswagen tiguan | 2010 |  12500 |
  278. | toyota taris      | 2019 | 125000 |
  279. | toyota hilux      | 2020 | 160000 |
  280. | mercedes benz     | 2021 | 200000 |
  281. | mercedes benz     | 2018 | 100000 |
  282. | mercedes benz     | 2015 |  80000 |
  283. | BMW G32           | 2018 |  80000 |
  284. +-------------------+------+--------+
  285. 7 rows in set (0.012 sec)
  286.  
  287. Query OK, 0 rows affected (0.031 sec)
  288.  
  289. MariaDB [cars]> call showCarsModel;
  290. +-------------------+------+--------+--------------+---------+----------+------+------+------------+
  291. | model             | year | price  | transmission | mileage | fueltype | tax  | mpg  | enginesize |
  292. +-------------------+------+--------+--------------+---------+----------+------+------+------------+
  293. | volkswagen tiguan | 2010 |  12500 | manual       |  180000 | diesel   |    5 |    6 |          2 |
  294. | mercedes benz     | 2018 | 100000 | automatic    |      18 | diesel   |   10 |   20 |        2.3 |
  295. | mercedes benz     | 2021 | 200000 | manual       |      20 | electric |   10 |   20 |        2.3 |
  296. | mercedes benz     | 2015 |  80000 | automatic    |      18 | gasoline |   10 |   20 |        2.3 |
  297. | BMW G32           | 2018 |  80000 | automatic    |      18 | gasoline |   10 |   20 |        2.2 |
  298. | toyota taris      | 2019 | 125000 | automatic    |    1800 | hybrid   |    5 |   10 |          2 |
  299. | toyota hilux      | 2020 | 160000 | automatic    |     100 | hybrid   |    5 |   18 |        2.2 |
  300. +-------------------+------+--------+--------------+---------+----------+------+------+------------+
  301. 7 rows in set (0.012 sec)
  302.  
  303. Query OK, 0 rows affected (0.103 sec)
  304.  
  305. MariaDB [cars]> DELIMITER |
  306. MariaDB [cars]>
  307. MariaDB [cars]> CREATE PROCEDURE showToyotal()
  308.     -> BEGIN
  309.     -> SELECT * FROM used_cars_data  WHERE model REGEXP '[[:<:]]toyota[[:>:]]'
  310.     ->
  311.     ->
  312.     -> END |
  313. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'END' at line 6
  314. MariaDB [cars]>
  315. MariaDB [cars]> DELIMITER ;
  316. MariaDB [cars]>
  317. MariaDB [cars]> DELIMITER |
  318. MariaDB [cars]>
  319. MariaDB [cars]> CREATE PROCEDURE showToyotal()
  320.     -> BEGIN
  321.     -> SELECT * FROM used_cars_data  WHERE model REGEXP '[[:<:]]toyota[[:>:]]';
  322.     ->
  323.     ->
  324.     -> END |
  325. Query OK, 0 rows affected (0.018 sec)
  326.  
  327. MariaDB [cars]>
  328. MariaDB [cars]> DELIMITER ;
  329. MariaDB [cars]> call Toyota
Add Comment
Please, Sign In to add comment