Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Setting environment for using XAMPP for Windows.
- nelly@NELLYIVANOVA c:\xampp
- # mysql -uroot
- Welcome to the MariaDB monitor. Commands end with ; or \g.
- Your MariaDB connection id is 16
- Server version: 10.4.21-MariaDB mariadb.org binary distribution
- Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- MariaDB [(none)]> create database statements;
- Query OK, 1 row affected (0.007 sec)
- MariaDB [(none)]> use statements;
- Database changed
- MariaDB [statements]> create table t1 (a int,b char(10));
- Query OK, 0 rows affected (0.015 sec)
- MariaDB [statements]> insert into t1 values (1,"one"),(2, "two"),(3,"three");
- Query OK, 3 rows affected (0.010 sec)
- Records: 3 Duplicates: 0 Warnings: 0
- MariaDB [statements]> prepare test from "select * from t1 where a=?";
- Query OK, 0 rows affected (0.003 sec)
- Statement prepared
- MariaDB [statements]> set @param=2;
- Query OK, 0 rows affected (0.006 sec)
- MariaDB [statements]> execute test using @param;
- +------+------+
- | a | b |
- +------+------+
- | 2 | two |
- +------+------+
- 1 row in set (0.012 sec)
- MariaDB [statements]> set @param=3;
- Query OK, 0 rows affected (0.000 sec)
- MariaDB [statements]> execute test using @param;
- +------+-------+
- | a | b |
- +------+-------+
- | 3 | three |
- +------+-------+
- 1 row in set (0.000 sec)
- MariaDB [statements]> deallocate prepare test;
- Query OK, 0 rows affected (0.006 sec)
- MariaDB [statements]> PREPARE stmt1 FROM 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse';
- Query OK, 0 rows affected (0.008 sec)
- Statement prepared
- MariaDB [statements]> SET @a = 3;
- Query OK, 0 rows affected (0.000 sec)
- MariaDB [statements]> SET @b = 4;
- Query OK, 0 rows affected (0.000 sec)
- MariaDB [statements]> EXECUTE stmt1 USING @a, @b;
- +------------+
- | hypotenuse |
- +------------+
- | 5 |
- +------------+
- 1 row in set (0.006 sec)
- MariaDB [statements]> DEALLOCATE PREPARE stmt1;
- Query OK, 0 rows affected (0.000 sec)
- MariaDB [statements]> SET @s = 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse';
- Query OK, 0 rows affected (0.001 sec)
- MariaDB [statements]> PREPARE stmt2 FROM @s;
- Query OK, 0 rows affected (0.000 sec)
- Statement prepared
- MariaDB [statements]> SET @a = 6;
- Query OK, 0 rows affected (0.000 sec)
- MariaDB [statements]> SET @b = 8;
- Query OK, 0 rows affected (0.000 sec)
- MariaDB [statements]> EXECUTE stmt2 USING @a, @b;
- +------------+
- | hypotenuse |
- +------------+
- | 10 |
- +------------+
- 1 row in set (0.000 sec)
- MariaDB [statements]> DEALLOCATE PREPARE stmt2;
- Query OK, 0 rows affected (0.000 sec)
- MariaDB [statements]> CREATE TABLE t1 (a INT NOT NULL);
- ERROR 1050 (42S01): Table 't1' already exists
- MariaDB [statements]> INSERT INTO t1 VALUES (4), (8), (11), (32), (80);
- ERROR 1136 (21S01): Column count doesn't match value count at row 1
- MariaDB [statements]> SET @table = 't1';
- Query OK, 0 rows affected (0.000 sec)
- MariaDB [statements]> SET @s = CONCAT('SELECT * FROM ', @table);
- Query OK, 0 rows affected (0.007 sec)
- MariaDB [statements]> PREPARE stmt3 FROM @s;
- Query OK, 0 rows affected (0.000 sec)
- Statement prepared
- MariaDB [statements]> EXECUTE stmt3;
- +------+-------+
- | a | b |
- +------+-------+
- | 1 | one |
- | 2 | two |
- | 3 | three |
- +------+-------+
- 3 rows in set (0.001 sec)
- MariaDB [statements]> CREATE TABLE t2 (a INT NOT NULL);
- Query OK, 0 rows affected (0.015 sec)
- MariaDB [statements]> INSERT INTO t2 VALUES (4), (8), (11), (32), (80);
- Query OK, 5 rows affected (0.009 sec)
- Records: 5 Duplicates: 0 Warnings: 0
- MariaDB [statements]> SET @table = 't2';
- Query OK, 0 rows affected (0.000 sec)
- MariaDB [statements]> SET @s = CONCAT('SELECT * FROM ', @table);
- Query OK, 0 rows affected (0.000 sec)
- MariaDB [statements]> PREPARE stmt3 FROM @s;
- Query OK, 0 rows affected (0.000 sec)
- Statement prepared
- MariaDB [statements]> EXECUTE stmt3;
- +----+
- | a |
- +----+
- | 4 |
- | 8 |
- | 11 |
- | 32 |
- | 80 |
- +----+
- 5 rows in set (0.001 sec)
- MariaDB [statements]> DEALLOCATE PREPARE stmt3;
- Query OK, 0 rows affected (0.000 sec)
- MariaDB [statements]>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement