oracle学习记录2021-4-7开始(持续更新)

  • nvl函数
    nvl(expr1,expr2):如果expr1为空,则返回expr2,不为空,则是它本身。
    nvl(expr1,expr2,expr3):如果expr1为空,则返回expr2,不为空,则返回expr3。

2021-4-8

  • GROUP BY函数
    在select列表中所有未包含在组函数中的列都应该包含在GROUP BY子句中。
  • 不能在where子句中使用组函数,可以在having子句中使用组函数。

组函数类型:

  • AVG
  • COUNT
  • MAX
  • MIN
  • SUM

创建表:

  1. 直接创建
create table emp1(
id number(10),
name varchar2(20),
salary number(10,2),
hire_date date
)
  1. 通过select另一个表创建
create table emp2
as 
select employee_id id,last_name name,hire_date,salary
from employees
//where 1=2

这样创建会将数据也导入,需要加一个where条件。


管理表:
alter table
drop table
rename table
truncate table


插入数据:

insert into...
value ...

(超文本标记语言从其他表中拷贝数据时,直接在insert语句中加入子查询,不需要写value)


更新数据:

update emp1
set salary = 12000
where employee_id = 179

删除数据:

delete from employees
where department_id = (
                        select department_id 
                        from departments
                        where department_name like 'Public'
                      )

约束:

  • NOT NULL
  • UNIQUE
  • PRIMARY KEY
  • FOREIGN KEY
  • CHECK
create table emp3(
--列级约束
id number(10) constraint emp3_id_uk unique,
name varchar2(20) constraint emp3_name_nn not null,
salary number(10,2),
email varchar2(20),
--表级约束
constraint emp3_email_uk unique(email)
)

2021-4-9

昨晚在家里看了视图的视频,今天来办公室整理一下!

  • rownum:伪列(只能用 <、<= 号)

创建视图:

create or replace view employee_vu
as
select last_name,employee_id,department_id
from employees

修改视图为只读:

create or replace view employee_vu
as
select last_name,employee_id,department_id
from employees
with read only

创建序列:

create sequence empseq
increment by 10
start with 10
maxvalue 100
cycle
nocache

创建索引:

create index emp01_id_ix
on emp01(employee_id)


删除索引:

drop index emp01_id_ix;

创建用户(登录的用户要有DBA权限):

create user yifan
identified by yifan;

赋予权限:

grant create session
to yifan;

↑是赋予登录权限

alter user yifan quota unlimited
on users;

↑是赋予表空间

grant create table
to yifan;

↑是赋予建表权限


创建角色:

create role my_role;

赋权操作同上


  • union
  • uoion all
  • intersect(交集)
  • minus(差集)

到这里,基本的语句学的差不多了,我要暂时转战Spring了!加油!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值