首页 > 编程知识 正文

oracle数据库模糊查询,oracle模糊查询sql语句

时间:2023-05-04 04:26:32 阅读:22482 作者:4410

链接https://www.bilibili.com/video/bv12 b 411 k7zu? p=31条件查询语法SELECT查询列表FROM表名WHERE筛选条件; 用分类条件式过滤简单的条件运算符:=,=,=,=

例如,“查询工资为12000的员工信息”

select * fromemployeeswheresalary 12000还表示“咨询部门编号与90号不同的员工姓名和部门编号”

SELECTlast_name,department _ idfromemployeeswheredepartment _ id90; 按逻辑表达式筛选逻辑运算符:||、and、or、not、用于连接表达式

例如,“查询工资在10000到20000之间的员工姓名、工资、奖金”

SELECTlast_name、salary、commission _ pctfromemployeeswheresalary=10000 and salary=20000,或者“查询部门编号不是90到110之间,或者工资

select * fromemployeeswheredepartment _ id90 or department _ id 110 orsalary 15000; 模糊搜索like、between and、in和is null

like特点:一般与通配符搭配使用。

通配符:

%:0个字符_ :包含任意一个字符的任意多个字符

例如,“查询员工姓名中包含字符a的员工信息”select * fromemployeeswherelast _ name like“% a %”; 另外,“查询员工姓名的第3个字是e,第5个字是a的员工姓名和工资”

SELECTlast_name,salaryfromemployeeswherelast _ name like ' _ e _ a % '; 例如,"查询员工姓名中第二个字符为_的员工姓名"

许多语言都可以使用通用转义字符“”。

select last _ namefromemployeeswherelast _ name like ' _ _ % '; 也可以使用MySQL escape将任何字符声明为转义字符。

select last _ namefromemployeeswherelast _ name like ' _ $ _ % ' escape ' $ '; between and可以提高语句的简洁度。 请勿调换包含阈值的两个阈值的顺序,例如“查询员工编号为100~120的员工信息”

select * fromemployeeswhereemployee _ id between 100 and 120; 确定in字段的值是否属于in列表中的项目

提高语句简洁度的in列表的值类型必须匹配。 此外,兼容的输入列表值不支持通配符。 例如,“为员工查询的工作编号是IT_PROG、AD_VP、AD_PRES的员工姓名和工作编号”

SELECTlast_name,job _ idfromemployeeswherejob _ idin (' it _ prot ',' AD_VP ',' AD_PRES ' ); 不能用于确定is null=或null值is null或is not null。 例如,null值可以确定为“调查无奖励的员工姓名和奖励率”

SELECTlast_name,commission _ pctfromemployeeswherecommission _ pct is null;

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。