[英]Oracle db query - data format issue
I'm wondering if there is a way to query the oracle db against formatted field value. 我想知道是否有一种方法可以针对格式化的字段值查询oracle db。 Example:
例:
I have a table of postcodes stored in the format of "part1 part2". 我有一张以“ part1 part2”格式存储的邮政编码表。 I want to be able to find a postcode either by searching it using the above format or "part1part2" format.
我希望能够通过使用上述格式或“ part1part2”格式进行搜索来查找邮政编码。 What I was thinking is to format the entered postcode by removing the spaces and then query the database like:
我当时想的是通过删除空格来格式化输入的邮政编码,然后像这样查询数据库:
SELECT *
FROM POSTCODES_TBL t
WHERE t.postcode.**Format(remove spaces)** = 'part1part2'
The Format(remove spaces would convert the postcode from "part1 part2" to "part1part". Format(删除空格会将邮政编码从“ part1 part2”转换为“ part1part”。
My question is, is it possible? 我的问题是,可能吗?
You can use regexp_replace
您可以使用
regexp_replace
SELECT *
FROM POSTCODES_TBL t
WHERE regexp_replace(t.postcode,'\s', '') = 'part1part2'
This will remove any whitespace (space, tab, newlines etc) 这将删除所有空格(空格,制表符,换行符等)
or if you only want to get rid of spaces, replace
will work just as well: 或者,如果您只想摆脱空间,那么
replace
也将同样有效:
SELECT *
FROM POSTCODES_TBL t
WHERE replace(t.postcode,' ', '') = 'part1part2'
More details in the manual: 手册中的更多详细信息:
You could use like 你可以用像
SELECT * FROM POSTCODES_TBL t WHERE t.postcode like 'part1%part2' SELECT * FROM POSTCODES_TBL t在类似'part1%part2'的t.postcode中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.