What does the pipe/veritcal bar character mean in TSQL? [duplicate]

谁说我不能喝 提交于 2019-11-27 07:55:55

问题


This question already has an answer here:

  • What does the pipe operator do in SQL? 4 answers

Google-fu is failing me on this one. Can anyone briefly explain what the following statement would do?:

UPDATE
    message WITH (ROWLOCK)
SET
    message = message | 2

I found this in a trigger, and I am unable to find docs explaining what the | character does in a statement like this.


回答1:


That is a bitwise OR

http://msdn.microsoft.com/en-us/library/ms176122.aspx




回答2:


It's the bitwise OR operator. See this article. Effectively, message is a bitfield, and by bitwise-ORing it with 2, you're setting the second bit. See Wikipedia's bitwise operation article for a good overview of bit-twiddling :)




回答3:


| is a bitwise OR in T-SQL:

http://msdn.microsoft.com/en-us/library/ms186714.aspx

So if message contained 0, it would contain 2, if it contained 1, it would contain 3, etc.



来源:https://stackoverflow.com/questions/4993532/what-does-the-pipe-veritcal-bar-character-mean-in-tsql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!