索引巧建

来源:互联网 发布:营养配餐软件正式版 编辑:程序博客网 时间:2024/05/05 19:29

 

SQL> conn /as sysdba
Connected.

 


--添加一列 alter table person add birthday date;


--select sysdate from dual;


--时间戳 select systimestamp from dual;

 

--rowid物理地址 rownum 数据行

SQL> select rowid,rownum,dept.* from scott. dept;

ROWID                  ROWNUM     DEPTNO DNAME          LOC
------------------ ---------- ---------- -------------- -------------
AAAL+XAAEAAAAANAAA          1         10 ACCOUNTING     NEW YORK
AAAL+XAAEAAAAANAAB          2         20 RESEARCH       DALLAS
AAAL+XAAEAAAAANAAC          3         30 SALES          CHICAGO
AAAL+XAAEAAAAANAAD          4         40 OPERATIONS     BOSTON
AAAL+XAAEAAAAANAAE          5         50 aa             aa

 

SQL> select rowid,rownum,dept.* from scott. dept where rownum<3;

ROWID                  ROWNUM     DEPTNO DNAME          LOC
------------------ ---------- ---------- -------------- -------------
AAAL+XAAEAAAAANAAA          1         10 ACCOUNTING     NEW YORK
AAAL+XAAEAAAAANAAB          2         20 RESEARCH       DALLAS

 

 

---rownum随时会变,所以为空
SQL> select rowid,rownum,dept.* from scott. dept where rownum>3;

no rows selected

 

--利用rownum 实现分页,但必须把(select rownum num,dept.* from scott.dept)做为固定视图
SQL> select * from (select rownum num,dept.* from scott.dept) where num>=3 and n
um<5;

 

       NUM     DEPTNO DNAME          LOC
---------- ---------- -------------- -------------
         3         30 SALES          CHICAGO
         4         40 OPERATIONS     BOSTON

 

 

--distinct 去掉重复行
SQL> select distinct deptno from emp;

    DEPTNO
----------
        10
        20
        30
        40
        50


---save transaction=savepoint创建保留点
SQL>savepoint p1;insert into person values(5,'aa',sysdate) rollback to p1;


--视图
--键保留表(视图中的主键为表的主键)
--不能同时修改两张表,除非主键都是键保留,只能修改键保留表中数据
----索引
--oracle 中索引按照rowid排序,其结构为平衡二叉树 及遍历 2的对数次
--重建索引,当oracle 自定义的结构不平衡时。
--反向键索引  当统计中国百家姓的情况reverse
--create index re_index on itemfile(itemcode) reverse
--位图索引适合创建在低基数列上(男女),因为它不直接存储在rowid上,而是存储字节位到rowid的映

射上


declare name varchar2(20);
no number;
begin
no:=7369;
select ename into name  from emp where empno=no;
dbms_output.put_line(name);
exception
when no_data_found then
dbms_output.put_line('未找到该数据');
end;

 

 

declare score number;
begin
score:=&score;
if(score>100) then
 dbms_output.put_line('成绩非法');
elsif(score>90) then
 dbms_output.put_line('A');
elsif(score>80) then
 dbms_output.put_line('B');
elsif(score>70) then
 dbms_output.put_line('C');
elsif(score>60) then
 dbms_output.put_line('D');
else
 dbms_output.put_line('E');
end if;
end;

 


declare no emp.empno%type;
rec emp%rowtype;
begin
no:=&no;
select * into rec from emp where empno=no;
dbms_output.put_line(rec.deptno||':'||rec.ename);
end;

 

原创粉丝点击