Restricting and Sorting Data
来源:互联网 发布:日本综艺节目软件app 编辑:程序博客网 时间:2024/06/05 04:47
一、符号补充
用于where比较条件的有:- 等于: =、<、<=、>、>=、<>
- 包含: in、not in、 exists、not exists
- 范围: between……and、not between……and
- 匹配测试: like、not like
- Null测试: is null、is not null
- 布尔链接: and、or、not
在where子句中,通配符可与like条件一起运用。在Oracle中:
- %(百分号): 用来表示任意数量的字符,或者可能根本没有字符。
- _(下划线): 表示确切的未知字符。
- ?(问号): 用来表示确切的未知字符。
- #(井号): 用来表示确切的阿拉伯数字,0到9.
- [a-d](方括号): 用来表示字符范围,在这里是从a到d.
二、模糊查询
- 我们可以在where子句中使用like关键字来达到Oracle模糊查询的效果;
- 在Where子句中,可以对datetime、char、varchar字段类型的列用Like关键字配合通配符来实现模糊查询
三、变量
如果不使用替换变量,每次操作我都都要修改脚本。非常不便,如果使用替换变量,我们可以将带变量的语句存放在sql脚本中,每次运行时,只需要输入替换变量的值就可以了。- &:&引用的替换变量只在当前SQL有效
- &&:&&引用的替换变量则在当前会话有效
- SET VERIFY:如果要显示SQL*Plus使用替换值替换后的脚本文件,可以使用SET VERIFY ON/OFF 命令
- SET DEFINE:在存储过程或包体里面,经常有在字符串中使用&的情况,执行脚本时,经常会将这些字符串视为替换变量,要求输入值,这样烦不甚烦,其实只需要设置一下SQL*PLUS的环境变量即可避免这种情况。通常通过SET DEFINE OFF
- DEFINE
- 使用DEFINE定义了的变量,可以使用&引用声明的变量。其作用范围或生命周期通常是整个会话。
- 如果定义了变量后,需要清除变量,则可以使用UNDEFINE清除变量
- 使用DEFINE VARIABLE来查看变量
四、where 语句整理
--数字比较(<):工资小于6000select last_name ,salaryfrom employeeswhere salary < 6000 ;--字符串比较(=):员工 名字,查询King 的工资select last_name ,salaryfrom employeeswhere last_name='King' ;--时间比较(=)--雇佣日期是 1998.07.01 的员工 名字, 工资--确定时间格式select sysdate from dual;22-oct-11--查询名字和工资select last_name , salaryfrom employeeswhere hire_date = '01-jul-98' ;--时间(between .. and ..):1998 年 2 月 入职的员工 名字和工资select last_name , salaryfrom employeeswhere hire_date between '01-2月-98' and '28-2月-98' ;--10----60 号部门员工--between .. and ..: select last_name , salary from employees where department_id between 10 and 60 ;--比较运算符:select last_name , salary from employees where department_id >= 10 and department_id <= 60; --in:10 , 30, 70 号部门员工 select last_name , salaryfrom employeeswhere department_id in ( 10,30,70 ) ;--模糊查询(_单个字符):--模糊查询(%多个字符,长度不固定)--last_name 中 第三个字符是 sselect last_name , salaryfrom employeeswhere last_name like '__s%' ;--last_name 中 倒数第三个字符是 sselect last_name , salaryfrom employeeswhere last_name like '%s__' ;--1998 年入职的员工 名字和工资--方法一:比较查询select last_name , salary from employees where hire_date between '01-1月-98' and '31-12月-98' ;--方法二:通配符方式select last_name , salaryfrom employeeswhere hire_date like '%98'; --2 月 入职的员工 名字和工资select last_name , hire_datefrom employeeswhere hire_date like '%-2月%'; --转译符,转译_select * from t1 where a like 's_%' ;select * from t1 where a like 's\_%' escape '\\';--转译*select * from t1 where a like 's*_%' escape '*';--null值处理:哪些员工 没有部门号select last_name , salaryfrom employeeswhere department_id is null ;--哪些员工 有部门号--方法一select last_name , salaryfrom employeeswhere department_id > 0 ;--方法二select last_name , salaryfrom employeeswhere department_id is not null order by 2 ;--and:--名字 S 开头,并且工资高于 8000 的员工select last_name , salaryfrom employeeswhere last_name like 'S%' and salary > 8000 ;--排序order byselect last_name , hire_datefrom employeesorder by 2 ;--verify:使用VERIFY 命令来显示的替代变量之前和之后SQL开发人员替换替换变量的值--&:用来提示用户输入一个数值:set verify onselect last_name from employeeswhere employee_id=&1;
阅读全文
0 0
- Restricting And Sorting Data
- Restricting and Sorting Data
- oracle学习笔记2-Restricting and sorting data
- 【Data Structures】 8. Sorting in Java—Comparable and Comparator
- Spring Data Rest学习篇----Paging and Sorting (分页和排序)
- 【Data Structures】 7. Simple Sorting—Bubble Sort, Selection Sort, and Insertion Sort
- spring.data.jpa.query :Cannot use native queries with dynamic sorting and/or pagination in method
- Sorting and Searching
- CListCtrl and sorting rows
- Shifting and Sorting Matrices
- Searching and Sorting
- Searching and Sorting
- Searching and Sorting
- Searching and Sorting
- 知识点总结2 External Sorting, Bucket Sorting, and Radix Sorting
- 基于Problem Solving with Algorithms and Data Structures using Python的学习记录(5)——Sorting
- ACM and STL-DNA Sorting
- <codeforces>Little Elephant and Sorting
- 马克较好用的各种网站
- java 遍历集合的同时添加和删除元素
- samtools及BCFtools常用参数和使用文档
- 网络连接对象能不能缓存?
- 分布式基础通信协议:paxos,totem和gossip
- Restricting and Sorting Data
- 最新网狐荣耀版整理、编译和搭建教程
- java高级工程师线路图
- Python 脚本:创建SFTP连接传输数据
- Selenium自动化测试:如何使用cookie跳过验证码登录
- 操作系统——相关面试考点
- zookeeper 6 : 服务端存储设计与实现
- class not found (php)明明命名空间和类目都存在却总是提示找不到的奇葩现象原因以及解决方案
- PathVariable