/* 2 功能:生成博客目录的JS工具 3 测试:IE8,火狐,google测试通过 6 */ 7 var BlogDirectory = { 8 /* 9 获取元素位置,距浏览器左边界的距离(left)和距浏览器上边界的距离(top) 10 */ 11 getElementPosition:function (ele) { 12 var topPosition = 0; 13 var leftPosition = 0; 14 while (ele){ 15 topPosition += ele.offsetTop; 16 leftPosition += ele.offsetLeft; 17 ele = ele.offsetParent; 18 } 19 return {top:topPosition, left:leftPosition}; 20 }, 21 22 /* 23 获取滚动条当前位置 24 */ 25 getScrollBarPosition:function () { 26 var scrollBarPosition = document.body.scrollTop || document.documentElement.scrollTop; 27 return scrollBarPosition; 28 }, 29 30 /* 31 移动滚动条,finalPos 为目的位置,internal 为移动速度 32 */ 33 moveScrollBar:function(finalpos, interval) { 34 35 //若不支持此方法,则退出 36 if(!window.scrollTo) { 37 return false; 38 } 39 40 //窗体滚动时,禁用鼠标滚轮 41 window.onmousewheel = function(){ 42 return false; 43 }; 44 45 //清除计时 46 if (document.body.movement) { 47 clearTimeout(document.body.movement); 48 } 49 50 var currentpos =BlogDirectory.getScrollBarPosition();//获取滚动条当前位置 51 52 var dist = 0; 53 if (currentpos == finalpos) {//到达预定位置,则解禁鼠标滚轮,并退出 54 window.onmousewheel = function(){ 55 return true; 56 } 57 return true; 58 } 59 if (currentpos < finalpos) {//未到达,则计算下一步所要移动的距离 60 dist = Math.ceil((finalpos - currentpos)/10); 61 currentpos += dist; 62 } 63 if (currentpos > finalpos) { 64 dist = Math.ceil((currentpos - finalpos)/10); 65 currentpos -= dist; 66 } 67 68 var scrTop = BlogDirectory.getScrollBarPosition();//获取滚动条当前位置 69 window.scrollTo(0, currentpos);//移动窗口 70 if(BlogDirectory.getScrollBarPosition() == scrTop)//若已到底部,则解禁鼠标滚轮,并退出 71 { 72 window.onmousewheel = function(){ 73 return true; 74 } 75 return true; 76 } 77 78 //进行下一步移动 79 var repeat = "BlogDirectory.moveScrollBar(" + finalpos + "," + interval + ")"; 80 document.body.movement = setTimeout(repeat, interval); 81 }, 82 83 htmlDecode:function (text){ 84 var temp = document.createElement("div"); 85 temp.innerHTML = text; 86 var output = temp.innerText || temp.textContent; 87 temp = null; 88 return output; 89 }, 90 91 /* 92 创建博客目录, 93 id表示包含博文正文的 div 容器的 id, 94 mt 和 st 分别表示主标题和次级标题的标签名称(如 H2、H3,大写或小写都可以!), 95 interval 表示移动的速度 96 */ 97 createBlogDirectory:function (id, mt, st, interval){ 98 //获取博文正文div容器 99 var elem = document.getElementById(id); 100 if(!elem) return false; 101 //获取div中所有元素结点 102 var nodes = elem.getElementsByTagName("*"); 103 //创建博客目录的div容器 104 var divSideBar = document.createElement('DIV'); 105 divSideBar.className = 'sideBar'; 106 divSideBar.setAttribute('id', 'sideBar'); 107 var divSideBarTab = document.createElement('DIV'); 108 divSideBarTab.setAttribute('id', 'sideBarTab'); 109 divSideBar.appendChild(divSideBarTab); 110 var h2 = document.createElement('H2'); 111 divSideBarTab.appendChild(h2); 112 var txt = document.createTextNode('目录导航'); 113 h2.appendChild(txt); 114 var divSideBarContents = document.createElement('DIV'); 115 divSideBarContents.style.display = 'none'; 116 divSideBarContents.setAttribute('id', 'sideBarContents'); 117 divSideBar.appendChild(divSideBarContents); 118 //创建自定义列表 119 var dlist = document.createElement("dl"); 120 divSideBarContents.appendChild(dlist); 121 var num = 0;//统计找到的mt和st 122 mt = mt.toUpperCase();//转化成大写 123 st = st.toUpperCase();//转化成大写 124 //遍历所有元素结点 125 for(var i=0; i

oracle学习笔记(十四) 数据库对象 索引 视图 序列 同义词

数据库对象

用户模式:指数据库用户所创建和存储数据对象的统称。在访问其它用户模式的数据库对象时需加上用户模式。
如:scott.emp, scott.dept等。
数据库对象包括:表、视图、索引、序列、目录、同义词、数据库用户、存储过程、函数、触发器等。

同义词

同义词是现有数据库对象的一个别名。

  1. 简化SQL语句
  2. 隐藏对象的名称和所有者

同义词分为私有和公有的

--创建同义词得通过sys进行授权
grant create [any] synonym to $username$; --授权,创建私有同义词
grant create public synonym to $username$;--授权,创建公有同义词

私有:只有当前用户才能使用

--创建私有同义词
create [or replace] synonym 同义词名称 for 对象(如:表,视图等); 
drop synonym  $同义词名$; --删除同义词

create or replace synonym emp for employee;

公有:全部的用户都能使用

--创建公有同义词
create [or replace] public synonym 同义词名称 for 对象(如:表);
drop public synonym $同义词名$;--删除同义词

create or replace public synonym emp for employee;

序列

序列是用于生成唯一、连续序号的对象,如:1,2,3.......
作用:
序列常用于生成表的主键值、唯一键的值以及需要连续序号的场合。
补充:
序列可以是升序的,也可以是降序的。
一个序列产生的值可以同时供多个表使用,如果有这个需要的话。
创建序列:

--语法
CREATE sequence序列名
  START WITH 初始值 
  【INCREMNT BY 步长】 --步长为负数,则是降序
  【MAXVALUE  最大值】 
  【MINVALUE 最小值】
  【CYCLE/NOCYCLE】
  【CACHE/NOCACH】默认oracle缓存20个序列值
create sequence emp_seq
start with 1;

select emp_seq.nextval from dual;
--先执行,序列才会有数据,从1开始,步长默认为1,执行一次,序列的当前数值就会自加1

slect emp_seq.currval from dual;--返回当前的数值

--创建序列
create sequence emp_seq 
start with 8001; --没加increment by 默认步长为1

--最初创建序列时初始值是没有的,第一次访问序列必须先访问它的nextval属性
select emp_seq.nextval from dual;
select emp_seq.nextval,emp_seq.currval from dual;

--修改序列,不能修改初始值(start with x)
select max(empno) from emp;

--删除序列
drop sequence emp_seq;

--在插入时使用序列来生成主键值
insert into employee(empno,ename,job,sal) values(emp_seq.NEXTVAL, 'james','CLERK',3999);

--生成序列的下一个值
select emp_seq.nextval from dual;

--访问序列的当前值
select 'XYZ-'||emp_seq.currval from dual;

视图

视图,被称为虚拟表,可以简化select语句
作用:

  • 提供了另外一种级别的表安全性
  • 隐藏的数据的复杂性
  • 简化的用户的SQL语句
  • 隔离基表(创建视图时用到的表)结构的改变
  • 通过重命名列,从另一个角度提供数据
  • 数据独立性

和之前的序列一样,需要sys进行授权

grant create view to $username$
--相当于复制一个表
create view emp_view as select * from employee
--隐藏了其他的属性,只显示员工编号,姓名以及部门
create view emp_view as select empno,ename,deptno from employee
--复杂查询的结果当成一个表
--列出薪金高于公司平均薪金的所有员工,所在部门,上级领导,和工资等级
--如果需要使用当前的结果,使用select语句就简单许多
create or replace view emp_sal_vw
as 
  select e.empno,
    e.ename,
    d.dname dept_name,
    m.empno as mgrNo,
    m.ename as manager,
    s.grade
  from employee e,
       employee m, 
       department d,
       salgrade s
  where e.mgr=m.empno(+)
    AND e.deptno=d.deptno
    AND e.sal>(select avg(sal) from employee)
    AND e.sal BETWEEN s.losal AND s.hisal; 

索引

查询时候数据量大的时候,通过索引可以提高查询的效率(百万条数据级别),在常用的列名(字段)创建索引

--创建索引
create [unique] index $indexName$ on $tablename$(列名1,列名2...) 

唯一索引和普通索引

索引有唯一索引和普通索引,如在多个列上创建索引则成为组合索引
唯一索引一般在创表的时候,把某列设置某个主键,系统就会自动为该列创建唯一索引

--普通索引
create index hiredate_idx on employee(hiredate);
--组合索引
create index emp_comp on employee(mgr,deptno);
--组合索引的顺序可以是任意的,不过,此顺序会影响查询的时候是否会启用索引查询

--下面两条是会启用索进行查询
select mgr,deptno from employee;
select mgr from employee;

--下面两条是会不会启用索进行查询
select deptno from employee;
select deptno,mgr from employee;

函数索引

create index emp_job_fun on employee(lower(job));

--不启用索引查询
select * from employee where job='CLERK';

--启用索引查询
select * from employee where lower(job)='clerk';
posted @ 2019-09-19 14:38  我的人生  阅读(340)  评论(0编辑  收藏  举报