JagaSrik
JagaSrik

Reputation: 718

Need to get the max value in a given string after matching with a column

Consider this string '123456789' and the table consisting of col1 with the values as discribed below:

Col1     
123
456
789

I need to write a query so the query will have to check for every value in the col1 and output the max matched with the string '123456789' in this i need to get output as 789.

Upvotes: 0

Views: 34

Answers (1)

Philipp Salvisberg
Philipp Salvisberg

Reputation: 360

Setup:

create table t (c varchar2(10));
insert into t values ('123');
insert into t values ('456');
insert into t values ('789');
commit;

Query:

select c, instr('123456789',c) as pos
  from t
 order by 2 desc 
 fetch first 1 row only;

Result:

C                 POS
---------- ----------
789                 7

Upvotes: 1

Related Questions