Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » Oracle »

Operation between hexadecimal data Oracle

Estas en el tema de Operation between hexadecimal data Oracle en el foro de Oracle en Foros del Web. 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, ...
  #1 (permalink)  
Antiguo 22/04/2014, 11:31
 
Fecha de Ingreso: octubre-2011
Ubicación: Merlo
Mensajes: 18
Antigüedad: 12 años, 5 meses
Puntos: 1
Operation between hexadecimal data Oracle

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):
Código:
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:
Código:
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;
And I saw:
Código:
SALIDA
Q
Q
Q
Q
OK
Q
Q
Q
Q
Q
Q
Q
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


here the script wirt create table and inserts sentences:
Código:
CREATE TABLE A_5MIN_TST1
(
  UTCTIME      DATE                             NOT NULL,
  POINTNUMBER  INTEGER                          NOT NULL,
  SITEID       INTEGER,
  VALOR_INST   FLOAT(126),
  TLQ_INST     INTEGER,
  VALOR_PROM   FLOAT(126),
  TLQ_PROM     INTEGER,
  VALOR_MAX    FLOAT(126),
  TLQ_MAX      INTEGER,
  UTCTIME_MAX  DATE,
  VALOR_MIN    FLOAT(126),
  TLQ_MIN      INTEGER,
  UTCTIME_MIN  DATE
)
TABLESPACE USERS
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           )
LOGGING 
NOCOMPRESS 
NOCACHE
NOPARALLEL
MONITORING;


ALTER TABLE A_5MIN_TST1 ADD (
  PRIMARY KEY
 (UTCTIME, POINTNUMBER)
    USING INDEX 
    TABLESPACE USERS
    PCTFREE    10
    INITRANS   2
    MAXTRANS   255
    STORAGE    (
                INITIAL          64K
                MINEXTENTS       1
                MAXEXTENTS       UNLIMITED
                PCTINCREASE      0
               ));


SET DEFINE OFF;
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:05:00', 'MM/DD/YYYY HH24:MI:SS'), 32);
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:10:00', 'MM/DD/YYYY HH24:MI:SS'), 128);
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:15:00', 'MM/DD/YYYY HH24:MI:SS'), 8);
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:20:00', 'MM/DD/YYYY HH24:MI:SS'), 32);
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:25:00', 'MM/DD/YYYY HH24:MI:SS'), 1);
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:30:00', 'MM/DD/YYYY HH24:MI:SS'), 10);
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:35:00', 'MM/DD/YYYY HH24:MI:SS'), 100);
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:40:00', 'MM/DD/YYYY HH24:MI:SS'), 1000);
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:45:00', 'MM/DD/YYYY HH24:MI:SS'), 2000);
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:50:00', 'MM/DD/YYYY HH24:MI:SS'), 3000);
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:55:00', 'MM/DD/YYYY HH24:MI:SS'), 4000);
COMMIT;

Última edición por carlino70; 22/04/2014 a las 11:36 Razón: script create table and inserts
  #2 (permalink)  
Antiguo 22/04/2014, 11:52
Avatar de gnzsoloyo
Moderador criollo
 
Fecha de Ingreso: noviembre-2007
Ubicación: Actualmente en Buenos Aires (el enemigo ancestral)
Mensajes: 23.324
Antigüedad: 16 años, 4 meses
Puntos: 2658
Respuesta: Operation between hexadecimal data Oracle

@carlino70: Foros del Web es un foro en español (castellano, para nosotros), y según las propias PDU del sitio, los posts deben escribirse preferentemente en neustro idioma.
Por favor, edita y traduce lo que has puesto.
__________________
¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...
"El problema es la interfase silla-teclado." (Gillermo Luque)
  #3 (permalink)  
Antiguo 22/04/2014, 12:06
 
Fecha de Ingreso: octubre-2011
Ubicación: Merlo
Mensajes: 18
Antigüedad: 12 años, 5 meses
Puntos: 1
Respuesta: Operation between hexadecimal data Oracle

Gracias gnzsoloyo, he tratado de editarlo, y no encuentro la opción

Podrás guiarme por favor?

Muchas gracias

Carlinodba
  #4 (permalink)  
Antiguo 22/04/2014, 12:09
Avatar de gnzsoloyo
Moderador criollo
 
Fecha de Ingreso: noviembre-2007
Ubicación: Actualmente en Buenos Aires (el enemigo ancestral)
Mensajes: 23.324
Antigüedad: 16 años, 4 meses
Puntos: 2658
Respuesta: Operation between hexadecimal data Oracle

SI al lado del botón "CITAR", no te aparece "Editar", es porque no tienes aún suficientes mensajes en tu haber para hacerlo.
Reglas de uso de FDW.

Si puedes ver el de "Citar", usa ese, y al editarlo quita los QUOTE dejando el post incial.
__________________
¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...
"El problema es la interfase silla-teclado." (Gillermo Luque)
  #5 (permalink)  
Antiguo 22/04/2014, 12:30
 
Fecha de Ingreso: octubre-2011
Ubicación: Merlo
Mensajes: 18
Antigüedad: 12 años, 5 meses
Puntos: 1
Operacion lógica con valores hexadecimales - BITAND

Hola expertos, necesito por favor resolver la siguiente situacion:

Tengo 12 registros desde una tabla llamada A_5MIN_TST1 (estos datos serán comparados con una mascara en hexa, pero aqui utilizo decimales)
Código:
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
Haciendo un select debo analizar cada bit del valor obtenido de la columna tlq_inst, y decidir:

si algun valor de tlq_inst es:
= 8
ó
= 32
ó
= 128
entonces debo anotar = 8

cuando ningun registro es 8, 32, 128 entonces debo seleccionar el primer valor de tlq_inst (primero segun utctime)

He intentado con este query, pero con resultados aún no correctos:
Código:
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;
note: 168 es la suma de 8+32+128 y lo uso como mascara
note: 'Q' sería lo deseado reemplazandolo el 8 decimal
Entonces veo:
Código:
SALIDA
Q
Q
Q
Q
OK
Q
Q
Q
Q
Q
Q
Q
En resumen, desde estos 12 valores, necesito hacer:
-Obtener 'Q' (8) si la comparacion logica con la mascara encuentra los bits con valor 8, 32, 128 en algun valor de tlq_inst

-Obtener el primer valor de tlq_inst, cuando la comparacion logica con la mascara no detecta los bits con valor 8, 32,128

-Si es posible realizar esto dentro del 'where'

-Obtener un único valor. Según mi consulta me devuelve 12 valores, uno por cada valor de tlq_inst

Podrán ayudarme a encontrar una solución

Gracias por adelantado

Saludos cordiales


Aqui, copio las sentencias de creacion de la tabla y los inserts:
Código:
CREATE TABLE A_5MIN_TST1
(
  UTCTIME      DATE                             NOT NULL,
  POINTNUMBER  INTEGER                          NOT NULL,
  SITEID       INTEGER,
  VALOR_INST   FLOAT(126),
  TLQ_INST     INTEGER,
  VALOR_PROM   FLOAT(126),
  TLQ_PROM     INTEGER,
  VALOR_MAX    FLOAT(126),
  TLQ_MAX      INTEGER,
  UTCTIME_MAX  DATE,
  VALOR_MIN    FLOAT(126),
  TLQ_MIN      INTEGER,
  UTCTIME_MIN  DATE
)
TABLESPACE USERS
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           )
LOGGING 
NOCOMPRESS 
NOCACHE
NOPARALLEL
MONITORING;


ALTER TABLE A_5MIN_TST1 ADD (
  PRIMARY KEY
 (UTCTIME, POINTNUMBER)
    USING INDEX 
    TABLESPACE USERS
    PCTFREE    10
    INITRANS   2
    MAXTRANS   255
    STORAGE    (
                INITIAL          64K
                MINEXTENTS       1
                MAXEXTENTS       UNLIMITED
                PCTINCREASE      0
               ));


SET DEFINE OFF;
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:05:00', 'MM/DD/YYYY HH24:MI:SS'), 32);
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:10:00', 'MM/DD/YYYY HH24:MI:SS'), 128);
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:15:00', 'MM/DD/YYYY HH24:MI:SS'), 8);
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:20:00', 'MM/DD/YYYY HH24:MI:SS'), 32);
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:25:00', 'MM/DD/YYYY HH24:MI:SS'), 1);
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:30:00', 'MM/DD/YYYY HH24:MI:SS'), 10);
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:35:00', 'MM/DD/YYYY HH24:MI:SS'), 100);
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:40:00', 'MM/DD/YYYY HH24:MI:SS'), 1000);
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:45:00', 'MM/DD/YYYY HH24:MI:SS'), 2000);
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:50:00', 'MM/DD/YYYY HH24:MI:SS'), 3000);
Insert into A_5MIN_TST1
   (UTCTIME, TLQ_INST)
 Values
   (TO_DATE('08/01/2013 01:55:00', 'MM/DD/YYYY HH24:MI:SS'), 4000);
COMMIT;

Etiquetas: sql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:30.