create or replace function isSame(str1 varchar2,str2 varchar2) return varchar2 is flag varchar2(10) := 'false'; i number := 0; strtemp varchar2(100); begin if str1 is null or str2 is null then return flag; elsif length(str1) != length(str2) then return flag; else loop i := i + 1; exit when i = length(str1) or instr(str1,strtemp) = 0; strtemp := substr(str2,i,1); end loop; if i = length(str1) then flag := 'true'; end if; end if;
return flag; end; 测试:SQL> select isSame('234','432') from dual;ISSAME('234','432') -------------------------------------------------------------------------------- true
或者SQL> select case when length('234') = length('431') and translate('234','432','') is null and translate('234','432','') is null then 'true' else 'false' end from dual;CASEW ----- trueSQL>
敲错了,请把length('431')改成'length('432')
SQL> select * from test;NAME ---------- 234 432 123 213SQL> select max(name) name from (select name,translate(name,name,substr(name,1,1) + substr(name,2,1) + substr(name,3,1)) col from test) group by col;NAME ---------- 213 432
create or replace function isSame(str1 varchar2,str2 varchar2) return varchar2
is
flag varchar2(10) := 'false';
i number := 0;
strtemp varchar2(100);
begin
if str1 is null or str2 is null then
return flag;
elsif length(str1) != length(str2) then
return flag;
else
loop
i := i + 1;
exit when i = length(str1) or instr(str1,strtemp) = 0;
strtemp := substr(str2,i,1);
end loop;
if i = length(str1) then
flag := 'true';
end if;
end if;
return flag;
end;
测试:SQL> select isSame('234','432') from dual;ISSAME('234','432')
--------------------------------------------------------------------------------
true
-----
trueSQL>
敲错了,请把length('431')改成'length('432')
----------
234
432
123
213SQL> select max(name) name from (select name,translate(name,name,substr(name,1,1) + substr(name,2,1) + substr(name,3,1)) col from test) group by col;NAME
----------
213
432
敲错了,请把length('431')改成'length('432')这个sql可以实现功能吗?我输入‘2243’和‘4322’居然返回ture