新知识点1: Exceptions into exceptions
SELECT * FROM emp a
WHERE rowid > ANY
(SELECT rowid FROM emp b
WHERE a.ename = b.ename
)
可以找到冗余的数据
今个发现还有一个比较简便的方法,如下使用 exceptions into exceptions;
SQL> create table t ( a int, b int, c int );
表已创建。
SQL> insert into t select rownum,rownum+1,rownum+2 from all_objects where rownum<5;
已创建4行。
SQL> insert into t select *from t where rownum<3;
已创建2行。
SQL> commit;
提交完成。
SQL> select *from t;
ABC
---------- ---------- ----------
123
234
345
456
123
234
已选择6行。SQL> create table exceptions(row_id rowid,
2owner varchar2(30),3table_name varchar2(30),
4constraint varchar2(30));
表已创建。
SQL>SQL> alter table t add constraint t_unique
2unique(a,b,c) exceptions into exceptions;
alter table t add constraint t_unique
*ERROR 位于第 1 行:ORA-02299: 无法验证 (EPUSER.T_UNIQUE) - 未找到重复关键字
SQL> create table dups
2as select *from t where rowid in (select row_id from exceptions);
表已创建。
SQL> select *from dups;
ABC
---------- ---------- ----------
123
234
123
234
SQL> select row_id from exceptions;
ROW_ID
------------------
AAAIEJAAKAAAyMSAAA
AAAIEJAAKAAAyMSAAE
AAAIEJAAKAAAyMSAAB
AAAIEJAAKAAAyMSAAF
SQL> delete from t where rowid in ( select row_id2from exceptions );
已删除4行。
SQL> insert into t select distinct * from dups;
已创建2行。
SQL>SQL> commit;
提交完成。
SQL> select *from t;
ABC
---------- ---------- ----------
345
456
123
234
新知识点2:比对字符相似度的函数:
UTL_MATCH.EDIT_DISTANCE_SIMILARIT
sys@ORCL-10.1.16.14>select UTL_MATCH.EDIT_DISTANCE_SIMILARITY('china telecom','china Telecom') sim from dual;
SIM
----------
93
1 row selected.
sys@ORCL-10.1.16.14>select UTL_MATCH.EDIT_DISTANCE_SIMILARITY('abcdefg','abcdfh') sim from dual;
SIM
----------
72
1 row selected.
说不定以后会用到
SELECT * FROM emp a
WHERE rowid > ANY
(SELECT rowid FROM emp b
WHERE a.ename = b.ename
)
可以找到冗余的数据
今个发现还有一个比较简便的方法,如下使用 exceptions into exceptions;
SQL> create table t ( a int, b int, c int );
表已创建。
SQL> insert into t select rownum,rownum+1,rownum+2 from all_objects where rownum<5;
已创建4行。
SQL> insert into t select *from t where rownum<3;
已创建2行。
SQL> commit;
提交完成。
SQL> select *from t;
ABC
---------- ---------- ----------
123
234
345
456
123
234
已选择6行。SQL> create table exceptions(row_id rowid,
2owner varchar2(30),3table_name varchar2(30),
4constraint varchar2(30));
表已创建。
SQL>SQL> alter table t add constraint t_unique
2unique(a,b,c) exceptions into exceptions;
alter table t add constraint t_unique
*ERROR 位于第 1 行:ORA-02299: 无法验证 (EPUSER.T_UNIQUE) - 未找到重复关键字
SQL> create table dups
2as select *from t where rowid in (select row_id from exceptions);
表已创建。
SQL> select *from dups;
ABC
---------- ---------- ----------
123
234
123
234
SQL> select row_id from exceptions;
ROW_ID
------------------
AAAIEJAAKAAAyMSAAA
AAAIEJAAKAAAyMSAAE
AAAIEJAAKAAAyMSAAB
AAAIEJAAKAAAyMSAAF
SQL> delete from t where rowid in ( select row_id2from exceptions );
已删除4行。
SQL> insert into t select distinct * from dups;
已创建2行。
SQL>SQL> commit;
提交完成。
SQL> select *from t;
ABC
---------- ---------- ----------
345
456
123
234
新知识点2:比对字符相似度的函数:
UTL_MATCH.EDIT_DISTANCE_SIMILARIT
sys@ORCL-10.1.16.14>select UTL_MATCH.EDIT_DISTANCE_SIMILARITY('china telecom','china Telecom') sim from dual;
SIM
----------
93
1 row selected.
sys@ORCL-10.1.16.14>select UTL_MATCH.EDIT_DISTANCE_SIMILARITY('abcdefg','abcdfh') sim from dual;
SIM
----------
72
1 row selected.
说不定以后会用到
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24383181/viewspace-712930/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/24383181/viewspace-712930/