MySQL语句正确插入多值如何运行?

数据库 MySQL
我们今天主要向大家描述的是MySQL语句正确插入多值的实际操作步骤,如果你对MySQL语句正确插入多值的实际操作步骤感兴趣的话,你不妨浏览以下的文章。

以下的文章主要介绍的是MySQL语句正确插入多值的实际操作步骤,以及HQL多表查询及在条件 in 中插入N个变量值的实际操作,我前两天在相关网站看见的资料,觉得挺好,就拿出来供大家分享。

一条sql语句插入多组数据:insert into table values (id,name),(id,name),(id,name) 但似乎语句长度有限制,不能超过1MB,并且该语句是MySQL专用的写法,不是标准sql.

以下转自paradise总结的HQL多表查询的写法及in的使用:

 

HQL查询多表的时候,取出结果是两个对象的列表,但是我只要我自己想要的属性,之前的HQL语句是这样写的:

 

 

  1. from Hytxbz h,Tgbzk t where h.hytxbzid=t.hytxbzid and t.bztgid=:bztgid 

 

结果我debug去看query.list();是Hytxbz和Tgbzk两个对象的列表,结果并不是我想要的,我改成

 

 

  1. from Hybztx h where h.hytxbzid in (select t.hytxbzid from Tgbzk where t.bztgid =:bztgid) 

 

还是不行,google一把,发现可以这样写

 

 

  1. select h from Hytxbz as h,Tgbzk as t where h.hytxbzid=t.hytxbzid and t.bztgid=:bztgid 

 

如果想取得对应属性的话,也可以这样写

 

 

  1. select h.hytxbzid from Hytxbz as h,Tgbzk as t where h.hytxbzid=t.hytxbzid and t.bztgid=:bztgid 

 

 

发现in的语句可以这样写

 

 

  1. String ids[]=new String[]{"1","2","3"};   
  2. String hql" from com,you.YourPOJO where id in (?)";   
  3. Query query = session.createQuery(hql);   
  4. query .setParameters(ids); 

 

 

相关方法:

 

 

  1. Query setParameters(Object[] objectArray, Type[] typeArray) throws HibernateException;   
  2. Query setParameterList(String string, Collection collection, Type type) throws HibernateException;   
  3. Query setParameterList(String string, Collection collection) throws HibernateException;   
  4. Query setParameterList(String string, Object[] objectArray, Type type) throws HibernateException;   
  5. Query setParameterList(String string, Object[] objectArray) throws HibernateException 

 

 

 以上的相关内容就是对MySQL语句插入多值的介绍,望你能有所收获。

【编辑推荐】

  1. MySQL临时表的具体使用方案
  2. 用Excel如何对MySQL数据进行分析
  3. MySQL数据类型与相应的建库策略
  4. MySQL数据库中定义外键的必备条件
  5. MySQL数据库所支持的三个引擎
责任编辑:佚名 来源: 互联网
相关推荐

2010-05-25 15:24:38

MySQL updat

2010-05-27 14:47:14

MySQL INSER

2010-05-06 09:19:03

Oracle表

2010-05-12 15:00:50

MySQL事件

2010-06-09 11:22:06

MySQL datet

2020-04-24 21:41:45

MySQL数据库插入数据

2010-01-14 15:29:44

C++编译器

2010-05-11 10:12:50

mysql数据库sql

2021-04-08 10:55:53

MySQL数据库代码

2019-11-14 16:23:07

MySQL索引数据库

2010-05-05 17:53:39

Oracle 8i

2017-08-30 17:47:35

MySql索引

2010-06-01 12:51:23

MySQL数据库

2010-05-18 15:58:39

MySQL触发器

2010-08-19 13:14:17

DB2自动增长主键

2017-11-22 15:33:56

MySQL快速插入语句优化

2010-11-22 16:05:53

MySQL多表插入

2010-09-08 16:38:13

SQL循环语句

2011-08-16 09:21:30

MySQL大数据量快速语句优化

2010-05-31 18:41:10

MySQL连接数
点赞
收藏

51CTO技术栈公众号