SERVER SQL
--SQL过滤掉空格和其他特殊字符函数
crteate function dbo.GetCodeString(@SourceSql varchar(500))
returns nvarchar(500)
as
begin
declare @i int
declare @ValidChar nvarchar(100)
declare @temp nvarchar(500)
set @ValidChar='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
set @i=0
while @i<=LEN(@SourceSql)
begin
if(charindex(substring(@SourceSql,@i+1,1),@ValidChar))>0
begin
if(@i=0)
begin
set @temp=substring(@SourceSql,@i+1,1)
end
else
begin
set @temp=@temp+substring(@SourceSql,@i+1,1)
end
end
set @i=@i+1
end
return @temp
end
--测试
--select dbo.GetCodeString('ST ror'' US')
--输出结果为STrorUS
oracle
CREATE OR REPLACE FUNCTION GET_CODE_STRING(SourceSql in varchar)
return varchar is
ValidChar varchar(500);
v_temp varchar(500);
i NUMBER(10);
begin
i := 0;
ValidChar := '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
while i <= length(SourceSql) loop
if (instr(ValidChar, substr(SourceSql, i + 1, 1))) > 0 then
if i = 0 then
v_temp := substr(SourceSql, i + 1, 1);
else
v_temp := v_temp || substr(SourceSql, i + 1, 1);
end if;
end if;
i := i + 1;
end loop;
--v_temp:=v_temp;
return v_temp;
end;