格式:if(conditon.a,b)
解析:当condition为真时,返回a,反之返回b
作用:作为条件语句使用,有时候也可以巧妙的改变从数据库拿出的值;
开发实例如下:String sql = " SELECT s.field_id,IF (s.ifshow IS NULL, 0, s.ifshow) AS ifshow,"
+ "IF (s.ifrequired IS NULL,0,s.ifrequired) AS ifrequired,"
+ "IF (s.ifedit IS NULL, 0, s.ifedit) AS ifedit "
+ "FROM s_template_field s "
+ "where s.template_id ="
+ "(select t.template_id from s_template t "
+ "WHERE t.union_id="
+ "(SELECT d.union_id from sys_account a ,"
+ "sys_department b , "
+ "s_hospitall_info c ,"
+ "s_union_info d "
+ "where a.USER_ACCT_ID='"+userAccId+"' "
+ "and b.DEPT_ID=a.DEPT_ID "
+ "and c.hospitall_id=b.HOSPITALL_ID "
+ "and d.union_id=c.union_id));";
解析:由于数据库中的ifshow ,ifedit,ifrequired默认值为null;用jdbc查询出来以后方便在jsp页面上遍历的话,我们要把null改为0;
这就用到了 if(ifshow IS NULL,0,ifshow);意思就是如果为空的话让它为0,如果不为空就继续为ifshow的值;