首页 > Linux操作系统 > Linux操作系统 > 007_02(约束和排序数据)
select ename,sal from emp where ename='SCOTT';
select ename,sal from emp where deptno=10 or deptno=30;
select ename,sal from emp where sal between 1300 and 3000;
alter session set nls_date_format='yyyy-mm-dd';
regedit ---> HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraDb10g_home1
中添加一个字符串 : nls_data_format -->值为 'yyyy-mm-dd' (值可以任意设置)
目标
完成本科,可以:
1.用一个查询限制返回的行
2.用一个查询分类返回的行
限制选择的行:
用 where 子句限制返回的行:
where 子句由三个元素组成:
1.列名;
2.比较条件;
3.列名、常量或值列表
select * from emp where deptno=30;
字符串和日期:
字符串和日期的值放在单引号中(在 where 子句中字符串和日期必须包含在单引号中,数字常数不应该包含在单引号中)
字符值区分大小写,日期值是格式敏感的
日期的默认格式是 DD-MON-RR.
(Oracle数据库以内部数字格式存储日期,表示为:世纪、年、月、日、小时、分、和秒)
比较条件:
比较条件被用于一个表达式与一个值或另一个表达式的比较。
运算 含义
= 等于
> 大于
>= 大于等于
< 小于
<= 小于等于
<> 不等于
select ename,sal from emp where sal <=3000;
其他比较条件:
操作 含义
between..(最小值)..and..(最大值).. 在两个值之间(包含)
in(set) 匹配一个任意值列表
like 匹配一个字符模版
is null 是一个空值
使用 between 条件显示上下限之间的行: select ename,sal from emp where sal between 300 and 3000;
使用 in 条件: select ename,sal from emp where ename in ('SMITH','CLARK');
(使用 in 并没有得到性能的提高,只是逻辑上简单.等价与 ename='SHITH' or ename='CLARK')
使用 like 条件执行搜索串值: select ename from emp where ename like '_L%';
select ename,sal from emp where sal like '%3%';
select ename,sal from emp where sal like '%3\_%' escape '\';
( _ 表示任意一个(单个)字符; % 表示零个或多个字符(文字或数字); escape 转义字符)
使用 null 条件测试空值: select ename,comm from emp where comm is null;
(null不能参与运算,分为: is null 和 is not null)
逻辑条件:
逻辑条件组合两个比较条件的结果来产生一个基于这些条件的单个的结果,当所有条件的结果为真时,返回行。
运算 含义
and 如果两个组成部分的条件都为真,返回ture
or 如果两个组陈各部分中的任一个条件为真,返回ture
not 如果跟随的条件为假
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/21021875/viewspace-621695/ ,如需转载,请注明出处,否则将追究法律责任。