SQL Server的写法:
declare @i int
declare @tb table (v int)
set @i = 10
while @i < 1000
begin
if cast(@i as nvarchar(10)) = reverse(cast(@i as nvarchar(10)))
begin
insert into @tb
select @i
end
set @i = @i + 1
end
select * from @tb
结果:
我用JAVA给你写下来,你自己转成SQL;
String start="";
String end="";
for (int i=1;i<1000;i++){
if(i<12){
System.out.println(i);
continue;
}
start=String.valueOf(i).substring(0,1);
end=String.valueOf(i).substring(-1,1);
if (start.equalse(end)){
System.out.println(i);
}
}
select 1 from dual where '2002'=REVERSE('2002');
用反转函数REVERSE。反转过来跟原字串相等。