简体   繁体   中英

Measure cost of SELECT statement in PL/SQL

I'm trying to measure how much does a select cost. Normally I would do it simply by getting the value of consistent gets before executing the statement and after, however, I'd like to wrap it in PL/SQL so that it's more generic. The problem I'm facing however, is how can I simply run a select without actually storing the result?

One of the ideas I had was to wrap it in a for loop like so

select value into getsBefore from v$sesstat ...

for dummy in (select name from my_table where city = 'XYZ') loop
  i := i;
end loop;

select value into getsAfter from v$sesstat ...

But this doesn't seem like a correct approach.

I guess that I could simplify my question to - how can I SELECT something INTO <nothing> ?

Any ideas or hints on how to accomplish this?

Thanks

Try : SELECT * bulk collect INTO [variable]

See this as a reference SELECT INTO Statement

Since the counters in V$SESSSTAT are absolute since a session is started there is no other way than to store a snapshot before an action and then subtract the snapshot from new one after the action is executed.

One of Tom Kyte's most used scripts is RUNSTATS meant to compare two actions performing the same thing to see which implementation is better.

You can find of the versions with description at http://betteratoracle.com/posts/12-runstats

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM