序列和视图

--分页语句rownum
select * from (select d.*,rownum rn from ( select * from emp order by sal desc) d ) where rn>5 and rn<=10 ;

--序列
--创建序列
create sequence seq_class start with 1 increment by 2 maxvalue 5000 cache 30;

--修改序列
alter sequence seq_class cache 20;

--删除序列
drop sequence seq_class;
--查询当前用户下的序列信息
select * from user_sequences;

select seq_class.nextval from dual;
--序列建成功后,第一次不能用currval获取当前值,必须使用一次nextval,才可以查询当前值
select seq_class.currval from dual;

 

 

--为用户授予创建视图的权限
grant create view to scott;
revoke create view from scott;

--视图
--创建视图 不带with check option 也不带where 条件 数据可以通过视图和源表添加
create or replace view emp_view as
select empno,ename,job from emp;

select empno,ename from emp_view; --操作视图

select * from emp;
delete from emp_view where empno=6666;
insert into emp_view values(1111,'lily','clerk');--通过视图添加数据,视图和源表都能添加

--创建视图 带 with check option 条件, 没带where条件 ,也可以添加
create or replace view emp_view2 as

select empno,ename,job from emp with check option;

select * from emp_view2;

insert into emp_view2 values(1111,'lily','clerk'); --也可以添加

select * from emp;
delete from emp where empno=1111;
--创建视图 带where条件 带 with check option
create or replace view emp_view3 as
select empno ,ename ,job,sal from emp where sal >1000 and sal<2000 with check option;

select * from emp_view3;

insert into emp_view3 values(1111,'lily','clerk',2500);--不满足where条件,不能添加
insert into emp_view3 values(2222,'lucy','clerk',1500); --满足where条件是可以添加的

--创建视图 带where 条件 不带with check option

create or replace view emp_view4 as
select empno,ename ,job ,sal from emp where sal>1000 and sal<2000;

insert into emp_view4 values(1111,'lily','clerk',2500);

select * from emp_view4;
select * from emp;
delete from emp where empno=1111;

--创建视图 with read only 只读操作
create or replace view emp_view5 as
select empno,ename,job from emp with read only;

select * from emp_view5;

insert into emp_view5 values(3333,'偶发清','搬砖');--不能对只读视图 做DML操作 也就是增删改

转载于:https://www.cnblogs.com/yin-dt/p/6736500.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值