Oracle判断数据或字段是否存在处理


关于数据的处理

declare
   v_cnt int;
begin
select count(*) into v_cnt from 表名称 where 查询操作处理数据的条件
if v_cnt>0 then  --如果存在记录

   相关操作

else
   相关处理
  --
end if;
end;


关于字段的处理


declare
   v_col int;
begin

select count(*) into v_col   from cols
 where table_name = upper('表名称')    and column_name = upper('字段名称');

if v_col>0 then
相关操作
-- alter table PXXXX  drop COLUMN EXECUTE_DEPT_ID;

else

相关操作
-- ALTER TABLE PXXXX      ADD ( SUPERVISION_DEPT_ID VARCHAR2(36) NULL) ;
end if;
end;

相关内容