Laravel中所有这些SQL运算符是什么? [英] What are all those SQL operators in Laravel?

查看:69
本文介绍了Laravel中所有这些SQL运算符是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看Laravel的源代码,并且发现了很多用于Eloquent的SQL运算符,我想知道它们中的一些以及如何使用它们.

I was looking through Laravel's source code and I've found a lot of SQL operators for Eloquent and I was wondering what are some of them and how can they be used.

很遗憾,我没有找到任何文档.

I haven't managed to find any documentation unfortunately.

这是我在vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php中找到的运算符:

Here's the operators I've found in vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:

protected $operators = [
    '=', '<', '>', '<=', '>=', '<>', '!=',
    'like', 'like binary', 'not like', 'between', 'ilike',
    '&', '|', '^', '<<', '>>',
    'rlike', 'regexp', 'not regexp',
    '~', '~*', '!~', '!~*', 'similar to',
    'not similar to',
];

有一堆我不明白的东西.例如:&|^<<>>~~*!~!~*.

And there's a bunch of them I don't understand. For example: &, |, ^, <<, >>, ~, ~*, !~, !~*.

任何人都可以向我展示如何使用它们的示例吗?

Can anyone show me an example of how they can be used?

谢谢

推荐答案

就像其他评论者所提到的那样,它们是按位运算符. PHP的按位运算符记录在这里: http://php.net/manual/en/language.operators.bitwise .php

Just like other commenters have mentioned, those are bitwise operators. PHP's bitwise operators are documented here: http://php.net/manual/en/language.operators.bitwise.php

示例

&按位AND 运算符.

按位与运算符采用两个等长的二进制表示形式,并且 对每对对应的对象执行逻辑与"运算 位乘以它们.因此,如果两个位都在比较位置 为1,结果二进制表示中的位为1(1×1 = 1);否则,结果为0(1×0 = 0和0×0 = 0)

A bitwise AND takes two equal-length binary representations and performs the logical AND operation on each pair of the corresponding bits, by multiplying them. Thus, if both bits in the compared position are 1, the bit in the resulting binary representation is 1 (1 × 1 = 1); otherwise, the result is 0 (1 × 0 = 0 and 0 × 0 = 0)

10& 10 = 10(所有十进制表示形式).如何? 10是1010二进制.

10 & 10 = 10 (all decimal representation). How? 10 is 1010 binary.

    1010
and 1010
--------
    1010

请注意,仅当同一列中的最高和最低数字均为1时,结果才为1.

Notice that the result is 1 only when both top and bottom number in the same column are 1.

PHP的编写方式:

<?php
echo 10 & 10;
?>
Result: 10

它的实际用途是什么?让我们举个例子:有4套双门.两个门必须同时打开,一个人才能通过.打开的门被赋予数字1.关闭的门被赋予数字2.

What's the practical use for it? Let's take an example: There are 4 sets of double doors. Both doors have to open at the same time for a person to pass through. Open door is given number 1. Closed door is given number 2.

1010表示第一扇门是打开的,第二扇门是关闭的,第三扇门是打开的,第四扇门是关闭的.当所有门都关闭时,它们看起来像这样:

1010 means first door is open, second is closed, third is open, fourth is closed. When all doors are closed, they would look like this:

0000  <-- first set of doors
0000  <-- second set of doors

要允许某人穿过最左边的门,门应该是这样的:

To allow someone to pass through left-most door, doors should be like this:

0001
0001

一切都很好,但是有一种更快的方法来对此进行注释.按位运算符&.我们做在两个门之间,结果为1.因此,如果将数据存储为1,我们知道最左边的门是打开的.

That's all fine, but there's a faster way to annotate that. Bitwise operator &. We do & between both doors and get a result of 1. So if data is stored as 1, we know that left-most doors were open.

要打开最左边的门,组合必须为:

To open left-most door, the combination would have to be:

1000
1000

按位运算符的结果为十进制8.使用计算器就像miniwebtool上的那个一样,可以运行一些数学运算.

Result of bitwise operator is decimal 8. Use calculator like the one on miniwebtool to run some math.

在另一面,当门全天打开和关闭时,可以记录4套门中的任何一个门都打开的时间.这只是对一个简单问题的漫长回答.

On the flip side, as the doors open and close all day, one could record when both doors of any of the 4 sets of doors were open. It's just a long-winded answer to perhaps a simple question.

这篇关于Laravel中所有这些SQL运算符是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆