Do you ever wonder why Oracle Enterprise Manager and AWR reports show the SQL text for some SQL IDs as not available?
The DBA forums and discussion groups mention that it might be because the SQLs have already been flushed from the shared pool or wonder how do you get and confirm the SQL ID for a query without seeing the text of the query?
The truth is however slightly different. These are Oracle internal or so called pseudo cursors which are just structures providing direct access database objects by avoiding the overhead of writing an explicit SELECT statement. These structures access directly most of the time the data dictionary tables, CLOBs and BLOBs. Sometimes even NCHAR and NVARCHAR2.
This is the reason why these internal cursors show in OEM and AWR with the legend “SQL Text Not Available”. There is just no SQL.
They are used internally within the database and cannot be described. At least not completely. However, here is what you can do as suggested by MOS 1298471.1:
create or replace view h$pseudo_cursor as select Pseudo_cursor, sql_id,obj_id hex_obj_id ,obj# object_id, u.name owner, o.name object_name from (select distinct KGLNAOBJ Pseudo_cursor,kglobt03 sql_id ,substr(KGLNAOBJ ,instr(KGLNAOBJ,'_',1,3)+1 ,instr(KGLNAOBJ,'_',1,4)-instr(KGLNAOBJ,'_',1,3)-1) obj_id ,(case when replace(translate(substr(upper(KGLNAOBJ) ,instr(KGLNAOBJ,'_',1,3)+1 ,instr(KGLNAOBJ,'_',1,4) -instr(KGLNAOBJ,'_',1,3)-1) ,'0123456789ABCDEF','................') ,'.') is null then 'Y' else 'N' end) is_safe_to_compare from x$kglob) k , obj$ o, user$ u where obj#=decode(is_safe_to_compare,'Y',to_number(obj_id,'xxxxxxxxxx'),0) and o.owner#=u.user#
Now, we can try to find out more about our invisible SQL:
col hex_obj_id format a10 col pseudo_cursor format a30 col owner format a20 col object_name for A22 select * from h$pseudo_cursor where sql_id='grv54uyqkw2yc';
The second query shows us the pseudo PL/SQL used by Oracle internally. Notice the missing value for SQL ID!
Now, here is a question: how to tune pseudo cursors? If you run STA (SQL Tuning Advisor), the error message you get will be “The SQL has aged out of the cursor cache”. OEM will notify you with “The SQL statement is not available”:
So the bottom line is: if you see messages about SQL Text not being available, it is most likely due to Oracle trying to access internally LOBs or its own tables.