我有一个名为X的字段(Oracle中的列),其值为" a1b2c3"," abc"," 1ab"," 123& #34;," 156"
我写了一个sql查询,它只返回包含没有字母的纯数值的X;从上面的例子可以看出是123和156。
使用Oracle语法编写的查询:
select X from where REGEXP_LIKE(X, '^[[:digit:]]+$')
结果:
123, 156
此外,我需要编写一个查询来获取100到150之间的值。
我怎样才能在Oracle中编写这样的查询?如下所示:
select X from where REGEXP_LIKE(X, '^[[:digit:]]+$') between 100 and 150
答案 0 :(得分:2)
regexp_like()
is a condition,因此您无法将其与任何内容进行比较。您可以改为使用the regexp_substr()
function:
var count = 1;
grid.closest("div.ui-jqgrid-view").find("div.ui-jqgrid-hdiv table.ui-jqgrid-htable tr.ui-jqgrid-labels > th.ui-th-column > div.ui-jqgrid-sortable > button.btnfilter ")
.each(function () {
$('<button>').css({ height: '10px',background: 'url(img/filter.png) no-repeat',border: '0'
}).appendTo(this).button({
icons: {
primary: ""
},
text: false
}).click(function (e) {
var idPrefix = "jqgh_" + grid[0].id + "_",
thId = $(e.target).closest('div.ui-jqgrid-sortable')[0].id;
if (thId.substr(0, idPrefix.length) === idPrefix) {
if (count == 1) {
$('#gview_' + grid_id).find("div.ui-jqgrid-hdiv table.ui-jqgrid-htable tr.ui-search-toolbar").show();
count = 0;
}
else {
$('#gview_' + grid_id).find("div.ui-jqgrid-hdiv table.ui-jqgrid-htable tr.ui-search-toolbar").hide();
count = 1;
}
return false;
}
});
});
$('#gview_' + grid_id).find("div.ui-jqgrid-hdiv table.ui-jqgrid-htable tr.ui-search-toolbar").hide();
函数返回的值为null或一串数字,可以(隐式)转换为数字进行比较。
使用您的样本数据进行演示:
where regexp_substr(x, '^[[:digit:]]+$') between 100 and 150
答案 1 :(得分:0)
CREATE FUNCTION is_number (p_string IN VARCHAR2)
RETURN INT
IS
v_new_num NUMBER;
BEGIN
v_new_num := TO_NUMBER(p_string);
RETURN 1;
EXCEPTION
WHEN VALUE_ERROR THEN
RETURN 0;
END is_number;
然后在查询中使用它
select X from where is_number(X)=1 and TO_Number(X) between 100 and 150
答案 2 :(得分:0)
试试这个。
with tbl(X) as
(select 'a1b2c3' from dual union all select
'abc' from dual union all select
'123' from dual union all select
'156' from dual )
select * from (
select * from tbl where
REGEXP_LIKE(X, '^[[:digit:]]+$')
) t
where x between 100 and 150