[sql]代码库
--1.创建表
create table student(
id number(19) not null,
name varchar2(20),
sex number(2),
primary key(id)
);
--2.创建序列
create sequence s_student
increment by 1 start with 1 nomaxvalue nocycle nocache;
--3.插入若干条数据
insert into student values(s_student.nextval, 'student001', 0);
insert into student values(s_student.nextval, 'student002', 0);
insert into student values(s_student.nextval, 'student003', 0);
insert into student values(s_student.nextval, 'student004', 0);
insert into student values(s_student.nextval, 'student005', 0);
select * from student;
--4.复制数据并插入当前表的语句
insert into student
select s_student.nextval, student.name, student.sex from student;
--删除重复数据
delete from student
where name in (select name from student group by name having count(*) > 1)
and id not in (select min(id) from student group by name having count(*)>1);
中级程序员
by: 觉 发表于:2017-09-19 16:15:59 顶(0) | 踩(0) 回复
回复评论