mysql的位运算, 开关设计

关键词:位运算、开关设计

  1. -- mysql的位运算
  2. select 2 | power(2,3); -- 使某位为1
  3. select 10 & ~power(2,1); -- 使某位为0
  4. select 10 & power(2,3); -- 确定某位为1

 

效率对比

[SQL] update model_user_stt
set op_code = INSERT(op_code,8,1,'1');
受影响的行: 20071
时间: 0.791s

[SQL] update model_user_stt
set op_nums_day = op_nums_day | pow(2,3)

受影响的行: 20071
时间: 0.267s

mysql> SELECT BIN(12);
        -> '1100'

原文地址:https://www.cnblogs.com/lucky110100/p/4137622.html