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;
Run Code Online (Sandbox Code Playgroud)
或者这个:
select x.id
from(select t.id
from table1 t
where t.foo=p_foo
order by t.creation_date) x
where rownum = 1
Run Code Online (Sandbox Code Playgroud)
以上两者都有类似的结果,但我需要知道哪一个更有效!
这是Tom Kyte的口头禅:
如果可能的话,您应该在单个SQL语句中执行此操作.
如果您无法在单个SQL语句中执行此操作,请在PL/SQL中执行此操作.
如果您无法在PL/SQL中执行此操作,请尝试Java存储过程.
如果您不能在Java中执行此操作,请在C外部过程中执行此操作.
如果你不能在C外部程序中做到这一点,你可能需要认真思考为什么你需要这样做...
http://tkyte.blogspot.com/2006/10/slow-by-slow.html
| 归档时间: |
|
| 查看次数: |
21392 次 |
| 最近记录: |