在Oracle存储过程中检测,语句要如何实现。
我想用exists这个方法,可是怎么做才行呢?例如:
if (判断AreaName='aa'的记录不存在) then
  执行插入
end if还望朋友们指教~

解决方案 »

  1.   

    if exists(select * from Table where Col='hhhh') then
      执行插入
    end if
      

  2.   

    Sorry
    不存在應該為:
    if not exists(select * from Table where Col='hhhh') then
      执行插入
    end if
      

  3.   

    在Oracle中, 不能将exists用于if判断中, 类似MSSQL这样的写法是错误的
    因此,只能
    select fieldname into fieldvar from tablename
    if fieldvar then
    ...
    else
    ...
    end if;
      

  4.   

    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;