oracle查询出表中某几个字段值不唯一的数据

假设有一张学生表,建表语句如下:

--学生 student表
create table student(
sno varchar2(10) primary key,
sname varchar2(20),
sage number(2),
ssex varchar2(5),
birthday date
);

现计划创建唯一索引(sno,sname),由于数据录入失误导致这两列数据有重复数据,进而导致唯一索引创建失败。

因此我们需要先查询出表中这些捣乱的数据,并进行去重处理。

可使用如下语句查询重复数据:

select T.*, T.ROWID
  from student  T
 where exists (select 1
          from student
         where sno = T.sno
           and sname = T.sname
           and ROWID != T.ROWID)

补充:
如果只是查询某一列的重复值(如:sno),语句更加简单,可以如下:

select    t. *    from  student t , student tt  where  t.rowid != tt.rowid  and  t.sno = tt.sno

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-10 18:50:03       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-10 18:50:03       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-10 18:50:03       45 阅读
  4. Python语言-面向对象

    2024-07-10 18:50:03       55 阅读

热门阅读

  1. Git 常用命令

    2024-07-10 18:50:03       16 阅读
  2. C#规则引擎

    2024-07-10 18:50:03       18 阅读
  3. 深度学习Day-24:ResNeXt-50算法思考

    2024-07-10 18:50:03       22 阅读
  4. 完全背包求具体方案(c++题解)

    2024-07-10 18:50:03       21 阅读
  5. Pull Request

    2024-07-10 18:50:03       18 阅读
  6. stm32使用硬件SPI

    2024-07-10 18:50:03       16 阅读
  7. Elasticsearch7.10集群搭建

    2024-07-10 18:50:03       16 阅读
  8. 串口工具推荐

    2024-07-10 18:50:03       19 阅读
  9. Python实现Mybatis Plus

    2024-07-10 18:50:03       23 阅读
  10. 管理客户的10个CRM系统技巧

    2024-07-10 18:50:03       24 阅读