Oracle 关于 视图、索引及存储过程的实例操作

1.添加视图

--视图:虚拟表、可以作为表一样查询使用、预定义的查询
create [or replace] [[no] force] view 视图名
as
       select查询
[with read only];
--ex:
create or replace view empinfo
as
  select e.*, d.dname, d.loc
  from emp e
  left join dept d
       on e.deptno = d.deptno
with read only;

select *
from empinfo
where sal > 2000;

drop view empinfo;

2.添加索引

--索引:加速查询
create [unique] index 索引名字 on 表名(列);
--ex:
create index emp_index_id on emp(ename);

drop index emp_index_id;

3.有关分支的存储过程

create or replace procedure sp_sal(name in varchar)
-- 创建一个存储过程
is
       i number;
       --创建一个变量
begin
       select e.sal into i
       from emp e
       where e.ename = name;
       --查询语句,查询结果赋予给 i
       if i > 2000 then
              -- 条件成立
              update emp set sal = sal + 0.01  where ename = name;
       else
              --条件不成立
              update emp set sal = sal + 0.1  where ename = name;
       end if;
       --提交
       commit;
end sp_sal;

4.有关循环的存储过程

create or replace procedure sp_for1(num in number)
is
begin
       for i in 1..num loop
           insert into dept(deptno,dname,loc) values (to_char(50+i),concat('OREEE',to_char(i)),concat('OOOO',to_char(i)));
       end loop;
       commit;
end sp_for1;

  

转载于:https://www.cnblogs.com/nullnullnull/p/11209622.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值