如何在Oracle SQL中比较十六进制值

时间:2018-12-13 21:54:38

标签: sql oracle

我有一列具有HEXADECIMAL值的列,我想与其他HEXADECIMAL值进行比较,如下所示,但结果不准确

SELECT vc_vin_vis_start_range FROM ok_dc.gms3_vc_mme_vin_si_detail
   WHERE TO_NUMBER(vc_vin_vis_start_range) >= TO_NUMBER('100001');

有没有一种方法可以比较查询中的两个十六进制值。

感谢您的帮助!

2 个答案:

答案 0 :(得分:2)

使用TO_NUMBER( hex_value, , 'xxxxxxxxxx' )(其中x的数量是十六进制VARCHAR2列的最大长度):

Oracle设置

CREATE TABLE ok_dc.gms3_vc_mme_vin_si_detail ( vc_vin_vis_start_range ) AS
  SELECT '1'      FROM DUAL UNION ALL
  SELECT 'FFFFF'  FROM DUAL UNION ALL
  SELECT '100001' FROM DUAL UNION ALL
  SELECT '100002' FROM DUAL UNION ALL
  SELECT NULL     FROM DUAL;

查询

SELECT vc_vin_vis_start_range
FROM ok_dc.gms3_vc_mme_vin_si_detail
WHERE TO_NUMBER(vc_vin_vis_start_range, 'xxxxxxxxxx') >= TO_NUMBER('100001', 'xxxxxxxxxx');

输出

VC_VIN_VIS_START_RANGE
----------------------
100001
100002

答案 1 :(得分:1)

假设列<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.min.js"></script> <div class="container"> <br /> <div class="row"> <div class="col-md-1"></div> <div class="col-md-10"> <!-- Chart.js Canvas Tag --> <canvas id="lineChart"></canvas> </div> <div class="col-md-1"></div> </div> </div>没有空值,那么我会这样做:

library(tidyverse)

df %>% rowwise() %>%  
  mutate(Combined = paste0(min(CallNo, DupCallNo, na.rm = TRUE), max(CallNo,DupCallNo, na.rm = TRUE))) 

# A tibble: 4 x 5
# Groups:   Combined [2]
  CallNo DupCallNo Priority Unit    Combined
   <int>     <int> <fct>    <fct>   <chr>   
1    123       255 A        Bravo12 123255  
2    255       123 A        Bravo44 123255  
3    366       476 B        Xray22  366476  
4    476       366 A        Xray109 366476 

vc_vin_vis_start_range函数根据要转换的每个值构建一个十六进制格式。