查询短时间内删除数据:
SELECT * FROM 表名 AS OF TIMESTAMP TO_TIMESTAMP('20240126 14:00:00','YYYYMMDD HH24:MI:SS') ORDER BY id desc;
数据回滚
开启回滚权限
alter table 表名 enable row movement;
回滚表数据至某时间之前
flashback table 表名 to timestamp to_timestamp('20230331 17:41:00','YYYYMMDD HH24:MI:SS');
解锁会话数据:
先进行查询
SELECT s.sid, s.serial# FROM v$locked_object lo, dba_objects ao, v$session s WHERE ao.object_id = lo.object_id AND lo.session_id = s.sid;
删除被锁数据
ALTER system KILL session 'SID,SERIAL#';
自增主键创建
创建序列
create sequence 表名
minvalue 1
nomaxvalue
increment by 1
start with 1
nocache;
创建触发器
create or replace trigger 触发器
before insert on 表名 for each row
begin
select 序列名.Nextval into:new.需要的主键自增字段 from dual;
end;
查询字段内容重复数据:
SELECT 字段名, COUNT(*) as count
FROM 表名
GROUP BY 字段名
HAVING COUNT(*) > 1
约束字段值不允许重复
create or replace trigger trig_tbtest
before insert on 表名for each row
declare
v_count number ( 5 );
begin
select count(*) into v_count from 表名 where 字段名 = :new.字段名;
if(v_count > 0) then
raise_application_error( - 20000 , ' data is duplication ' );
end if;
end;