Oracle DML 基础查询

/*
Message={"Author":"lucheng","Date":"2017.12.6",Host:"localhost","Database":"scott","Password":"tiger"}
*/
/*连接scott用户*/
conn scott/tiger;
/*设置每行记录显示的长度*/
set linesize 120;
/*设置每页显示的记录数*/
set pagesize 20;
/*查询scott中的表*/
select * from tab;
/*查看表结构*/
desc dept;
desc emp;
desc bonus;
desc salgrade;
/*查询scott中表的全部记录 *:意为所有 */
select * from dept;
select * from emp;
select * from bonus;
select * from salgrade;
select deptno,dname,loc from dept;
select empno,ename,job,mgr,hiredate,sal,comm,deptno from emp;
select ename,job,sal,comm from bonus;
select grade,losal,hisal from salgrade;
/*消除查询到的数据中的重复内容*/
select job from emp;
select distinct job from emp;
/*定义别名: as <别名>*/
select empno,ename,sal*12 as saltotal from emp;
/*
关系运行符:=、>、<、>=、<=、<>(!=)
逻辑运算符:and、or、not
范围运算符:between...and...
谓词范围:in、not in
空判断:is null、is not null
模糊查询:like
限定查询: select [distinct] <列名称>[,<列名称>]... from <表名称> [[as] <别名>] [where <过滤条件>]
*/
/*查询KING雇员的信息*/
select *  from emp where ename ='KING';
/*查询基本工资大于1000的雇员信息*/
select * from emp where sal > 1000;
/*查询基本工资在1000~1500之间的雇员信息*/
select * from emp where sal >= 1000 and sal <=1500;
--只判断一个条件,性能有一定的提升
select * from emp where sal between 1000 and 1500;
/*查询基本工资在小于1000或大于1500之间的雇员信息*/
select * from emp where sal < 1000 or sal >1500;
--只判断一个条件,性能有一定的提升
select * from emp where sal not between 100 and 1500;
/*
查询所有在1981年雇佣的雇员
1981-01-01 :'01-1月 -81'
1981-12-31 :'31-12月 -81'
*/
select * from emp where hiredate between '01-1月 -81' and '31-12月 -81';
/*
空(null)在数据库中解释为不确定的内容,在数字列中使用不代表0
	--查询所有领取佣金的雇员信息
	--查询所有不领取佣金的雇员信息
*/
select * from emp where comm is not null;
select * from emp where comm is null;
/*
--查询雇员编号为7369或7566或7900的雇员信息
--查询雇员编号不为7369和7566和7900的雇员信息
*/
select * from emp where empno in (7369,7566,7900);
select * from emp where empno not in (7369,7566,7900);
--null对in操作没有影响
select * from emp where empno in (7369,7566,7900,null);
--null对not in具有影响,不会查到任何记录
select * from emp where empno not in (7369,7566,7900,null);
/*
模糊查询通配符
“_”:匹配任意字符
“%”:匹配任意多(0~n)个字符
*/
--查询雇员姓名第三个字是“L”的雇员信息
select * from emp where ename like '__L%';
--查询雇员姓名中包含是“LL”的雇员信息
select * from emp where ename like '%L%';
/*
	针对于指定的列内容实现排序:order by <列名称>[,<列名称>]... [asc | desc] [<,列名称>[,<列名称>]... [asc | desc]]...
	asc(默认):按照升序的方式排序
	
	优先级:from子句 > where子句 > select子句 > order by子句
*/
--查询先按部门名称升序,后按基本工资降序的数据表
select * from emp order by deptno asc,sal desc;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值