黑马程序员c语言教程:Oracle指令由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“黑马程序员c语言教程”。
--sql structured query language
--DML--Data Manipulation Language--数据操作语言
query information(SELECT), add new rows(INSERT), modify existing rows(UPDATE), delete existing rows(DELETE), perform a conditional update or insert operation(MERGE), see an execution plan of SQL(EXPLAIN PLAN), and lock a table to restrict acce(LOCK TABLE).--DDL--Data Definition Language--数据定义语言
create, modify,drop, or rename objects(CREATE,ALTER,DROP,RENAME), remove all rows from a database object without dropping the structure(TRUNCATE), manage acce privileges(GRANT,REVOKE), audit database use(AUDIT,NOAUDIT)and add a description about an object to the dictionary(COMMENT).--Transaction Control事务控制语句 save the changes(COMMIT)or discard the changes(ROLLBACK)made by DML statements.Also included in the transaction-control statements are statements to set a point or marker in the transaction for poible rollback(SAVEPOINT)and to define the properties for the transaction(SET TRANSACTION).Used to manage the properties of the database.There isonly one statement in this category(ALTER SYSTEM).--DCL--Data Control Language--与开发关系不是很密切,用于权限的分配与回收 grant,revoke,data control
--Seion Control control the seion properties(ALTER SESSION)and to enable/disable roles(SET ROLE).--System Control
-------------------------select的用法
--每个员工的所有信息
select * from emp--每个人的部门编号,姓名,薪水
select deptno,ename,sal from emp;--每个人的年薪
select ename,sal*12 from emp;--计算2*3的值
select 2*3 from emp;--计算2*3的值(dual)select 2*3 from dual;select * from dual;--得到当前时间
select sysdate from dual--可以给列起别名,比如求每个人的年薪
select ename,sal*12 salperyear from emp;--如果别名中有空格,需要用双引号
select ename,sal*12 “sal per year” from emp;--如果没有内容,则为空 select comm from emp;--当空字段参与计算,则结果是null--例如:计算每个人的全年的收入包括月薪和年终奖 select ename,sal*12+comm from emp;--可以将多个字符串拼在一起。比如:求每个人的薪水,格式为smith-sal-123 select ename||'-sal-'||sal from emp;--如果字符串中有单引号,需要用另外一个单引号转义,比如:这样一个字符串: he's friend select ename||'''s sal is'||sal from emp;
---------------------------distinct 关键词的用法--求有哪些个部门
select distinct deptno from emp--可以用来修饰多个字段。比如:求有哪些个部门和job的组合 select distinct deptno,job from emp
-------------------------where关键词的用法
--可以是数值类型的等值判断。比如:求10这个部门的所有员工 select * from emp where deptno=20--可以是字符串类型的等值判断。比如:求叫KING的这个人的信息 select * from emp where ename = 'KING'--也可以是不等值判断。比如:求薪水小于2000的员工信息 select * from emp where sal
--字符串也可以做不等值判断,比如:求所有ename大于'CBA'的员工信息。select * from emp where ename>'CBA';--求部门不是10的员工
select * from emp where deptno 10;--求薪水在800和1500之间的员工信息
select * from emp where sal >=800 and sal
select * from emp where sal between 800 and 1500--这样写则不可以
-----------------------------select * from emp where 800
select * from emp where sal in(1500,800,2000,1500,1500,1500,1500);--再比如求姓名是KING,SMITH,AA的员工信息
select * from emp where ename in('KING','SMITH','AA')--求入职时间在20-2月-81之后的员工信息
select * from emp where hiredate
---------------------------and or not的用法
--求薪水大于1000或者部门在20这个部门的员工信息 select * from emp where sal>1000 and deptno=20--求薪水不是800或者不是1500或者不是3000的员工信息 select * from emp where sal not in(800,1500,3000)--也可以这样来写
select * from emp where sal 800 and sal 1500 and sal3000
---------------------------like的用法
--求名字中包含ALL这三个字符的员工信息
select * from emp where ename like '%E%';--求名字中的第二个字母是A的员工
select * from emp where ename like '_A%';--特殊字符需要转义。比如:求员工中包含特殊字符%的员工信息 select * from emp where ename like '%%%' escape ''
---------------------------null的用法
--求没有年终奖的员工
select * from emp where comm is null--求有年终奖的员工
select * from emp where comm is not null
------------------------- --order by的用法--员工信息按照姓名正序排列select * from emp order by ename asc; --员工信息按照倒叙排列select * from emp order by ename......
------------------------- --不准用组函数(即MAX()),求薪水的最高值(面试题) --第一种解决办法: --1,先把所有薪水按照倒序排列 --2,再取第一行 select * from (select sal......
--总结一下select语法 select from where group by having order by ------------------------- -- 执行顺序very important! -- 首先执行where语句将原有记录过滤; -- 第二......
--什么时候用外连接呢?比如领导向你要所有学生的列表,顺便把所属的班级也列出来,就需要外连接 --在Where语句中使用子查询--- --雇员中最高薪水的人员名称 --1,先求出最高薪......
------------------------------ --为什么in的后面不能order by ?- --求部门经理人中平均薪水最低的部门名称 (思考题) 第一步,求部门经理的雇员编号select distinct mgr fro......