在Oracle数据库中设置一个数字的特定位

Moh*_*shi 2 sql oracle oracle10g

如何使用SQL命令在Oracle中设置数字的特定位?只有BITAND操作员

BITAND (DEPENDENCY_MAP, 2)
Run Code Online (Sandbox Code Playgroud)

在DEPENDENCY_MAP中,每个位都定义一个类型依赖项.使用此命令,我可以找到第二位是否已设置.但是如何修改此位?

Kla*_*äck 6

设置位:

UPDATE <table name>
   SET DEPENDENCY_MAP = DEPENDENCY_MAP + 2 -- Set the bit (the row must not have the bit set already)
 WHERE BITAND (DEPENDENCY_MAP, 2) = 0 -- This will match rows that don't have the bit set
   AND <add your own row filters>
Run Code Online (Sandbox Code Playgroud)

清除一下:

UPDATE <table name>
   SET DEPENDENCY_MAP = DEPENDENCY_MAP - 2 -- Clear the bit (the row must have the bit set already)
 WHERE BITAND (DEPENDENCY_MAP, 2) > 0 -- This will match rows that do have the bit set
   AND <add your own row filters>
Run Code Online (Sandbox Code Playgroud)

注意: 上面的代码适用于正数.我没有打算弄清楚如果DEPENDENCY_MAP是负数会发生什么,因为我假设你没有负数.