考虑此字符串'123456789'
以及包含col1的表格,其值如下所示:
Col1
123
456
789
我需要编写一个查询,以便查询必须检查col1中的每个值,并输出与字符串'123456789'
匹配的最大值,我需要输出为789
。< / p>
答案 0 :(得分:1)
设定:
create table t (c varchar2(10));
insert into t values ('123');
insert into t values ('456');
insert into t values ('789');
commit;
查询:
select c, instr('123456789',c) as pos
from t
order by 2 desc
fetch first 1 row only;
结果:
C POS
---------- ----------
789 7