马士兵oracle笔记

上传人:re****.1 文档编号:562576602 上传时间:2022-11-01 格式:DOC 页数:20 大小:62.01KB
返回 下载 相关 举报
马士兵oracle笔记_第1页
第1页 / 共20页
马士兵oracle笔记_第2页
第2页 / 共20页
马士兵oracle笔记_第3页
第3页 / 共20页
马士兵oracle笔记_第4页
第4页 / 共20页
马士兵oracle笔记_第5页
第5页 / 共20页
点击查看更多>>
资源描述

《马士兵oracle笔记》由会员分享,可在线阅读,更多相关《马士兵oracle笔记(20页珍藏版)》请在金锄头文库上搜索。

1、第一课:客户端 1. Sql Plus(客户端),命令行直接输入:sqlplus,然后按提示输入用户名,密码。 2. 从开始程序运行:sqlplus,是图形版的sqlplus. 3. http:/localhost:5560/isqlplus Toad:管理, PlSql Developer:第二课:更改用户 1. sqlplus sys/bjsxt as sysdba 2. alter user scott account unlock;(解锁)第三课:table structure 1. 描述某一张表:desc 表名 2. select * from 表名第四课:select 语句: 1.

2、计算数据可以用空表:比如:.select 2*3 from dual 2.select ename,sal*12 annual_sal from emp;与select ename,sal*12 annual sal from emp;区别,加双引号保持原大小写。不加全变大写。 3. select ename | abcd 如果连接字符串中含有单引号,用两个单引号代替一个单引号。第五课:distinct select deptno from emp; select distinct deptno from emp; select distinct deptno from emp; select

3、 distinct deptno ,job from emp 去掉deptno,job两者组合的重复。更多的项,就是这么多项的组合的不重复组合。第六课:Where select * from emp where deptno =10; select * from emp where deptno 10;不等于10 select * from emp where ename =bike; select ename,sal from emp where sal between 800 and 1500 (=800 and 800 order by sal desc; select lower(en

4、ame) from emp; select ename from emp where lower(ename) like _a%;等同于 select ename from emp where ename like _a% or ename like _A%; select substr(ename,2,3) from emp;从第二字符截,一共截三个字符. select chr(65) from dual 结果为:A select ascii(a) from dual 结果为:65 select round(23.652,1) from dual; 结果为: 23.7 select roun

5、d(23.652,-1) from dual; 20 select to_char(sal,$99_999_999) from emp; select to_char(sal,L99_999_999) from emp;人民币符号,L:代表本地符号 这个需要掌握牢: select birthdate from emp; 显示为: BIRTHDATE - 17-12月-80 - 改为: select to_char(birthdate,YYYY-MM-DD HH:MI:SS) from emp; 显示: BIRTHDATE - 1980-12-17 12:00:00 - select to_ch

6、ar(sysdate,YYYY-MM-DD HH24:MI:SS) from dual; /也可以改为:HH12 TO_CHAR(SYSDATE,YY - 2007-02-25 14:46:14 to_date函数: select ename,birthdate from emp where birthdate to_date(1981-2-20 12:34:56,YYYY-MM-DD HH24:MI:SS); 如果直接写 birthdate1981-2-20 12:34:56会出现格式不匹配,因为表中的格式为: DD-MM月-YY. select sal from emp where sal

7、888.88 无错.但 select sal from emp where sal$1,250,00; 会出现无效字符错误. 改为: select sal from emp where salto_number($1.250.00,$9,999,99); 把空值改为0 select ename,sal*12+nvl(comm,0) from emp; 这样可以防止comm为空时,sal*12相加也为空的情况.第九课: Group function 组函数 max,min,avg ,count,sum函数 select to_char(avg(sal),99999999,99) from emp

8、; select round(avg(sal),2) from emp; 结果:2073.21 select count(*) from emp where deptno=10; select count(ename) from emp where deptno=10; count某个字段,如果这个字段不为空就算一个. select count(distinct deptno) from emp; select sum(sal) from emp;第十课: Group by语句 需求:现在想求,求每个部门的平均薪水. select avg(sal) from emp group by dept

9、no; select deptno avg(sal) from emp group by deptno; select deptno,job,max(sal) from emp group by deptno,job; 求薪水值最高的人的名字. select ename,max(sal) from emp;出错,因为max只有一个值,但等于max值的人可能好几个,不能匹配. 应如下求: select ename from emp where sal=(select max(sal) from emp); Group by语句应注意, 出现在select中的字段,如果没出现在组函数中,必须出现在

10、Group by语句中. 第十一课: Having 对分组结果筛选 Where是对单条纪录进行筛选,Having是对分组结果进行筛选. select avg(sal),deptno from emp group by deptno having avg(sal)2000; 查询工资大于1200雇员,按部门编号进行分组,分组后平均薪水大于1500,按工薪倒充排列. select * from emp where sal1200 group by deptno having avg(sal)1500 order by avg(sal) desc; 第十二课:字查询 谁挣的钱最多(谁:这个人的名字, 钱最多) select 语句中嵌套select 语句,可以在where,from后. 问那些人工资,在平均工资之上.

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 中学教育 > 试题/考题 > 初中试题/考题

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号