当前位置: 代码迷 >> Oracle开发 >> 检测行记录是否存在,该怎么处理
  详细解决方案

检测行记录是否存在,该怎么处理

热度:100   发布时间:2016-04-24 07:51:04.0
检测行记录是否存在
在Oracle存储过程中检测,语句要如何实现。
我想用exists这个方法,可是怎么做才行呢?

例如:
if   (判断AreaName= 'aa '的记录不存在)   then
    执行插入
end   if

还望朋友们指教~

------解决方案--------------------
在Oracle中, 不能将exists用于if判断中, 类似MSSQL这样的写法是错误的
因此,只能
select fieldname into fieldvar from tablename
if fieldvar then
...
else
...
end if;
------解决方案--------------------
declare
n_count integer;
begin
select count(1)
into n_count
from dual
where exists (select fieldname from tablename where ???);
if n_count = 0 then
-- 插入语句
end if;
end;
  相关解决方案