首页 > SQL中||符号什么意思

SQL中||符号什么意思

select e1.ename from emp e1, emp e2
where e1.path like e2.path || '%'
and e2.ename = 'JONES'

这个查询语句中的||和那个‘%’是什么个意思呀。原来没看到还有这个写法。


MySQL 中 || 等同于 or。

MySQL 逻辑运算符中 and 优先级要高于 or,所以你上面的SQL 等同于下面:

select e1.ename from emp e1, emp e2
where e1.path like e2.path 
or ('%' and e2.ename = 'JONES')

括号中的 '%' 等价于字符串,转化为boolean为 false,所以括号中整体为false,所以 SQL 也等价于:

select e1.ename from emp e1, emp e2
where e1.path like e2.path 

由于没有更详细的问题描述,问题只能回答到这里


||为Oracle字符串连接符
Concatenation Operator

%为通配符,匹配一个或多个字符
通配符

此处where e1.path like e2.path || '%'就是要求e1为e2或者e2的子目录


or的意思,或的意思,无论是什么数据库,万变不离其宗的


用的是oracle数据库吧,||表示字符串连接,%表示通配符,综合起来表示e1.path以e2.path打头。

【热门文章】
【热门文章】