I like to store data in o/1 format.
eg. I need to values from 5 columns in one column.
I've parameters p1...p5... and value could be either 0 or 1.
So eg. if I want to store p1=1, p2=0,p3=1,p4=1,p5=0 ....
and I want to store these values in one column like 10110.
What datatype shd I use ???
If I use number is there way to store this type of data.
03-21-2001, 05:53 PM
I haven't ever used bit maps in Oracle, but you can certainly use a number to store the bits. A "number" data type is actually a decimal integer, but the conversion beteen decimal and binary is simple. If their isn't a delivered function to test whether or not a bit is set, you could always write a PL/SQL function to test for it. Setting and clearing the bits are easy. Just set the variable to 0 (zero) to clear all bits, and set individual bits by adding the decimal equivalent to the current value. For example, val = 0 clears all bits; val = 1 sets bit 0; val = 2 sets bit 1; val = 4 set bit 2; val = 1 + 4 sets bit 0 and bit 2; etc. In your example, you would set the first, second and fourth bits, which is the same as setting val = 2^1 + 2^2 + 2^4 (or val = 2 + 4 + 16).
03-21-2001, 06:03 PM
I was looking at the bit stream without comparing it to your text. The least significant (zero) bit for binary numbers is typically at the right end, and are read right to left. So the binary number 10110 has bits 1, 2 and 4 set. To set p1, p3 and p4 you would set bits 0, 2 and 3 (or, 01101). Confusing, but that's what computers are for :-)