sql - Fetch error list with integer to binary conversion -


i have table_of_errors id's 2^n values:

id,value ----------------- 1,'error 1' 2,'error 2' 4,'error 3' 8,'error 4' 

etc... in other table let's call products, each row have error code sum of errors table_of_errors:

prod_id,erors_code -------------------- prod1, 2 prod2, 5 prod3, 12 

what need join converts afrificial one_to_many relation :

prod1,'error 2' prod2,'error 1' prod2,'error 3' prod3,'error 3' prod3,'error 4' 

can please suggest hint? have no idea how start...

regards
pawel

you can use bitand():

select p.*, toe.value products p left join      table_of_errors toe      on bitand(p.errorscode, toe.id) > 0; 

i recommend change data structure. bit-packing may make sense in computer languages, not particularly useful oracle. there many other facilities, such junction tables, nested tables, , json fields more appropriate type of data structure.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -