admin管理员组文章数量:1401666
I have a SQLite table with a column num (data type: text)
1.100.00
2.3025.00
2.000.00
3.500.16
4.3124.00
I would like to remove the first period.
The column should then look like this:
1100.00
23025.00
2000.00
3500.16
43124.00
I tried with:
SELECT num, REPLACE(num, substr(num, 2,1),'') FROM log WHERE INSTR(num, '.'),
but it deletes all periods.
How can I remove the period?
I have a SQLite table with a column num (data type: text)
1.100.00
2.3025.00
2.000.00
3.500.16
4.3124.00
I would like to remove the first period.
The column should then look like this:
1100.00
23025.00
2000.00
3500.16
43124.00
I tried with:
SELECT num, REPLACE(num, substr(num, 2,1),'') FROM log WHERE INSTR(num, '.'),
but it deletes all periods.
How can I remove the period?
Share Improve this question edited Mar 22 at 11:14 Mark Rotteveel 110k229 gold badges156 silver badges224 bronze badges asked Mar 22 at 11:11 IamBeginnerIamBeginner 313 bronze badges 1- Will the start always be a single digit, then a period character? Will at always be a period followed by two digits at the end? Will it always be a total of exactly 2 periods? If the answer is no to any of these questions, add more sample data having different patterns. – jarlh Commented Mar 22 at 19:35
2 Answers
Reset to default 4You'll want
SELECT num, substr(num, 1, 1)||substr(num, 3) FROM log WHERE INSTR(num, '.');
That is: "return the first char pasted with everything from character 3".
The hickup
In your original query:
SELECT num, REPLACE(num, substr(num, 2,1),'') FROM log WHERE INSTR(num, '.');
The substr(num, 2,1)
is first evaluated, not as "position 2" but as "char at position 2", that is: '.'
Thus your query was internally interpreted as:
SELECT num, REPLACE(num, '.', '') FROM log WHERE INSTR(num, '.');
Which, you guess it, meant "replace all dots by nothing".
If and only if your string always ends with a dot and two digits you could take the route via a numeric that you then format to the expected output
SELECT num, printf("%.02f", CAST(REPLACE(num, '.', '') as Decimal)/100.0)
FROM log
本文标签: sqlRemove period from specific placeStack Overflow
版权声明:本文标题:sql - Remove period from specific place - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744317545a2600338.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论