欢迎投稿

今日深度:

Oracle入门学习六,

Oracle入门学习六,


事务:把一组操作看做一个工作单元,要么都执行,要么都不执行。dml操作才有事务,查询没有事务。

create table bank
(
id number(5) primary key,
money number(10) check(money>0)
)

insert into bank values (1,3000);
insert into bank values (2,5000);

update bank set money = money-1000 where id=1;
update bank set money = money+1000 where id=2;

begin
  update bank set money = money - 1000 where id = 1;
  update bank set money = money + 1000 where id = 2;
  commit;
exception
  when others then
    rollback;
end;

select * from bank;

视图:一个虚拟表,不存放数据,只存sql。建立在一张表或多张表的数据查询基础上。oracle普通用户本身没有创建视图权限,需要授予。

grant create view to scott;
create view abc
as
select e.empno,e.ename,d.dname from emp e,dept d where e.deptno=d.deptno;

select * from abc;
View Code

索引:在某列上创建索引,系统就会对该列进行排序,并且创建该列的索引目录。如果我们按这个条件来查询数据,会在该列的索引目录上找,比一条一条去看全部数据查找满足条件的要快。主键、外键创建,系统默认建立索引。

create index ix_emp on emp (ename);
drop index ix_emp;

频繁用于搜索、查询选择、排序、分组的列最好就创建索引。该列的值没有几个不一样的(???)、或者该表数据不多,无需创建索引。

索引使用的优化知识:

  • 查询列、减少*的使用,返回需要的列就好了
  • where条件如果多个条件表达式,包含索引列的条件表达放前面。
  • 避免order by使用表达式
  • 一个表格一个索引就够了。

序列:一个自增的变量。

select * from bank;
delete from bank;
create sequence sq_bank;

insert into bank values(sq_bank.nextval,500);
commit;

create sequence sq_bank1
start with 100
increment by 5
nomaxvalue;

insert into bank values(sq_bank1.nextval,500);
commit;
select sq_bank1.currval from dual;

 

www.htsjk.Com true http://www.htsjk.com/oracle/42966.html NewsArticle Oracle入门学习六, 事务:把一组操作看做一个工作单元,要么都执行,要么都不执行。dml操作才有事务,查询没有事务。 create table bank(id number ( 5 ) primary key , money number ( 10 ) check ( mon...
相关文章
    暂无相关文章
评论暂时关闭