查询oracle数据库_sql学习笔记

oracle数据库学习  时间:2021-03-15  阅读:()

资料内容仅供您学习参考如有不当或者侵权请联系改正或者删除。oracle-9isql(structured query language,结构化查询语言)

SQL语言按照功能可分为4大类

*DQL(数据查询语言):查询数据

*DDL(数据定义语言):建立/删除和修改数据对象

*DML(数据操纵语言):完成数据操作的命令,包括查询

*DCL(数据控制语言):控制对数据库的访问,服务器的关闭/启动等在Oracle 9i中为使用SQL语言提供了2个主要工具

*[SQL Plus]

*[SQL Plus Worksheet]select*from scott.emp--"用户名.数据表"的形式select distinct job from scott.emp--distinct保留字指在显示时去除相同的记录,select empno,ename,jobfrom scott.empwherejob='MANAGER'select empno,ename,salfrom scott.empwhere sal<=2500

--等于select*from scott.empwherejob='MANAGER'select*from scott.emp where sal=1100

--不等于select*from scott.empwherejob!='MANAGER'

资料内容仅供您学习参考如有不当或者侵权请联系改正或者删除。select*from scott.emp where sal !=1100select*from scott.empwherejob^='MANAGER'select*from scott.emp where sal^=1100select*from scott.emp wherejob<>'MANAGER'select*from scott.emp where sal<>1100

--小于select*from scott.empwherejob<'MANAGER'select*from scott.emp where sal<

--大于select*from scott.empwherejob>'MANAGER'select*from scott.emp where sal>

--int列表select*from scott.empwhere sal in( ,1000,3000)select*from scott.empwherejob in('MANAGER', 'CLERK')select*from scott.empwhere sal not in( ,1000,3000)select*from scott.empwherejob not in('MANAGER', 'CLERK')

--betweenselect*from scott.empwhere sal not between and 3000select*from scott.empwherejob not between'MANAGER'and'CLERK'--l ikeselect*from scott.emp wherejob l ike'%M%' --代表包含M的字符串select*from scott.emp wherejob l ike'%M' --代表以M字符结尾的字符串

资料内容仅供您学习参考如有不当或者侵权请联系改正或者删除。select*from scott.emp wherejob l ike'M%' --代表以M字符开头的字符串select*from scott.emp wherejob l ike'M_' --代表M开头的长度为2的字符串select empno,ename,jobfrom scott.empwherejob>='CLERK'orsal<=

"notjob='CLERK'"等价于"job<>'CLERK'"

--逻辑比较符and(与) select*from scott.empwherejob='MANAGER'and sal<>or(或) select* from scott.empwherejob!='MANAGER'or sal<>not(菲) select*from scott.emp where not job>='MANAGER'

--排序查询select empno,ename,job,salfrom scott.empwherejob<='CLERK'order byjobasc,sal desc--分组查询select empno,ename,job,salfrom scott.empgroup byjob,empno,ename,sal having sal<=select empno,ename,job,sal from scott.empwhere sal<= group byjob,empno,ename,sal/*where检查每条记录是否符合条件,having是检查分组后的各组是否满足条件.having语句只能配合group by

语句使用,没有group by时不能使用having,但可使用where*/select empno,ename,sal,mgr,sal+mgr from scott.emp --"常见'+' '-' '*' '/'"select empno编号,ename姓名,job工作,sal薪水from scott.emp

--无条件多表查询"笛卡尔"积的方式组合起来

资料内容仅供您学习参考如有不当或者侵权请联系改正或者删除。select emp.empno,emp.ename,emp.deptno,dept.dname,dept. loc from scott.emp,scott.dept--等值多表查询select emp.empno,emp.ename,emp.deptno,dept.dname,dept. locfrom scott.emp,scott.deptwhere scott.emp.deptno=scott.dept.deptno --具有相同的属性(相同的数据类型/宽度和取值范围)

--非等值多表查询select emp.empno,emp.ename,emp.deptno,dept.dname,dept. locfrom scott.emp,scott.deptwhere scott.emp.deptno!=scott.dept.deptno and scott.emp.deptno=10

--嵌套查询

子查询能够嵌套多层,子查询操作的数据表能够是父查询不操作的数据表,子查询中不能有order by分组语句select emp.empno,emp.ename,emp.job,emp.salfrom scott.empwhere sal>=(select salfrom scott.empwhere ename='WARD')--查询薪水>=WARD薪水的员工select emp.empno,emp.ename,emp.job,emp.salfrom scott.empwhere sal in (select sal from scott.emp where ename='WARD') --查询薪水和WARD相等的员工

带any查询select emp.empno,emp.ename,emp.job,emp.sal

资料内容仅供您学习参考如有不当或者侵权请联系改正或者删除。from scott.empwhere sal>any(select sal from scott.empwhere job='MANAGER')

/*select sal from scott.empwherejob='MANAGER' --查询到3各薪水值2975/2850/2450select emp.empno,emp.ename,emp.job,emp.salfrom scott.empwhere sal>2975 orsal>2850 or sal>2450 --执行any查询条件语句

*/

带some查询select emp.empno,emp.ename,emp.job,emp.salfrom scott.empwhere sal=some(select sal from scott.empwherejob='MANAGER')

/*select sal from scott.empwherejob='MANAGER' --查询到3各薪水值2975/2850/2450select emp.empno,emp.ename,emp.job,emp.salfrom scott.empwhere sal=2975 orsal=2850 orsal=2450 --执行some查询条件语句

*/

带al l查询select emp.empno,emp.ename,emp.job,emp.salfrom scott.empwhere sal>al l(select sal from scott.empwherejob='MANAGER')

资料内容仅供您学习参考如有不当或者侵权请联系改正或者删除。

/*select sal from scott.empwherejob='MANAGER' --查询到3各薪水值2975/2850/2450select emp.empno,emp.ename,emp.job,emp.salfrom scott.empwheresal>2975andsal>2850and sal>2450 --执行al l查询条件语句

*/

带exists查询select emp.empno,emp.ename,emp.job,emp.salfrom scott.emp,scott.deptwhere exists(select *from scott.emp where scott.emp.deptno=scott.dept.deptno)

并操作查询

(select deptno from scott.emp)union(select deptno from scott.dept)

交操作查询

(select deptno from scott.emp) intersect (select deptno from scott.dept)

差操作查询--属于A且不属于B

(select deptno from scott.emp)minus(select deptno from scott.dept)

--用SQL进行函数查询

[cei l]函数:cei l(n),取大于等于数值n的最小整数select mgr,mgt/100,cei l(mgr/100)from scott.emp

[floor]函数:floor(n),取小于等于数值n的最大整数select mgr,mgt/100,floor(mgr/100)from scott.emp

资料内容仅供您学习参考如有不当或者侵权请联系改正或者删除。[mod]函数:mod(m,n),取m整除n后的余数select mgr,mod(mgr,1000),mod(mgr,100),mod(mgr,10)from scott.emp[power]函数:power(m,n),取m的n次方select mgr,power(mgr,2),power(mgr,3)from scott.emp

[round]函数:round(m,n),四舍五入,保留n位select mgr,round(mgr/100,2),round(mgr/1000,2)from scott.emp

[sign]函数:sign(n),n>0,取1; n=0,取0;n<0,取-1select mgr,mgr-7800,sign(mgr-7800)from scott.emp

[a vg]函数:a vg(字段名),求平均值,要求字段为数据值select avg(mgr)平均薪水from scott.emp

[count]函数:count(字段名)或count(*),统计总数select count(*)记录总数from scott.empselect count(distinct job)工作类别总数from scott.emp

[min]函数:min(字段名),计算数值型字段最小数select min(sal)最少薪水from scott.emp

[max]函数:max(字段名),计算数值型字段最大数select max(sal)最高薪水from scott.emp

[sum]函数:sum(字段名),计算数值型字段总和select sum(sal)薪水总和from scott.emp

--记录的录入

资料内容仅供您学习参考如有不当或者侵权请联系改正或者删除。

1.单行记录的录入insert into数据表 valuesinsert into scott.emp(empno,ename,hiredate)values(8000, 'JONE', '25-11月- ');

2.多行记录的录入insert into数据表

(select from数据表where条件)insert into scott.emp(empno,ename,hiredate)

(selectempno+100,ename,hiredatefrom scott.empwhere empon>=6999);

--表间数据复制createtable语句的功能就是创立新的数据表createtable scott.testas

(select distinct empno,ename,hiredatefrom scott.empwhereempno>=7000

);

--删除数据

使用[delete]命令能够删除数据,数据将存储在系统回滚段中,需要的时候能够回滚恢复;使用[truncate]命令能够删除整表数据但保留结构,数据不可恢复.

资料内容仅供您学习参考如有不当或者侵权请联系改正或者删除。deletefrom数据表where条件deletefrom scott.testwhere empno>=7500 and empno<=8000;truncate table scott.test;

--更新数据

[update]:update数据表set字段名1=新的赋值,字段名2=新的赋值where条件update scott.empset empno=8888,ename='TOM',hiredate='03-9月- 'whereempno=7566;update scott.empset sal=

(select sal+300 from scott.empwhereempno=7599

)whereempno=7599

Hostodo商家提供两年大流量美国VPS主机 可选拉斯维加斯和迈阿密

Hostodo商家算是一个比较小众且运营比较久的服务商,而且还是率先硬盘更换成NVMe阵列的,目前有提供拉斯维加斯和迈阿密两个机房。看到商家这两年的促销套餐方案变化还是比较大的,每个月一般有这么两次的促销方案推送,可见商家也在想着提高一些客户量。毕竟即便再老的服务商,你不走出来让大家知道,迟早会落寞。目前,Hostodo有提供两款大流量的VPS主机促销,机房可选拉斯维加斯和迈阿密两个数据中心,且都...

数脉科技:香港服务器低至350元/月;阿里云CN2+BGP线路,带宽10M30M50M100M

数脉科技(shuhost)8月促销:香港独立服务器,自营BGP、CN2+BGP、阿里云线路,新客立减400港币/月,老用户按照优惠码减免!香港服务器带宽可选10Mbps、30Mbps、50Mbps、100Mbps带宽,支持中文本Windows、Linux等系统。数脉香港特价阿里云10MbpsCN2,e3-1230v2,16G内存,1T HDD 或 240G SSD,10Mbps带宽,IPv41个,...

香港、美国、日本、韩国、新加坡、越南、泰国、加拿大、英国、德国、法国等VPS,全球独立服务器99元起步 湘南科技

全球独立服务器、站群多IP服务器、VPS(哪个国家都有),香港、美国、日本、韩国、新加坡、越南、泰国、加拿大、英国、德国、法国等等99元起步,湘南科技郴州市湘南科技有限公司官方网址:www.xiangnankeji.cn产品内容:全球独立服务器、站群多IP服务器、VPS(哪个国家都有),香港、美国、日本、韩国、新加坡、越南、泰国、加拿大、英国、德国、法国等等99元起步,湘南科技VPS价格表:独立服...

oracle数据库学习为你推荐
vc组合维生素C和维生素E混合胶囊有用吗,还是分开的好?地图应用看卫星地图哪个手机软件最好。haokandianyingwang谁给个好看的电影网站看看。杨丽晓博客明星的最新博文ww.66bobo.com这个www.中国应急救援网.com查询证件是真是假?baqizi.cc讲讲曾子杀猪的主要内容!dadi.tvApple TV是干嘛的?怎么用?多少钱?梦遗姐我姐姐很漂亮,她24了,我才15,晚上我和他睡在一起,我经常挨遗精,咋办?222cc.com求都市后宫小说、越多越好夏琦薇赞夏琦薇的人有多少?
主机租赁 什么是域名 万网域名代理 怎么申请域名 新网域名管理 联通c套餐 服务器评测 外国服务器 512au 申请空间 好看qq空间 godaddy域名证书 hostker 国外代理服务器软件 搜索引擎提交入口 环聊 石家庄服务器托管 新加坡空间 中国linux 金主 更多