Oracle整理笔记(一)

day01
建用户分配权限
create user student
identified by ‘123456’
grant connect to STUDENT;–授予connect角色
grant resource to STUDENT;–授予resource角色
创建学生信息表
create table student(
stuid varchar2(10) primary key,
stuname varchar2(10) not null,
age number(3) not null,
sex char(5) not null
);
–学生信息表改名
alter table student rename to t_student;
–学生信息表中加地址字段
alter table t_student add address varchar2(50);
–修改地址字段数据类型
alter table t_student modify address varchar(100);
–新增语句
insert into 表名(stuid,stuname,age,sex,address)values(1,‘qz’,22,‘男’,‘江苏无锡’);
–更新语句
update t_student
set sex=‘女’
where stuid=‘2’;
–删除语句
delete from t_student t where t.stuid=‘3’;
查询
select * from t_student;

day02
指定字段查询
select 字段名 from 表名 where 字段名=xxx;
查询所有数据
select from 表名 where 字段名=xxx;
避免重数据查询
select distinct 字段名 from 表名;
字符串连接符 ||
在这里插入图片描述
between and 关键字查询
select
from 表名 where 字段名 between to_date(‘2018/9/1’,‘yyyy/mm/dd’)and to_date(‘2018/12/1’,‘yyyy/mm/dd’);
select 字段名 from 表名 where 字段名 between xx and xx
is null 关键字查询
selectfrom 表名 where code is null;
select
from 表名where code is not null;
selectfrom 表名 where code=’’;
in关键字条件数据查询
在已知指定范围内进行数据查询
select
from 表名where id in (2,4);
like关键字查询
在这里插入图片描述

排序数据记录
–排序数据记录
selectfrom 表名 order by 字段名 desc(降序);
asc(升序)
–查询所有学生信息,按工资正序
select t.
,rownum from 表名 t order by t.字段名 asc;
–查询工资最低的四位(正确写法)
select m.* from
(select t.,rownum from 表名 t order by t.字段名 asc)m
where rownum<=4;
–第一页
select
from
(select tt.,rownum r
from(select
from tstudent t order by t.id desc)tt
where rownum<=2)ttt
where ttt.r>=1;
–第二页
selectfrom
(select tt.
,rownum r
from(select*from tstudent t order by t.id desc)tt
where rownum<=4)ttt
where ttt.r>=3;
统计数据查询 聚合函数
select
AVG(salary)as"平均薪水",
MAX(salary)as"最高薪水",
MIN(salary)as"最低薪水",
SUM(salary)as"薪水总和",
COUNT(id)as"总记录数"
from 表名 where 字段名=xxx;
分组数据查询
select group_num,AVG(salary) AS"平均薪水"from 表名 where group_num IS NOT NULL
group by group_num;
having是对聚合完数据进行调剂限制查询

–内连接的查询
select e.name AS"姓名", d.name AS"部门名称"
from t_employee e
inner join t_department d
on e.dept_id=d.id;
–左外连接
select e.name AS"姓名", d.name AS"部门名称"
from t_employee e
left join t_department d
on e.dept_id=d.id;
–右外连接
select e.name AS"姓名", d.name AS"部门名称"
from t_employee e
right join t_department d
on e.dept_id=d.id;
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值