I've thrown together a vb program to time 2 sql statements. However, after the first run both statements run at the same speed. I believe this is because of caching. Is there any other way of flushing the cache besides shutting down / restarting?
the Nth running should actually be faster than the 1st. The statement does not need to be parsed because a parse and plan are cached in the shared pool. Also, the data to be fetched are probably still in the database buffer cache.
You can flush the shared pool in most versions of Oracle, but you can only flush the database buffer cache starting with Oracle 10g. For example,
ALTER SYSTEM FLUSH SHARED_POOL;
ALTER SYSTEM FLUSH BUFFER_CACHE;