select rn,id from
(select rownum rn,id,name from id<'1' order by id desc)
where rn=1
union all
select id,name from id='1'
union all
select id,name from id>'1' where rownum=1 

解决方案 »

  1.   

    to hippie1024(痞子) 
    这条语句不用rowid我觉得是不可能做出来的
      

  2.   

    呵呵
    不难嘛
    select * from (
    (select * from tbl_name where id= :id)
    union
    select * from (select * from tbl_name where id< :id order by id desc) where ROWNUM=1 
    union
    select * from (select * from tbl_name where id> :id order by id asc) where ROWNUM=1 
    )
      

  3.   

    select * from tbname where abs(id-已知id) in (0,1);
      

  4.   

    试试解析函数 lag和lead:
    select id,lag(id,1,null) over(order by id) as last_record,lead(id,1,null) over(order by id) as next_record from table;
      

  5.   

    to  kulama2004(kulama) :我写的有不妥么?
    to Samland(samland) : 偶们写的是一回事:)
      

  6.   


    select * from tbname 
    where id between (id-1) and (id+1)括号可以不要
      

  7.   

    我想问一下,为什么只考虑id加减一的情况???有时候id是不连贯的啊?
      

  8.   

    select * from tbname where id-已知id = (select max(id-已知id) from tbname where id<已知id) or id-已知id = (select min(id-已知id) from tbname where id>已知id) or id=已知id;
      

  9.   

    select * from tbname where id =:id 
    or id in
    (select max(id) from tbname where id <:id) 
    or id in
    (select min(id) from tbname where id>:id)
      

  10.   

    分析函数lag和lead 就是专门搞这个滴~
      

  11.   

    select * from tbname where id =:id 
    or 
    ((id in
    (select max(id) from tbname where id <:id) 
    or id in
    (select min(id) from tbname where id>:id)) and id is not null) 
      

  12.   

    id long
    这个long是什么意思?vc的long还是oracle的long?