/* 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学习笔记(十) 查询练习(一)

查询练习一

表创建
create table employee as select * from soctt.emp ;
--记得授权
sysdba用户登录
grant select on scott.emp to $username$

--表结构
create table empployee_demo(
   empno     number(4) not null primary key,  --员工编号,主键
   ename     varchar2(10) not null unique,    --员工名,唯一键
   job       varchar2(9),                     --职位、工作
   mgr       number(4),                       --经理编号
   hiredate  date default sysdate,            --入职日期,默认约束
   sal       number(7,2) check(sal>=500 and sal<=10000),   --工资
   comm      number(7,2),                     --资金
   deptno    number(2)                        --部门编号
)

--16. 找出各月倒数第三天受雇的所有员工
select * from employee where last_day(hiredate)-2=hiredate;

--17. 找出早于25年前受雇佣的员工
select * from employee where months_between(hiredate,sysdate)/12>25;
select * from employee where year(sysdate)-year(hiredate)>25;

--18. 以首字母大写其它字母小写的方式显示所有的员工的姓名
select upper(substr(ename,0,1))||lower(substr(ename,1)) from employee;
--下面这两种写法都是可以获得同样的结果,不过不太清楚加nls的区别
select nls_initcap(ename) from employee;
select initcap(ename) from employee;

--以首字母小写其它字母大写的方式显示所有的员工的姓名。
select lower(substr(ename,1,1))||upper(substr(ename,2)) from employee;

--19. 显示正好为5字符的员工的姓名
select ename from employee where length(ename)=5;

--20. 显示不带有‘R’的与员工的姓名
select ename from employee where ename not like '%R%';

--21. 显示所有员工姓名的前三个字符。
select substr(ename,1,3) from employee --注意,与java中截取字符串的有所区别

--22. 显示所有员工的姓名,用 A 替换 a 
select replace(ename,'a','A') from employee; --把a替换成A

--23. 显示 满25年 服务年限的员工的姓名 和受雇日期
select ename,hiretate from employee where months_between(hiredate,sysdate)/12 >=25

--24. 显示员工的详细资料,按姓名排序,姓名相同按工资降序排序。
select * from employee order by ename,sal desc; --asc升序 desc降序 默认升序

--25. 显示与员工的姓名和受雇日期,根据其服务年限,将最老的员工排在最前面。
select ename,hiredate,months_between(hiredate,sysdate) 
from employee 
order by months_between(hiredate,sysdate)

select ename,hiredate,months_between(sysdate,hiredate) 
from employee 
order by months_between(sysdate,hiredate) desc

--26. 显示所有员工的姓名,工作和薪金,按工作的降序排序,若工作相同按薪金排序
select ename,job,sal from employee 
order by job,sal;

/*
27. 显示所有员工的姓名,加入公司的年份和月份,按受雇日期所在的月排序,
    若月份相同,则将最早的年份的员工排在最前面
*/
select ename,JOB,TO_CHAR(hiredate,'yyyy') year,
    TO_CHAR(hiredate,'mm') month
  from employee 
    order by month,year;
posted @ 2019-09-19 14:36  我的人生  阅读(294)  评论(0)    收藏  举报