Search notes:

Oracle: Query last executed SQL statement by joining V$SESSION and V$SQL

V$SESSION stores the hash and the child number of the most recently executed SQL statement in prev_hash_value and prev_child which allows the query the text, SQLID etc. from V$SQL:
select
   sql.sql_id,
   sql.sql_text
from
   v$session ses                                                     join
   v$sql     sql on ses.prev_hash_value   = sql.hash_value    and
                    ses.prev_child_number = sql.child_number        
where
   ses.sid = sys_context('userenv', 'sid')
;

Using concept in SQL*Plus

SQL> set  serveroutput off
SQL> var  sqlid varchar2(13)
SQL> select 'an sql statement' from dual;
SQL> -- TODO child number should also be captured.
SQL> exec    select sql.sql_id into :sqlid from v$session ses join v$sql sql on ses.prev_hash_value = sql.hash_value and ses.prev_child_number = sql.child_number where ses.sid = sys_context('userenv', 'sid')
SQL> select  sql_text from v$sqlarea where sql_id = :sqlid;
SQL> select * from table(dbms_xplan.display_cursor(:sqlid));
… but see also the _sql_id predefined variable …

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759561870, '216.73.216.149', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/installed/dynamic-performance-views/session/last-executed-SQL-statement(56): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78