oracle sql增删查改_2018/8/2

  • 增加数据 insert
格式:insert into [表名](列1,列2,...,列n) values(值1,值2,...,值n);

例:insert into student (id,name,sex,age,birthday)
 values(1,'张三','男',18,to_date('1997-1-1','yyyy-mm-dd'));

如果所有列都需要插入,则可以省略表名后的列名,但是必须严格按照表中列的顺序进行赋值
insert into [表名] values(值1,值2,...,值n);

例:insert into student 
values(1,'张三','男',18,to_date('1997-1-1','yyyy-mm-dd'));

注意:如果插入时间类型,注意插入语法
  • 删除数据 delete
删除对象:drop 如表空间,对象,角色        删除数据:delete

格式:delete from [表名] where [列名] = [值];

例:delete from student_tab where name='张三';

删除表中所有数据

delete from [表名];       或者          delete * from [表名];
  • 更新数据 update
修改表结构:alter             修改表数据:update

格式:update [表名] set [列名]=[值] where [列名]=[筛选条件];

例:update student_tab set name='李四' where id=1;
  • 查找数据 select
格式:select 列1,列2,列3,..., from [表名] where [筛选条件];

查询所有
select * from [表名];

Where筛选语句中,可以增加各种条件限定
包括常见的算术运算符,逻辑运算符,between and,like,in,is null
  • 关系运算
例:查询学生表中数学成绩大于60的学生信息

select * from student_tab where math>60;

例:查询学生表中数学成绩大于60并且小于90的学生信息

1.select * from student_tab where math>60 and math<90;

2.select * from student_tab where math between 60 and 90;

例:查询学生表中数学成绩小于60并且大于90的学生信息

select * from student_tab where math not between 60 and 90;

例:查询学生表中入学日期在2013年到2016年的学生信息

select * from student_tab where 
admissionDate//入学日期 between(to_date('2013-01-01','yyyy-mm-dd') and to_date('2016-12-31','yyyy-mm-dd'));

注意: between and也可用于时间的比较
例:查询学生表中家庭地址在北京或上海的学生信息

select * from student_tab where address='北京' or address='上海';

例:查询学生表中家庭地址在北京或上海的学生信息并且数学成绩大于60的学生信息

select * from student_tab where (address='北京' or address='上海') and math>60;
例:查询学生表中家庭住址不在上海的学生信息

1.select * from student_tab where address!='上海';

2.select * from student_tab where address <> '上海';

3.select * from student_tab where address not address = '上海';
判断是否为空 及其取反 is null;

例:查询学生表中拥有奖学金资格的学生信息

select * from student_tab where Scholarship is not null;

例:查询学生表中没有奖学金资格的学生信息

select * from student_tab where Scholarship is null;
指定范围的判断in

例:查询学生表中家庭地址在南京,上海,杭州的学生信息

select * from student_tab where address in('上海','南京','杭州');

例:查询学生表中家庭地址不在南京,上海,杭州的学生信息

select * from student_tab where address not in('上海','南京','杭州');
  • 模糊查询 like
1._ :匹配一个字符
2.% :匹配任意字符,包含0个1个多个

例:查询学生表中所有姓张的同学的学生信息

select * from student_tab where name like '张%';

例:查询学生表中不姓张的同学的学生信息

select * from student_tab where name  not like '张%';

例:查询学生表中姓名中含有"三"的学生信息

select * from student_tab where name like '%三%';

例:查询学生表中姓名第二个字为"三"的学生信息 

select * from student_tab where name like '_三%';
  • 去重查询 distinct
例:查询学生表中有哪些家庭地址

select distinct address from student_tab;

猜你喜欢

转载自blog.csdn.net/weixin_42835567/article/details/81357535