加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

plsql – 获取第一行 – 哪一个更好?

发布时间:2020-12-12 16:25:52 所属栏目:百科 来源:网络整理
导读:LV_id number;Cursor CR_test Is select t.id from table1 t where t.foo = p_foo order by t.creation_date; Open CR_test;Fetch CR_test Into LV_id;Close CR_test; 或者这个: select x.idfrom(select t.id from table1 t where t.foo=p_foo order by t.c
LV_id number;
Cursor CR_test Is
  select t.id
  from table1 t
  where t.foo = p_foo
  order by t.creation_date; 

Open CR_test;
Fetch CR_test
 Into LV_id;
Close CR_test;

或者这个:

select x.id
from(select t.id
     from table1 t
     where t.foo=p_foo
     order by t.creation_date) x
where rownum = 1

以上两者都有类似的结果,但我需要知道哪一个更有效!

这是Tom Kyte的口头禅:

You should do it in a single SQL statement if at all possible.
If you cannot do it in a single SQL Statement,then do it in PL/SQL.
If you cannot do it in PL/SQL,try a Java Stored Procedure.
If you cannot do it in Java,do it in a C external procedure.
If you cannot do it in a C external routine,you might want to seriously think about why it is you need to do it…

http://tkyte.blogspot.com/2006/10/slow-by-slow.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读