没有合适的资源?快使用搜索试试~ 我知道了~
java-Oracle概要.docx
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 115 浏览量
2021-12-18
14:12:06
上传
评论
收藏 498KB DOCX 举报
温馨提示
![preview](https://dl-preview.csdnimg.cn/66149868/0001-7b3ad5d7f77b65da179eab87e588f026_thumbnail-wide.jpeg)
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
试读
37页
。。。
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![exe](https://img-home.csdnimg.cn/images/20210720083343.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/release/download_crawler_static/66149868/bg1.jpg)
Oracle 基础知识
一.数据库标准语言
结构化查询语言 SQL:Structureed Query Language
1)数据定义语言 DDL:Data Definition Language
create table 列表结构、alter table 修改列、drop table 删除列
2)数据操作语言 DML:Data Manipulation Language
insert 增加一行,某些列插入值、update 修改一行,这一行的某些列、delete 删除一
行,跟列无关
3)事务控制语言 TCL:Transaction Conrtol Language
commit 确认,提交(入库)、rollback 取消,回滚,撤销
4)数据查询语言 DQL:Data Query Language
select 语句
5)数据控制语言 DCL:Data Control Language
系统为多用户系统因此有隐私权限问题:grant 授权、revoke 回收权限
几个简单命令
show user:查看当前用户
desc 表名:查看表结构
drop table 表名 purge;删除表,Oracle 中删除表不是真正的删除,而是占空间的移动到别
的地方,因为为了不占空间,真正的删除需要用purge。
delete from 表名:删除表中所有值;若加上 where 列名=value 则删除某列中的值
二.基本查询语句
1.select 语句功能
1)投影操作:结果集是源表中的部分“列”
2)选择操作:结果集是源表中的部分“行”
3)选择操作+投影操作:结果集是源表中的部分“行”部分“列”
4)连接操作 join:多表查询,结果集来自多张表,把多张的记录按一定条件组合起来
select 语句基本语法
1)select colname(列名)
from tabname(表名)
2)select 中指定多个列名,则用“逗号”分隔:select colname1,colname2 from tabname
3)* 号表示所有列:select * from tabname
4)select 语句:可有多个子句
5)select 子句:投影操作(列名)、列表达式、函数 、from 子句等
列别名
1)给列起一个别名,能够改变一个列、表达式的标识。
2)不写的话默认都是转成大写。 3)适合计算字段。
4)在原名和别名之间可以使用 as 关键字。
5)别名中包含空格、特数字符或希望大小写敏感的,用“”双引号将其括起来。
1 / 37
1
![](https://csdnimg.cn/release/download_crawler_static/66149868/bg2.jpg)
算术表达式
在 number 类型上使用算术表达式(加减乘除)。
eg:一个月使用了 250 小时,每种资费标准下应缴纳的费用(首次实现)
select base_cost + (250 - base_duration)*unit_cost fee from cost;
空值 null 的处理
未知的,没写数
1)空值不等于 0
2)空值不等于空格
3)在算术表达式中包含空值导致结果为空
4)在算术表达式中包含空值需要用空值转换函数nvl 处理
nvl(p1,p2) 函数
空值转换函数
1)两个参数类型要一致!
2)参数的数据类型可以是数值 number、字符 character、日期 date
3)但 null 转成字符串,null 也要用 to_char()转化。
4)实现过程:
elase
end if
5)实现空值转换:null->非 null 值 0
eg:一个月使用了 250 小时,每种资费标准下应缴纳的费用(再次实现)
select nvl(base_cost,0) + (250 - nvl(base_duration,0)) * nvl(unit_cost,0) fee from cost;
拼接运算符 ||
表达字符(串)的拼接,可以将某几列或某列与字符串拼接在一起。
select colname1||colname2 from tabname
文字字符串
select 语句后面可以包含的文字值:字符、表达式、数字。
1)字符常量(或字符串)必须用‘’单引号括起来,作为“定界符”使用。
2)表达单引号本身,需要两个单引号 ' ' ' ' 1,4 定界 2,3 表单引号。
3)对于文字值每行输出一次。
eg:显示客户姓名的身份证号是……
select real_name | | ' ' ' s IDCARD NO is ' | | idcard_no | | ' . ' cilent from account;
4)函数转换大小写,尽量在进入数据时操作。
消除重复行
distinct 去重复行(对整条记录返回的结果去重,不是对后面的某个列去重),若后面有
多列,则所有列联合起来唯一,即每列的值都可以重复,但组合不能重复。
eg1:哪些 unix 服务器提供远程登录业务
2 / 37
2
![](https://csdnimg.cn/release/download_crawler_static/66149868/bg3.jpg)
select distinct unix_host from service;
eg2:每一台 unix 服务器在哪些天开通了远程登录业务
select distinct unix_host,create_date from service;
其他注意事项
1)调常量时用单行单列的 dual 表,系统提供的表。
2)invalid identifier 无效标识名,列名不。
3)table or view does not exist 表名不对。
2.where 子句
用 where 子句对表里的记录进行过滤,where 子句跟在 from 子句后面。
where 子句后面可以跟什么
跟条件表达式:列名、常量、比较运算符(单、多值运算符)、文字值;不能跟组函数!
不能跟列别名!
注意事项:对列不经过运算的条件表达式效率会更高,建议在写 where 子句时尽量
不要对列进行运算。
eg:一年的固定费用为 70.8 元,计算年包在线时长
select base_duration*12 ann_duration from cost where base_cost*12=70.8; 没下面效率高
select base_duration*12 ann_duration from cost where base_cost=70.8/12;
语法和执行顺序
语法顺序:select from where
执行顺序:from where select
字符串是大小写敏感的,在比较时严格区分大小写
1)upper():函数将字符串转换成大写。
2)lower():函数将字符串转换成小写。
3)initcap():函数将字符串转换成首字符大写(是将列中的值大小写转换然后去和等号
后的字符串比,而不是把转字符串转换去和列比)。
eg:哪些 unix 服务器上开通了 os 帐号 huangr
select unix_host,os_username from service
where upper(os_username)='HUANGR';(有结果)
where 子句后面可以跟多个条件表达式
条件表达式之间用 and、or 连接,也可用()改变顺序。
betweenand 运算符
表示一个范围,是闭区间,含义为大于等于并且小于等于。
eg:哪些资费的月固定费用在 5 元到 10 元之间
select base_duration,base_cost,unit_cost from cost
where base_cost >= 5 and base_cost <= 10;
3 / 37
where base_cost between 5 and 10;
3
![](https://csdnimg.cn/release/download_crawler_static/66149868/bg4.jpg)
in 运算符(多值运算符)
表示一个集合,是离散值,含义为等于其中任意一个值,等价于any。
eg:哪些资费的月固定费用是 5.9 元,8.5 元,10.5 元
select base_duration,base_cost,unit_cost from cost
where base_cost in(5.9,8.5,10.5);
where base_cost =any(5.9,8.5,10.5);
like 运算符
在字符串比较中,可用 like 和通配符进行模糊查找。
1)通配符:%表示 0 或多个字符; _表示任意“一个”字符(要占位的)。
注意事项:若要查找%和_本身,则需要 escape 进行转移。
eg:哪些 unix 服务器上的 os 帐号名是以 h 开头的
select os_username from service where os_username like 'h%'
eg:哪些 unix 服务器上的 os 帐号名是以 h_开头的
select os_username from service where os_username like 'h\_%' escape '\';
isnull 运算符
测试 null 值需要用 is null。
1)null 不能用等于号“=”和不等于号“<>”跟任何值比较,包括它自身。所以不能用
“=”和“<>”来测试是否有空值。
2)即:null=null 是不成立的;null 不等于 null 也不成立;null 和任何值比较都不成立。
eg:列出月固定费用是 5.9 元,8.5 元,10.5 元或者没有月固定费。
select base_duration,base_cost,unit_cost from cost
where base_cost in (5.9,8.5,10.5) or base_cost is null;(正确)
比较和逻辑运算符(单值运算符)
1)比较运算符:=
> >=
<
<=
2)SQL 比较运算符:between and、in、like、is null
3)逻辑运算符:and、or、not
多值运算符 all、any
1)>all:大于所有的,等价于 >(select max()…)。
2)>any:大于任意的,等价于 >(select min()…)。
运算符的否定形式
1)比较运算符:<> != ^=
2)SQL 比较运算符:not between and
注意事项:
not in
not like is not null
❖ in 相当于=or =or =or 等价于 any
❖ not in 等价于 <>and <>and <>and 等价于<>all
❖ not between and 小于下界 or 大于上界
❖ 集合中有 null,对 in 无影响;但对 not in 有影响,有一个就没有返回值!
4 / 37
4
![](https://csdnimg.cn/release/download_crawler_static/66149868/bg5.jpg)
eg:哪些资费信息的月固定费用不是 5.9 元,8.5 元,10.5 元
select base_duration,base_cost,unit_cost from cost
where nvl(base_cost,0) <> 5.9 and nvl(base_cost,0) <> 8.5 and nvl(base_cost,0) <> 10.5;
where nvl(base_cost,0) not in (5.9,8.5,10.5);
3.order by 子句
select 语句输出的结果安记录在表中的存储顺序显示,order by 子句能够改变记录的输出
顺序。
order by 子句对查询出来的结果集进行排序,即对 select 子句的计算结果排序。
语法和执行顺序
语法顺序:select from where order by
执行顺序:from where select order by
升降序
ASC-升序,可以省略,默认值
DESC-降序
order by unix_host,create_date desc;
order by nvl(base_cost,0);
注意事项:order by 是 select 语句中最后一个子句
null 值在排序中显示
1)被排序的列如果包含 null 值,用 ASC 方式 null 值的在最后;
2)用 DESC 方式 null 在最前面;
orderby 后面可以跟什么
可以跟列名、列别名、列位置(数字)、表达式、函数。
order by 1:表示列位置为 1 的列
select 1 from:表示常量 1
eg:按年固定费用从大到小的顺序显示资费信息
方式一: select id,base_cost*12 ann_cost,base_duration ann_duration from cost
order by base_cost desc;
方式二: select id,base_cost ann_cost,base_duration ann_duration from cost
order by base_cost*12 desc;排序的效果和上面是一样的,但前一个效率高。
多列排序
order by 子句后面可以跟多列,而order by 后面的列可以不出现在 select 后面。结果集先
按第一列升序排列,若列值一样,再按第二列降序排列。
eg:按 unix 服务器 ip 地址升序,开通时间降序显示业务帐号信息
select id,unix_host,os_username,create_date from service
order by unix_host,create_date desc;
4.group by 子句
将表中的记录进行分组
5 / 37
5
剩余36页未读,继续阅读
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/6d4a39ec593a4e2fbcf3d53e4855e565_cqn2bd2b.jpg!1)
苦茶子12138
- 粉丝: 1w+
- 资源: 6万+
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)