一、建设用户和授予权限
1.1 情形:
Oracle 11g xe
第三方图形客户端: PLSQL
Windows 10
?
1.2 SQL 语句
建设用户:create user 用户名 identified by 用户名;
分派权限或脚色:grant connect,resource to 用户名;
打消权限或脚色:revoke 权限/脚色 from 用户名;
?
1.3 常用体系预界说脚色
connect:姑且用户
resource:更为靠得住的正式用户
dba:数据库打点员脚色,拥有打点数据库的最高权限
留意:脚色是具著名称的一组权限的组合。
?
二、SQL 说话的总结
2.1? SQL可以做什么?
- 数据库数据的增编削查操纵(CRUP)
- 数据库工具的建设,修改和删除操纵
- 用户权限/脚色的授予和打消
- 事宜节制
?
2.2? SQL说话的分类
- DQL? (数据查询语句)select
- DML(数据操纵语句)insert、update、delete
- DDL(数据界说语句)create、alter、drop
- DCL(数据节制语句)grant、revoke
- TCL(事宜节制语句)savepoint、rollback、set transaction、commit
【留意】数据操纵语句针对表中的数据,而数据界说语句针对数据库工具(表、索引、视图、触发器、存储进程、函数、表空间等)
?
2.3? select 查询语句
2.3.1 字段别名
1)重定名查询功效中的字段,以加强可读性;
2)别名假如含有空格或其他非凡字符或巨细写敏感,需用双引号引起来;
3)as 可以省略。
?
2.3.2? 去除一再行
在搜刮字段名前,加一个 distinct 要害字
譬喻:select distinct deptno from emp;
2.3.3? 排序---order by
排序包罗升序(asc,默认升序,该要害字可不写)和 降序(desc)
譬喻:select empno,ename,sal from emp order by sal;????????? --------以sal升序举办排序
???????? select empno,sal from emp order by sal desc; --------以sal降序举办排序
2.3.4? where 字句
举例:
select * from emp where deptno = 10;
select * from emp where ename = ‘SMITH’;
select * from emp where hiredate = ‘02-4月-81’;
留意:
1)字符串和日期值要用单引号括起来
2)字符串巨细写敏感
3)日期值名目敏感!!!
?
其他要害字:
- between… and…???? ------界于两值之间(包罗界线)
- in(value,value…)??? ------呈此刻荟萃中
- like?????????????????????? ------恍惚查询(%暗示零个或多个字符? _暗示一个字符,非凡字符可行使escape标识符查找)
- is null?????????????????? -------为空值
- not is null???????????? -------不为空
2.3.5? 逻辑运算符
譬喻:select * from emp where deptno = 10 and sal > 1000;
2.3.6?? SQL优化题目
and:把检索功效较少的前提放到后头
or? :把检索功效较多的放到后头
2.3.7?? 四种运算符
重要:算术? >? 毗连?? >? 较量? >? 逻辑
优先级:
- * /
- + -
- ||
- >,<,>=,<=,<>
- is [not] null,like [not] in
- [not] between… and…
- not
- and
- or
?
2.3.8?? 行使函数
函数分为:
单行函数:字符函数、数值函数、日期函数、转换函数、通用函数
多行函数:sum(),avg()? ----仅合用数值型。???? count(),max(),min()?? -----合用任何范例数据
2.3.8.1 单行函数
字符函数:
initcap(char)???????????????? -----首字母大写
lower(char)?????????????????? -----转换为小写
upper(char)?????????????????? -----转换为大写
ltrim(char,set)?????????????? -----左剪裁
rtrim(char,set)?????????????? -----右剪裁
replace(char,search_str,replace_str) -----字符串替代
instr(char,substr[,pos])?? -----查找字符串位置,譬喻:? instr(‘worldwide’,’d’)
substr(char,pos,len)??????? -----取子字符串
concat(char1,char2)??????? -----毗连字符串
数值函数:
日期函数:
转换函数:
其他函数:
?
2.3.8.2??? 多行函数
(编辑:湖南网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|