0
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来传递参数

4

1 回答 1

0

您可以将准备好的语句用于 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)
于 2016-11-19T15:20:14.283 回答