如题,我希望数据库查找到第一条记录就停下来返回,怎么写?
我加了一个条件rowmnum=1,没效果,应该是查找到所有记录然后再返回第一条的速度,大侠指点下迷津,多谢

解决方案 »

  1.   

    以我的经验...应该会有效果...贴出你的SQL
      

  2.   

    select bi from budget bi 
    where rownum = 1
    and bi.XXX = YYYYY 
      

  3.   


    --看个例子:SQL> select * from tbl;       ID1        ID2
    ---------- ----------
             1          2
             2          3
             5          7SQL> select t.id1,t.id2 from (select rownum rn,id1,id2 from tbl) t where t.rn<=1;       ID1        ID2
    ---------- ----------
             1          2SQL> 
      

  4.   


    --try it
    SQL> conn myuser/myuser@orcl
    已连接。
    SQL> select * from std_tea;       SID        TID
    ---------- ----------
          1003      20002
          1000      20002
          1002      20001
          1000      20001SQL> select * from std_tea where rowid >=all(select rowid from std_tea);       SID        TID
    ---------- ----------
          1000      20001SQL>
      

  5.   

    select * from (select bi from budget bi 
    where bi.XXX = YYYYY) where   rownum = 1
      

  6.   


    你对rownum的理解是对的。
    没效果说明找到第一条bi.XXX = YYYYY的记录就需要这么多时间。
      

  7.   

    写错了,呵呵
    发现问题了,是没建立索引,老大帮我建的,SQL菜鸟,各位大哥推荐点书,公司用的数据库是Oracle
    用Hibernate跟Oracle交互,基础知识比较不足想补充一下,谢谢了