Oracle

本文档详细介绍了Oracle数据库的一些基本操作,包括创建表空间、用户及授权,数据类型,表的创建、修改和删除,数据的插入、更新和删除,序列使用,单行和多行函数,条件表达式,以及分页查询。此外,还涉及到了视图、索引、存储过程和函数的创建。这些内容构成了Oracle数据库管理和开发的基础知识。
摘要由CSDN通过智能技术生成

Oracle创建表空间,用户,用户授权

  1. –创建表空间
    create tablespace itheima
    –指定创建位置
    datafile ‘c:\itheima.dbf’
    –指定创建大小
    size 100m
    –是否自动增长
    autoextend on
    –自动增长大小
    next 10m;

  2. –删除表空间
    drop tablespace itheima;

  3. –创建用户
    create user itheima
    –登入密码
    identified by itheima
    –出生地点
    default tablespace itheima;

  4. –给用户授权
    –connect连接角色,基本角色
    –resource开发者角色
    –dba超级管理员
    –赋予角色
    grant dba to itheima;

Oracle数据类型
在这里插入图片描述
Oracle创建修改表

  1. –创建表
    create table person(
    pid number(10),
    pname varchar2(10)
    )
  2. –添加一列
    alter table person add (gender number (1));
  3. –修改列类型
    alter table person modify gender char (1);
  4. –修改列名称
    alter table person rename column gender to sex;
  5. –删除一列
    alter table person drop column sex;

Oracle修改表中数据

  1. –添加数据
    insert into person(pid,pname) values(1,‘张三’);
  2. –修改数据
    update person set pname=‘李四’ where pid=‘1’;
  3. –删除数据
    –该删除法会先删除索引在删除表的数据,提高删除效率
    truncate table person;

Oracle序列使用
Oracle中的序列不真属于任何的表,dual是虚表
–创建序列
create sequence id_person;
select id_person.nextval from dual;

Oracle单行函数

  • sysdate得到当前时间
  • nvl(a,b)如果a为null值,则使用b的值,否则使用a的值

Oracle条件表达式

  • select e.ename , case e.ename when 'SMITH' then 'xixi' when 'ALLEN' then 'cici' else 'vivi' end name from EMP e;case开启,end结束
  • Oracle专用表达式decode(判断式,’‘SMITH’ , ‘xixi’’)

Oracle多行函数

  • count(),sum(),max(),min(),avg()

Oracle分页查询
使用column行号

视图:提供一个查询窗口,所有数据来自于原表
视图的作用?
第一:视图可以屏蔽掉一些敏感字段。
第二:保证总部和分部数据及时统一。

索引:就是在表的列上构建一个二叉树
作用:达到大幅度提高查询效率的目的,但是索引会影响增删改的效率。
创建索引:create index ind_xx on emp(xxx);
单列索引发规则:条件必须是索引列中的原始值。单行函数,模糊查询,都会影响索引的触发。
复合索引中第一列为优先检索列
如果要触发复合索引,必须包含有优先检索列中的原始值。

创建存储过程
create or replace procedure p1(eno emp.empno%type)
is
begin
update emp set sal=sal+100 where empno=eno;
commit;
end;

创建存储函数
create or replace function f1(eno emp.empno%type) return emp.job%type is
result1 emp.job%type;
begin
select job into result1 from emp where empno=eno;
return result1;
end f1;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

P_xuebuhui

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值