Advertisement
NellyIvanova29

Подготвени изрази

Nov 30th, 2021
1,272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 4.14 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 16
  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)]> create database statements;
  14. Query OK, 1 row affected (0.007 sec)
  15.  
  16. MariaDB [(none)]> use statements;
  17. Database changed
  18. MariaDB [statements]> create table t1 (a int,b char(10));
  19. Query OK, 0 rows affected (0.015 sec)
  20.  
  21. MariaDB [statements]> insert into t1 values (1,"one"),(2, "two"),(3,"three");
  22. Query OK, 3 rows affected (0.010 sec)
  23. Records: 3  Duplicates: 0  Warnings: 0
  24.  
  25. MariaDB [statements]> prepare test from "select * from t1 where a=?";
  26. Query OK, 0 rows affected (0.003 sec)
  27. Statement prepared
  28.  
  29. MariaDB [statements]> set @param=2;
  30. Query OK, 0 rows affected (0.006 sec)
  31.  
  32. MariaDB [statements]> execute test using @param;
  33. +------+------+
  34. | a    | b    |
  35. +------+------+
  36. |    2 | two  |
  37. +------+------+
  38. 1 row in set (0.012 sec)
  39.  
  40. MariaDB [statements]> set @param=3;
  41. Query OK, 0 rows affected (0.000 sec)
  42.  
  43. MariaDB [statements]> execute test using @param;
  44. +------+-------+
  45. | a    | b     |
  46. +------+-------+
  47. |    3 | three |
  48. +------+-------+
  49. 1 row in set (0.000 sec)
  50.  
  51. MariaDB [statements]> deallocate prepare test;
  52. Query OK, 0 rows affected (0.006 sec)
  53.  
  54. MariaDB [statements]> PREPARE stmt1 FROM 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse';
  55. Query OK, 0 rows affected (0.008 sec)
  56. Statement prepared
  57.  
  58. MariaDB [statements]> SET @a = 3;
  59. Query OK, 0 rows affected (0.000 sec)
  60.  
  61. MariaDB [statements]> SET @b = 4;
  62. Query OK, 0 rows affected (0.000 sec)
  63.  
  64. MariaDB [statements]> EXECUTE stmt1 USING @a, @b;
  65. +------------+
  66. | hypotenuse |
  67. +------------+
  68. |          5 |
  69. +------------+
  70. 1 row in set (0.006 sec)
  71.  
  72. MariaDB [statements]> DEALLOCATE PREPARE stmt1;
  73. Query OK, 0 rows affected (0.000 sec)
  74.  
  75. MariaDB [statements]> SET @s = 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse';
  76. Query OK, 0 rows affected (0.001 sec)
  77.  
  78. MariaDB [statements]> PREPARE stmt2 FROM @s;
  79. Query OK, 0 rows affected (0.000 sec)
  80. Statement prepared
  81.  
  82. MariaDB [statements]> SET @a = 6;
  83. Query OK, 0 rows affected (0.000 sec)
  84.  
  85. MariaDB [statements]> SET @b = 8;
  86. Query OK, 0 rows affected (0.000 sec)
  87.  
  88. MariaDB [statements]> EXECUTE stmt2 USING @a, @b;
  89. +------------+
  90. | hypotenuse |
  91. +------------+
  92. |         10 |
  93. +------------+
  94. 1 row in set (0.000 sec)
  95.  
  96. MariaDB [statements]> DEALLOCATE PREPARE stmt2;
  97. Query OK, 0 rows affected (0.000 sec)
  98.  
  99. MariaDB [statements]> CREATE TABLE t1 (a INT NOT NULL);
  100. ERROR 1050 (42S01): Table 't1' already exists
  101. MariaDB [statements]> INSERT INTO t1 VALUES (4), (8), (11), (32), (80);
  102. ERROR 1136 (21S01): Column count doesn't match value count at row 1
  103. MariaDB [statements]> SET @table = 't1';
  104. Query OK, 0 rows affected (0.000 sec)
  105.  
  106. MariaDB [statements]> SET @s = CONCAT('SELECT * FROM ', @table);
  107. Query OK, 0 rows affected (0.007 sec)
  108.  
  109. MariaDB [statements]> PREPARE stmt3 FROM @s;
  110. Query OK, 0 rows affected (0.000 sec)
  111. Statement prepared
  112.  
  113. MariaDB [statements]> EXECUTE stmt3;
  114. +------+-------+
  115. | a    | b     |
  116. +------+-------+
  117. |    1 | one   |
  118. |    2 | two   |
  119. |    3 | three |
  120. +------+-------+
  121. 3 rows in set (0.001 sec)
  122.  
  123. MariaDB [statements]> CREATE TABLE t2 (a INT NOT NULL);
  124. Query OK, 0 rows affected (0.015 sec)
  125.  
  126. MariaDB [statements]> INSERT INTO t2 VALUES (4), (8), (11), (32), (80);
  127. Query OK, 5 rows affected (0.009 sec)
  128. Records: 5  Duplicates: 0  Warnings: 0
  129.  
  130. MariaDB [statements]> SET @table = 't2';
  131. Query OK, 0 rows affected (0.000 sec)
  132.  
  133. MariaDB [statements]> SET @s = CONCAT('SELECT * FROM ', @table);
  134. Query OK, 0 rows affected (0.000 sec)
  135.  
  136. MariaDB [statements]> PREPARE stmt3 FROM @s;
  137. Query OK, 0 rows affected (0.000 sec)
  138. Statement prepared
  139.  
  140. MariaDB [statements]> EXECUTE stmt3;
  141. +----+
  142. | a  |
  143. +----+
  144. |  4 |
  145. |  8 |
  146. | 11 |
  147. | 32 |
  148. | 80 |
  149. +----+
  150. 5 rows in set (0.001 sec)
  151.  
  152. MariaDB [statements]> DEALLOCATE PREPARE stmt3;
  153. Query OK, 0 rows affected (0.000 sec)
  154.  
  155. MariaDB [statements]>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement