0

I have a Oracle connection string with SQL Statement:

OracleCommand cmd = new OracleCommand("SELECT * FROM Database WHERE IPADDRESS='10.00.000.000' ORDER BY DATETIME ASC", con);

After loading all data in a dataset I check the bit of the row "RAWOUTPUT1" and write it in the correct column:

int bit = Convert.ToInt32(dr[22]);

dr[24] = (bit & (1 << 0)) != 0;
dr[25] = (bit & (1 << 1)) != 0;
dr[26] = (bit & (1 << 2)) != 0;
dr[27] = (bit & (1 << 3)) != 0;
dr[28] = (bit & (1 << 4)) != 0;
dr[29] = (bit & (1 << 5)) != 0;
dr[30] = (bit & (1 << 6)) != 0;
dr[31] = (bit & (1 << 7)) != 0;
dr[32] = (bit & (1 << 8)) != 0;
dr[33] = (bit & (1 << 9)) != 0;

My problem now is that the data is too big and I get a memory exception. So my idea is to load only the data from the database that I need, something like this:

OracleCommand cmd = new OracleCommand("SELECT * FROM Database WHERE IPADDRESS='10.00.000.000' 
AND IF((RAWOUTPUT1 & (1 << 0)) != 0) //here I need help, example for check bit
ORDER BY DATETIME ASC", con);

Thanks for the help!

3 Answers 3

2

Try to use the oracle function BITAND https://docs.oracle.com/cd/B28359_01/server.111/b28286/functions014.htm#SQLRF00612

Sign up to request clarification or add additional context in comments.

Comments

1

What are you looking for? All records, where at least one bit is set in RAWOUTPUT1?

AND RAWOUTPUT1 <> 0

Or all records where all given 10 bits are set?

AND RAWOUTPUT1 = 1023

Or where at least one of the ten bits is set?

AND BITAND(RAWOUTPUT1, 1023) > 0

EDIT: If you are looking for a certain bit, then bitand with the according power of two:

AND BITAND( RAWOUTPUT1, POWER(2,:n-1) ) <> 0

3 Comments

I have to check which bit is set in Column "ROWOUTPUT1". Possible is e.g. 0001 - 1111. So I have to check if bit 1 is set (0001, 0011, 0111, 1111) and load only that data
This is AND BITAND(RAWOUTPUT1, 1) <> 0.
That's it! AND BITAND(RAWOUTPUT1, POWER(2,n-1) <> 0
1

I don't have much experience with Oracle database, but I think the IF condition cannot be used in that way in the WHERE clause. Filter your rows setting your condition as something like:

AND BITAND(RAWOUTPUT1, 1) <> 0

3 Comments

That is surprising. When was the bitshift operator added to Oracle SQL? It doesn't work in 11g.
@ThorstenKettner Sorry, you're right. Oracle supports bitshift in this way NumberA / power(2, NumberB). The line should be then AND BITAND(RAWOUTPUT1, POWER(2,n-1) <> 0
That's it! AND BITAND(RAWOUTPUT1, POWER(2,n-1) <> 0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.