关于mariaDB的插入动态列

On the insertion dynamic column of mariaDB

set @v1 = "'city', 'ITY', 'age', '20'";
select @v1;
insert into test values (11, 'hidy', column_create(@v1));

MariaDB不支持插入形式的变量,

client Error at))
MariaDB :10.1.19
client :heidi 9.4.0.5130 
OS: Windows 10

如何以变量形式插入?因为我想在我的JAVA中使用JDBC来传递参数

您可以为 INSERT 使用准备好的语句。

MariaDB [test]> set @v1 = "'city', 'ITY', 'age', '20'";
Query OK, 0 rows affected (0.01 sec)

MariaDB [test]> set @q = concat("insert into test values(11, 'hidy', column_create(",@v1,"))");
Query OK, 0 rows affected (0.00 sec)

MariaDB [test]> select @q;
+--------------------------------------------------------------------------------+
| @q                                                                             |
+--------------------------------------------------------------------------------+
| insert into test values(11, 'hidy', column_create('city', 'ITY', 'age', '20')) |
+--------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MariaDB [test]> prepare stmt from @q;
Query OK, 0 rows affected (0.00 sec)
Statement prepared

MariaDB [test]> execute stmt;
Query OK, 1 row affected (0.26 sec)

MariaDB [test]> select column_get(b,'city' as char(8)) from test;
+---------------------------------+
| column_get(b,'city' as char(8)) |
+---------------------------------+
| ITY                             |
+---------------------------------+
1 row in set (0.00 sec)