Oracle 操作表

--查询回收站中的表
select * from recyclebin;
--清空回收站中的表
purge recyclebin;
--清空回收站中指定的表
purge table &ORIGINAL_NAME;

--恢复回收站中的指定表
FLASHBACK TABLE TABLE_NAME TO BEFORE DROP;

--恢复回收站中的指定表并重命名
flashback table TABLE_NAME to before drop rename to new_table_name;

--一次性彻底删除表
drop table TABLE_NAME purge;

--删除带约束的表
drop table TABLE_NAME cascade constraints;

--删除表,并未真正删除,只是把表放入回收站中
drop table TABLE_NAME;

--查询表名
select * from user_tables;

--批量生成删除语句
select 'drop table '|| table_name || ' cascade constraints;' from user_tables;

 

--判断是否存在表再删除

declare
  n_count number;
begin
  select count(1)
    into n_count
    from user_tables
   where table_name = 'TABLE_NAME';
  if n_count > 0 then
    execute immediate 'drop table TABLE_NAMEcascade constraints';
  end if;
end;

--查询表最后的更新时间(last_ddl_time)

SELECT object_name,object_type,created,last_ddl_time FROM USER_OBJECTS WHERE OBJECT_TYPE = 'TABLE' order by last_ddl_time desc;

posted on 2021-12-20 14:53  lovezj9012  阅读(108)  评论(0)    收藏  举报

导航