oracle创建表之前判断表是否存在,如果存在则删除已有表

2024-12-31 13:17:46
推荐回答(1个)
回答1:

declare
num number;
begin
select count(1) into num from user_tables where table_name = upper('sys_area') ;
if num > 0 then
execute immediate 'drop table sys_area' ;
end if;
end;

-- 区域表
CREATE TABLE sys_area
(
id Number(4) NOT NULL,
parent_id varchar2(64) NOT NULL,
parent_ids varchar2(2000) NOT NULL,
name nvarchar2(100) NOT NULL,
sort number(10,0) NOT NULL,
code varchar2(100),
type char(1),
create_by varchar2(64) NOT NULL,
create_date timestamp NOT NULL,
update_by varchar2(64) NOT NULL,
update_date timestamp NOT NULL,
remarks nvarchar2(255),
del_flag char(1) DEFAULT '0' NOT NULL,
PRIMARY KEY (id)
);