Oracle 数据库,视图 ,索引

一. 视图

  1. 在oracle中单引号表示字符串, 在别名定义时需要用到双引号,别名是纯数字必须使用双引号

  2. 什么是视图
    是一个虚表, 可以对视图进行增删改查
    视图是不能存储数据的,所有的数据都在基本表(table)中
    操作视图就是操作基本表
    视图简单的说,就是封装了一个[复杂]的DQL;
    对视图操作,只能操作哪些查询出来的列, 一般不作为修改

  3. 视图的语法
    create [or replace] view 视图名称 as DQL;

  4. 视图的使用
    – create [or replace] view 视图名称 as DQL;
    – 创建视图
    create or replace view emp_view as select * from emp;
    – 查询视图
    select * from emp_view;
    – 修改(增删改)视图
    insert into emp_view(empno ,ename) values(1004, ‘laowang’);
    – 查询原表
    select * from emp;

  5. 视图的特点
    – 可以屏蔽敏感列
    create or replace view emp_view as
    select empno,ename,job,mgr,hiredate ,deptno from emp;
    select * from emp_view;
    – 可以创建一个只读的视图
    create or replace view emp_view as
    select empno,ename,job,mgr,hiredate ,deptno from emp with read only;
    insert into emp_view(empno ,ename) values(1004, ‘laowang’);

二. 索引

  1. 索引的作用
    效率高,提高检索效率
    前提:
    经常查询的列
    百万条记录以上
    不经常修改的列(修改列会导致索引重建)
    主键列和唯一键列为索引列

  2. 索引的创建语法
    create index 索引名称 on 表(列,…)

  3. 测试效率
    –1. 创建表
    create table a(
    id number primary key ,
    text varchar2(200)
    )
    create sequence a_seq;
    –2. 准备百万条记录
    select sys_guid() from dual;

    declare

    begin
    for i in 1…1000000 loop
    insert into a values(a_seq.nextval , sys_guid());
    end loop;
    end ;
    –3. 在创建索引前查询 – 0.547
    select * from a where text = ‘5F39F437DAB04E76A43DA83D0FDEC169’;
    –4. 创建索引
    create index a_text_index on a(text);
    –5. 在创建索引后查询 – 0.032
    select * from a where text = ‘286A6E4C385345A88BD5018093A9F3B4’;

  4. 复合索引(多列索引):触发条件 – (address ,name) 了解
    select * from 表 where address = ‘’ and name = ‘’ 触发索引
    select * from 表 where address = ‘’ or name = ‘’ 不会触发索引
    select * from 表 where address = ‘’ 触发索引
    select * from 表 where name = ‘’ 不会触发索引

    Oracle数据库plsql基本语句

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值