swingard
swingard

Reputation: 55

How to select all the string characters preceding a . in oracle

I am using Oracle 11 G and have the following set of data:

12.0
4.2
Version.1
7.9
abc.72

I want to return all string characters before the period. What sort of query would I run in order to achieve this? Any help would be greatly appreciated, thanks!

Upvotes: 0

Views: 2597

Answers (1)

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181290

You can try a combination of instr and substr.

Something like this:

select substr(field, 1, instr(field, '.') - 1)
  from your_table;

Assuming field always contains a . character on it.

You can also deal with strings without a . by using case, if or any other similar valid conditional function on Oracle's SQL language implementation.

Of course, you can always put this on a function to make it look nicer on your query.

Upvotes: 2

Related Questions