gpt4 book ai didi

sql - plsql - 获取第一行 - 哪个更好?

转载 作者:行者123 更新时间:2023-12-04 17:25:55 25 4
gpt4 key购买 nike

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

以上两者都产生了相似的结果,但我需要知道哪个更有效!

最佳答案

这是汤姆·凯特的口头禅:

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

关于sql - plsql - 获取第一行 - 哪个更好?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9654188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com