我需要SELECT
column1
没有前导0
的所有行。 column1
的数据类型为String
。
column1
0123455677
0987654321
2345567887
0233445566
3422245666
答案 0 :(得分:7)
ANSI SQL回答:
select * from tablename
where substring(column1 from 1 for 1) <> '0'
某些dbms产品改为SUBSTR(column1, 1, 1)
,或LEFT(column1, 1)
。
答案 1 :(得分:0)
我认为你在谈论一个字符字段,因为数字字段不会显示前导0,除非你格式化...无论如何
对于你要选择的字符字段......
WHERE column1 NOT LIKE '0%'
如果是数字字段,您可以选择...
WHERE column1 >= 1000000000
答案 2 :(得分:0)
有多种方法可以实现这一目标。这里有三个用于oracle dbms的例子(我不知道你的dbms)。
-- using substr
select * from
(select '0123' t from dual union
select '123' t from dual union
select '5123' t from dual union
select '413123' t from dual union
select '0454' t from dual) tab
where substr(tab.t,0,1) != 0;
-- using regex
select * from
(select '0123' t from dual union
select '123' t from dual union
select '5123' t from dual union
select '413123' t from dual union
select '0454' t from dual) tab
where regexp_like(tab.t,'^[^0]');
-- using the like operator
select * from
(select '0123' t from dual union
select '123' t from dual union
select '5123' t from dual union
select '413123' t from dual union
select '0454' t from dual) tab
where tab.t not like '0%';
答案 3 :(得分:0)
问题已得到解答,但您也可以尝试
SELECT LEFT(column1, 1) AS firstLetter
FROM <table>
WHERE colum1 => 1
它与字符串完美配合。
答案 4 :(得分:-1)
你需要检查第一个字符是否为零。使用SUBSTR
。
SELECT COLUMN FROM TABLE WHERE SUBSTR(COLUMN,1,1) <> '0';