首页 > 编程知识 正文

oracle数据库增删改查基本语句,数据库增删改查基本语句sql

时间:2023-05-03 14:19:09 阅读:131646 作者:3124

1 .在hql中使用group by的问题(1)将统计函数用作输出结果

selectsum(total ),sum (total up ) fromADwhereaid=? andfid=? andvdatetime=? andvdatetime=? groupbyaid

)2)使用统计函数作为查询约束条件

electuidfrommmgroupbyuidhavingcount (*? andmin(m_date )? )3)使用group by时的约束问题

如果约束是单个字段,则必须使用where,where必须位于group by (如: )之前

electcitynamefrommiwherevdatetime=? andvdatetime? 如果groupbycityname约束是统计函数,则使用having,having位于group by之后,如:(2)

)实际上,在某些情况下,可以用distinct替换group by。 例如,以下两个语句的功能相同:

electcitynamefrommiwherevdatetime=? andvdatetime? groupbycityname

selectdistinctcitynamefrommiwherevdatetime=? andvdatetime?

计数) )中使用别名问题

选择计数(* ) frommipmailconfigasmipmailconfigwheremipmailconfig.uid? andMipMailconfig.email=? -正确

选择计数(mipmailconfig.* ) frommipmailconfigasmipmailconfigwheremipmailconfig.uid? andMipMailconfig.email=? -错误3 .有关integer和Long的问题在Hibernate3.2中,所有计数都使用Long,使用integer有问题。

list list=this.find (选择计数(* ) fromMMCasMMCwhereMMC.uid? andMMC.email=?newString[]{uid,email};

If (列表!=空! list.isEmpty () }

long count=long.parse long (list.get (0).toString ) );

是if (计数0 )

返回真;

else

返回假;

}

4 .关于参数是数组的问题,在实际工作中经常会遇到这种情况:

(1)要删除大量数据,发送数组,

)2)或者,要检查数据组,还必须传递查询条件和数组。

这种情况下,怎么处理?

)1)查询数据。 查询条件是数组,有两种方法:

1直接拼写Hql语句

String[]ids={'1'、'2'、'3'};

Stringstr=' ';

for(inti=0; iids.length; I ) {

str=''' ids[i] ' ';

if(I!=(ids.Length-1 ) )

str=',';

}

列表列表;

list=appinfo manager.find (fromappinfowhereidin ) (str ' );

If (列表!=空) {

for(inti=0; ilist.size (; I ) {

appinfoapp=(appinfo ) list.get(i ) I;

system.out.println (app.get appname );

}

}

System.out.println ('共享' list.size ) ) '记录'); 2使用回调函数的公共列表geta plist () {

return(list ) this.getHibernateTemplate ).execute(newhibernatecallback () ) )。

publicobjectdoinhibernate (会话会话) throwsHibernateException,SQLException{

String[]ids={'1'、'2'、'3'};

字符串hql=' fromappinfowhereidin (: ids );

查询查询=session.create query (hql );

list list=query.setparameterlist (' ids ',ids ).list );

返回列表;

}

);

(2)删除数据,将自变量作为数组,利用回调函数publicvoiddelInArray () )

this.gethibernatetemplate ((.execute ) newhibernatecallback ) )。

publicobjectdoinhibernate (会话会话) throwsHibernateException,SQLException{

String[]ids={'1'、'2'、'3'};

字符串hql=' deleteappinfowhereidin (: ids );

查询查询=session.create query (hql );

query.setparameterlist('ids ',ids ).executeUpdate );

返回空值;

}

);

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。