Oracle 11g xe
第三方图形客户端: PLSQL
Windows 10
创建用户:create user 用户名 identified by 用户名;
分配权限或角色:grant connect,resource to 用户名;
取消权限或角色:revoke 权限/角色 from 用户名;
connect:临时用户
resource:更为可靠的正式用户
dba:数据库管理员角色,拥有管理数据库的最高权限
注意:角色是具有名称的一组权限的组合。
【注意】数据操作语句针对表中的数据,而数据定义语句针对数据库对象(表、索引、视图、触发器、存储过程、函数、表空间等)
1)重命名查询结果中的字段,以增强可读性;
2)别名如果含有空格或其他特殊字符或大小写敏感,需用双引号引起来;
3)as 可以省略。
在搜索字段名前,加一个 distinct 关键字
例如:select distinct deptno from emp;
排序包括升序(asc,默认升序,该关键字可不写)和 降序(desc)
例如:select empno,ename,sal from emp order by sal; --------以sal升序进行排序
select empno,ename,sal from emp order by sal desc; --------以sal降序进行排序
举例:
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 -------不为空
例如:select * from emp where deptno = 10 and sal > 1000;
and:把检索结果较少的条件放到后面
or :把检索结果较多的放到后面
重要:算术 > 连接 > 比较 > 逻辑
优先级:
- * /
- + -
- ||
- >, <, >=, <=, <>
- is [not] null ,like [not] in
- [not] between… and…
- not
- and
- or
函数分为:
单行函数:字符函数、数值函数、日期函数、转换函数、通用函数
多行函数:sum(),avg() ----仅适用数值型。 count(),max(),min() -----适用任何类型数据
字符函数:
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) -----连接字符串
数值函数:
日期函数:
转换函数:
其他函数:
原文:https://www.cnblogs.com/cgntiger/p/10981102.html