大连网站开发公司shepiguo,织梦模板更新网站,优购网官网,做职业测评的网站在数据库编程中#xff0c;select into 语句可以将数据库的某些值赋值给程序的变量#xff0c;使用起来非常方便。但很多时候也会遇到查询出来没有记录的情况#xff0c;这时程序会出错。 可以使用 exception
when NO_DATA_FOUND then 但是如merge into using 查不到时可以使… 在数据库编程中select into 语句可以将数据库的某些值赋值给程序的变量使用起来非常方便。但很多时候也会遇到查询出来没有记录的情况这时程序会出错。 可以使用 exception
when NO_DATA_FOUND then 但是如merge into using 查不到时可以使用该方法 merge into web_user_vip wv using (select vip_type,id from(select nvl(max(vip_type),0)vip_type ,nvl(max(id),0)id from web_user_vip where user_id v_user_id and source 2 and status 1 and vip_type v_vip_type)where rownum 1)e on (e.vip_type wv.vip_type)when matched thenUPDATE SET wv.expire_time v_expire_end_date where wv.id e.idwhen not matched theninsert(id,user_id,vip_type,expire_time,create_time,source,enterprise_id,status)VALUES(xshtest.WEB_USER_VIP_SEQ.NEXTVAL,v_user_id,v_vip_type,v_expire_end_date,sysdate,2,v_enterprise_id,1); 看下面示例 select 没有数据的时候 select t.prj_type_id into :id from PRJ_C_TYPE t where t.prj_type_nameabc 使用聚合函数后 select nvl(max(t.prj_type_id),0) into :id from PRJ_C_TYPE t where t.prj_type_nameabc 转载于:https://www.cnblogs.com/SimonHu1993/p/10197203.html