新聞中心
以下的文章主要介紹的是MySQL語句正確插入多值的實(shí)際操作步驟,以及HQL多表查詢及在條件 in 中插入N個(gè)變量值的實(shí)際操作,我前兩天在相關(guān)網(wǎng)站看見的資料,覺得挺好,就拿出來供大家分享。

創(chuàng)新互聯(lián)建站堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都做網(wǎng)站、成都網(wǎng)站建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的修文網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
一條sql語句插入多組數(shù)據(jù):insert into table values (id,name),(id,name),(id,name) 但似乎語句長(zhǎng)度有限制,不能超過1MB,并且該語句是MySQL專用的寫法,不是標(biāo)準(zhǔn)sql.
以下轉(zhuǎn)自paradise總結(jié)的HQL多表查詢的寫法及in的使用:
HQL查詢多表的時(shí)候,取出結(jié)果是兩個(gè)對(duì)象的列表,但是我只要我自己想要的屬性,之前的HQL語句是這樣寫的:
- from Hytxbz h,Tgbzk t where h.hytxbzid=t.hytxbzid and t.bztgid=:bztgid
結(jié)果我debug去看query.list();是Hytxbz和Tgbzk兩個(gè)對(duì)象的列表,結(jié)果并不是我想要的,我改成
- from Hybztx h where h.hytxbzid in (select t.hytxbzid from Tgbzk where t.bztgid =:bztgid)
還是不行,google一把,發(fā)現(xiàn)可以這樣寫
- select h from Hytxbz as h,Tgbzk as t where h.hytxbzid=t.hytxbzid and t.bztgid=:bztgid
如果想取得對(duì)應(yīng)屬性的話,也可以這樣寫
- select h.hytxbzid from Hytxbz as h,Tgbzk as t where h.hytxbzid=t.hytxbzid and t.bztgid=:bztgid
發(fā)現(xiàn)in的語句可以這樣寫
- String ids[]=new String[]{"1","2","3"};
- String hql= " from com,you.YourPOJO where id in (?)";
- Query query = session.createQuery(hql);
- query .setParameters(ids);
相關(guān)方法:
- Query setParameters(Object[] objectArray, Type[] typeArray) throws HibernateException;
- Query setParameterList(String string, Collection collection, Type type) throws HibernateException;
- Query setParameterList(String string, Collection collection) throws HibernateException;
- Query setParameterList(String string, Object[] objectArray, Type type) throws HibernateException;
- Query setParameterList(String string, Object[] objectArray) throws HibernateException
以上的相關(guān)內(nèi)容就是對(duì)MySQL語句插入多值的介紹,望你能有所收獲。
【編輯推薦】
- MySQL臨時(shí)表的具體使用方案
- 用Excel如何對(duì)MySQL數(shù)據(jù)進(jìn)行分析
- MySQL數(shù)據(jù)類型與相應(yīng)的建庫策略
- MySQL數(shù)據(jù)庫中定義外鍵的必備條件
- MySQL數(shù)據(jù)庫所支持的三個(gè)引擎
文章名稱:MySQL語句正確插入多值如何運(yùn)行?
當(dāng)前URL:http://m.fisionsoft.com.cn/article/dpdhosp.html


咨詢
建站咨詢
