You are not logged in.

  • Login

1

Monday, January 26th 2009, 4:10pm

SQL Abfragen (Binärzahlen)

Hallo,
ich habe eine Oracle Datenbank und hab ein paar Probleme
1.)
was mein erstes Problem ist, eine Zahl in eine Binärzahl umzuwandeln, das heißt:
37 -> 100101

2.)
das zweite Problem was ich habe ist, ist das ich mehrere Zahlen habe, sie dann in Binäre Zahlen umwandle und damit Fehler-Abfragen mache. Ich zeig mal ein Beispiel so kann ich es denk ich besser erklären.

Source code

1
2
3
4
       F6   F5  F4   F3   F2  Fehler1
37 -> 1    0    0    1    0    1
5  -> 0    0    0    1    0    1
22 -> 0    1    0    1    1    0



Überall wo eine 1 steht heißt Fehler.
Die Abfrage soll so aussehen z.B.:
Zeige mir die Zahl, überall wo an der 3 und 1 Stelle ein Fehler ist an (als Decimal).
Das heisst bei unserem Beispiel, die 37 und 5.

Ich weiss nicht wie ich anfgangen soll, könnte mir jemand beim Code helfen?

Danke im voraus

2

Monday, January 26th 2009, 4:23pm

Bzgl. #2: In einfachstem SQL sähe das so aus...

SQL Code

1
SELECT `feld` FROM `table` WHERE `f3` = '1' AND `f1` = '1'


Bzgl. #1: Ich nehme an, du greifst mittels irgendeiner Programmiersprache auf die Datenbank zu, die du verwenden kannst, um eine Zahl in einen Binärcode umzuwandeln. Oder soll diese Umwandlung per SQL erfolgen? In PHP ginge das z.B. mit decbin().

3

Monday, January 26th 2009, 6:06pm

kannst du 1 und 2 vielleicht zusammen lösen indem du den SQL Datentyp SET verwendest?

http://dev.mysql.com/tech-resources/arti…t-datatype.html

Quoted

The SET datatype is a string type, but is often referred to as a complex type due to the increased complexity involved in implementing them. A SET datatype can hold any number of strings from a predefined list of strings specified during table creation. The SET datatype is similar to the ENUM datatype in that they both work with predefined sets of strings, but where the ENUM datatype restricts you to a single member of the set of predefined strings, the SET datatype allows you to store any of the values together, from none to all of them.[...]

Similar threads

Social bookmarks