Oracle:select into 查询没有记录的解决办法
生活随笔
收集整理的這篇文章主要介紹了
Oracle:select into 查询没有记录的解决办法
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?在數(shù)據(jù)庫編程中,select into 語句可以將數(shù)據(jù)庫的某些值賦值給程序的變量,使用起來非常方便。但很多時(shí)候也會(huì)遇到查詢出來沒有記錄的情況,這時(shí)程序會(huì)出錯(cuò)。
可以使用
exception when NO_DATA_FOUND then但是如merge into using 查不到時(shí)可以使用該方法;
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 沒有數(shù)據(jù)的時(shí)候:
select t.prj_type_id into :id from PRJ_C_TYPE t where t.prj_type_name='abc'使用聚合函數(shù)后:
select nvl(max(t.prj_type_id),0) into :id from PRJ_C_TYPE t where t.prj_type_name='abc'?
轉(zhuǎn)載于:https://www.cnblogs.com/SimonHu1993/p/10197203.html
總結(jié)
以上是生活随笔為你收集整理的Oracle:select into 查询没有记录的解决办法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: UCSC数据库数据调用cruzdb
- 下一篇: matlab中特殊符号如希腊字符