Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Operation between hexadecimal data Oracle

Posted on 2014-04-22
9
Medium Priority
?
494 Views
Last Modified: 2014-04-30
HI experts, I need resolve the next situation:

I have the next twelve rows in a table A_5MIN_TST1 (the data to be compared are hexa, but Examples works with decimal values):
UTCTIME|TLQ_INST
01/08/2013 01:05:00 a.m.|32
01/08/2013 01:10:00 a.m.|128
01/08/2013 01:15:00 a.m.|8
01/08/2013 01:20:00 a.m.|32
01/08/2013 01:25:00 a.m.|1
01/08/2013 01:30:00 a.m.|10
01/08/2013 01:35:00 a.m.|100
01/08/2013 01:40:00 a.m.|1000
01/08/2013 01:45:00 a.m.|2000
01/08/2013 01:50:00 a.m.|3000
01/08/2013 01:55:00 a.m.|4000

Doing a select I must analyze each bit of the tlq_inst column (hexadecimal data) and to decide:
if some value of tlq_inst is
= 8
or
= 32
or
= 128
then write = 8
when tlq_inst doesn't is 8, 32, 128 then write the first value of tlq_inst, over the range.
I have tried with this query:
SELECT DECODE(POWER(2,BITAND(tlq_inst, 168)), 1, 'OK','Q') salida
FROM A_5MIN_TST1
WHERE utctime >= TO_DATE ('01/08/2013 01:00:01','dd/mm/yyyy hh24:mi:ss')
AND utctime < TO_DATE ('01/08/2013 02:00:00','dd/mm/yyyy hh24:mi:ss')
AND POINTNUMBER = 330062
;

Open in new window

And I saw:
SALIDA
Q
Q
Q
Q
OK
Q
Q
Q
Q
Q
Q
Q

Open in new window

Resuming, on these 12 values, I need to do:

Get 'Q' if the comparison condition with mask, is met.

Get the first value of tlq_inst, when the comparison with the mask, is NOT true.

If possible, do the same but inside where

With this query I managed to get 12 values, but I need to get only one.

Could you help me to resolve this problem?

Thanks all in advanced
Regards
0
Comment
Question by:carlino70
  • 5
  • 2
  • 2
9 Comments
 
LVL 15

Expert Comment

by:Ess Kay
ID: 40020776
do select TOP 1
0
 

Author Comment

by:carlino70
ID: 40020837
the sentence "select top" does not exist in Oracle.
0
 
LVL 15

Expert Comment

by:Ess Kay
ID: 40021019
sorry, forgot about that.

If you want just a first selected row you can:

select fname from MyTbl where rownum = 1
you can also use analytic functions to order and take the top x

select max(fname) over (rank() order by some_factor) from MyTbl
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
LVL 14

Expert Comment

by:Alexander Eßer [Alex140181]
ID: 40021364
With this query I managed to get 12 values, but I need to get only one.
So you're supposed to get just one row as result?! What exactly do you expect as result?!

@esskayb2d: Don't get me wrong + I really don't want to be too offensice, BUT please -if you do not exactly know what the asker wants AND obviously do not have or just have half knowledge about Oracle (RDBMS), please stick to your topics, where you are truly powerful (and I mean this since I viewed your profile + your answered threads)...
If you want just a first selected row you can:

select fname from MyTbl where rownum = 1

Yes, you'd get just one row. But within a table holding billions of rows, which row is returned??!! Without an "order by" (e.g.) this is totally undetermined!

you can also use analytic functions to order and take the top x

select max(fname) over (rank() order by some_factor) from MyTbl
Sorry, but this is far too vague ;-)
0
 

Author Comment

by:carlino70
ID: 40022359
"   WHERE utctime >= TO_DATE ('01/08/2013 01:00:01','dd/mm/yyyy hh24:mi:ss')
AND utctime < TO_DATE ('01/08/2013 02:00:00','dd/mm/yyyy hh24:mi:ss')  "

Open in new window


I have 12 rows.

If there is any value is in mask, then I must write :  'Q' (in hexa: 0000000000000008, in decimal: 8)

If any value doesn't is in mask, then I must write the first value of "tlq_inst"

Both cases, I need just 1 value

note: I'm using 'Q' and 'OK', just for testing
0
 
LVL 14

Accepted Solution

by:
Alexander Eßer [Alex140181] earned 2000 total points
ID: 40022496
I suppose you have to use analytic window functions for this, like:
select DECODE(POWER(2, BITAND(tlq_inst, 168)), 1, 'OK', 'Q') salida,
       case DECODE(POWER(2, BITAND(tlq_inst, 168)), 1, 'OK', 'Q')
        when
        'OK' then to_char(first_value(tlq_inst) ignore nulls over (partition by null order by null))
        else
        'Q'
       end testit,
       A_5MIN_TST1.*
  from A_5MIN_TST1
 where utctime >= TO_DATE('01/08/2013 01:00:00', 'dd/mm/yyyy hh24:mi:ss')
   and utctime < TO_DATE('01/08/2013 02:00:00', 'dd/mm/yyyy hh24:mi:ss');

Open in new window


Whereas you should adjust the "partition by" and "order by" within the window function to suit your needs/table specs...

As you might have seen, I also changed your "where utctime >= TO_DATE('01/08/2013 01:00:01', 'dd/mm/yyyy hh24:mi:ss')" to "where utctime >= TO_DATE('01/08/2013 01:00:00', 'dd/mm/yyyy hh24:mi:ss')": don't miss any data ;-)
0
 

Author Comment

by:carlino70
ID: 40022510
Good, I'll try this.

Thanks for the recomendation, I going put the time in correct way
0
 

Author Comment

by:carlino70
ID: 40032223
With a little change, the solution was:
select 
  case when max(bitand(tlq_inst, 168)) = 0 then 
    max(tlq_inst) keep (dense_rank first order by utctime)
  else
    8
  end as result
from a_5min_tst1
where utctime >= to_date ('01/08/2013 01:00:01','dd/mm/yyyy hh24:mi:ss')
and utctime < to_date ('01/08/2013 02:00:00','dd/mm/yyyy hh24:mi:ss')
and pointnumber = 330062;

Open in new window

Thanks  Alexander Eßer for your help, was very important.
Regards
0
 

Author Closing Comment

by:carlino70
ID: 40032225
Excellent!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question