First, it will look into the System Global Area (SGA) weather query is been executed earlier.
If it exists, it would retrieve the same output present in memory.
If not the query we typed complies and the resulting parse tree and execution plan is been stored in SGA. Then the query gets executed and the output is given to the application.