gpt4 book ai didi

sql - SQL中的整数到位

转载 作者:行者123 更新时间:2023-12-04 20:46:36 25 4
gpt4 key购买 nike

我有一个 Integer字段,我需要把它分成 Bits to the SQL(Firebird) . Integer 字段的每个字节都应该是一个新字段。例如:

Integer field: 7 = 00000111

Bit 1 field1: 1
Bit 2 field2: 1
Bit 3 field3: 1
Bit 4 Field4: 0
Bit 5 Field5: 0
Bit 6 Field6: 0
Bit 7 Field7: 0
Bit 8 Field8: 0

有人知道如何在 Firebird 中做到这一点吗?

最佳答案

使用 BIN_AND 功能:

SELECT 
bin_and(field, 1) as bit1,
bin_and(field, 2) as bit2,
bin_and(field, 4) as bit3,
bin_and(field, 8) as bit4,
...
FROM T

关于sql - SQL中的整数到位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17089862/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com