Finding SQL statements in cache

So I was trying to illustrate how Oracle statements issued with bind variables show up only once in the Shared Pool, and the following failed to display this info (I was getting a test case working before I incorporated Bind Vars):
SQL> begin
  2   for row in (select * from abcdef)
  3   loop
  4    null;
  5   end loop;
  6  end;
  7  /
PL/SQL procedure successfully completed.
SQL> select * from v$sql where sql_text like 'select * from abcdef%';
no rows selectedwhile if I just executed that same stmt I get back data:
SQL> select * from abcdef;
no rows selected
SQL> select SQL_TEXT,
            SQL_ID,
            EXECUTIONS
      from v$sql
      where sql_text like 'select * from abcdef%';
SQL_TEXT
SQL_ID        EXECUTIONS
select * from abcdef
1rd5f149c8591          1Why doesn't the SQL issued from PL/SQL display?
Thanks,
Chuck

How about this then
SQL> CREATE OR REPLACE procedure do_it (in1 number)
  2   as
  3   begin
  4    for row in (select f1 from abcdef where 1 = in1)
  5    loop
  6     null;
  7    end loop;
  8   end;
  9  /
Procedure created.
SQL>  select SQL_TEXT, SQL_ID, EXECUTIONS
  2   from v$sql
  3   where SQL_TEXT like '%select f1 from abcdef%';
SQL_TEXT
SQL_ID        EXECUTIONS
select SQL_TEXT, SQL_ID, EXECUTIONS  from v$sql  where SQL_TEXT like '%select f
1 from abcdef%'
61ngkxbm2pa00          1
SQL> begin
  2    do_it(1);
  3  end;
  4  /
PL/SQL procedure successfully completed.
SQL>  select SQL_TEXT, SQL_ID, EXECUTIONS
  2   from v$sql
  3   where SQL_TEXT like '%select f1 from abcdef%';
SQL_TEXT
SQL_ID        EXECUTIONS
select SQL_TEXT, SQL_ID, EXECUTIONS  from v$sql  where SQL_TEXT like '%select f
1 from abcdef%'
61ngkxbm2pa00          2This doesn't show that the SQL statement was executed when do_it is called.
-cf

Similar Messages

  • How to find sql statement with Unix process pid

    Hi
    how to find sql statement with Unix process pid
    is there any view to find that.
    please if so let me know
    Thanks in advance

    this is how I am doing this:
    oracle 7352340 7459066 0 07:47:10 - 0:00 oracleJDERED (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
    oracle 7459066 5386396 2 07:47:10 pts/1 0:01 sqlplus
    select sid,serial# from v$session where process='7459066';
    SID SERIAL#
    2178 6067
    select sql_text
    from
    v$sqlarea a,
    v$session b
    where a.hash_value = b.sql_hash_value
    and b.sid = 2178
    ;

  • How to find SQL Statement fired using SYS.AUD$ - Database Auditing

    Dear Friends
    I am having Oracle 9i Database and have configured it with database auditing option by setting the following parameter in init.ora file
    AUDIT_TRAIL = "DB"
    I want to audit SELECT, INSERT , UPDATE and DELETE operations on PRACTICE.EMP table for which I did :
    1) Logged in as SYS
    2) SQL> AUDIT SELECT, INSERT, UPDATE, DELETE
    ON PRACTICE.EMP
    BY ACCESS
    WHENEVER SUCCESSFUL;
    Audit Succedded
    Now how should I find out the SQL statement that does the insert, update or delete operation on the EMP table using SYS.AUD$ table
    Thanks

    Hi,
    It's contents can be viewed directly or via the following views:
    * DBA_AUDIT_EXISTS
    * DBA_AUDIT_OBJECT
    * DBA_AUDIT_SESSION
    * DBA_AUDIT_STATEMENT
    * DBA_AUDIT_TRAIL
    * DBA_OBJ_AUDIT_OPTS
    * DBA_PRIV_AUDIT_OPTS
    * DBA_STMT_AUDIT_OPTS
    The audit trail contains a lot of data, but the following are most likely to be of interest:
    * Username : Oracle Username.
    * Terminal : Machine that the user performed the action from.
    * Timestamp : When the action occured.
    * Object Owner : The owner of the object that was interacted with.
    * Object Name : The name of the object that was interacted with.
    * Action Name : The action that occured against the object. (INSERT, UPDATE, DELETE, SELECT, EXECUTE)
    So, take a look at action_name column from DBA_AUDIT_TRAIL view.
    Cheers
    Legatti

  • How to find SQL statement = Database Auditing

    Dear All
    I have configured Database Auditing on Oracle 9i Enterprise Edition Server
    parameter init.ora file:
    AUDIT_TRAIL = "DB"
    I want to audit INSERT,UPDATE, DELETE STATEMENT on PRACTICE.EMP table
    for which i did :
    1) Logged in as SYS
    SQL> AUDIT INSERT,UPDATE,DELETE
    ON PRACTICE.EMP
    BY ACCESS
    WHENEVER SUCCESSFUL
    Audit Succedded
    2) Now I have to check the SQL statement that did insert update or delete operation using SYS.AUD$
    3) There is SQLTEXT field , datatype is CLOB.
    How should I check the SQL Statements that were fired on PRACTICE.EMP table
    Kindly help

    SQL> show user
    USER is "SYS"
    SQL> alter system set audit_trail = db,extended scope=spfile;
    alter system set audit_trail = db,extended scope=spfile
    ERROR at line 1:
    ORA-32001: write to SPFILE requested but no SPFILE specified at startup
    I have init.ora but no spifle so should I create SPFILE based on INIT.ORA and then give the command ?
    As of now I am using V$SQL view to find all the commands executed on my database.
    I found one good book "Oracle Security" OREILY PUBLICATION in which Auditing Database is discussed in good details.
    Thank you so much for all your efforts

  • How to find sql statement which generates LOCK

    Hello,
    In my plsql procedure i have used SELECT FOR UPDATE NO WAIT statement to avoid the current record used by another user.
    Actually i want to find which sqlquery is locking the Object other than my procedure.
    I can find the session id which is locking the object but i can not able to find sql text.
    How to find the SQL text from particular LOCKING Session id as v$sql or v$sqltext or v$sqlarea dont have session id?
    Any help can be appreciated.
    Thanks in advance.

    It's not necessarily that easy to find the statement that was responsible for the lock.
    It depends.
    First of all, it depends on version.
    If you're >= 10g and you're lucky and you're licensed for Diagnostic Pack, you might find it in ASH.
    If the statement that's responsible for the lock is also waiting on something else or runs for long enough, then ASH will almost certainly have it.
    Doug Burns has a 10-part series on the subject.
    http://oracledoug.com/serendipity/index.php?/archives/1477-Diagnosing-Locking-Problems-using-ASH-Part-1.html

  • For Finding sql statements which consumes High CPU

    Hai,
    Can any help me for finding, which sql statements are comsumes high CPU

    generaly:
    1. from unix site :
    us top command or ps (but this depend on platform) -> use pid in select * from v$process where spid <>
    2. from db site
    select * from v$sql_area order by buffer_gets desc ;
    this can You join with v$session where v$session.sql_address=v$sqlarea.address
    and when You wont to see % of os select *spid from v$process where addr=<v$session.paddr>
    and then in unix ps -ef | grep <spid>
    But point 2 is maybe discutable because also parse is one style how to consume CPU ... etc
    In 10g
    from AWR dba_hist_osstat -> DBA_HIST_SQLSTAT You can see high usage CPU interval , but this show You not momentaly action , but historical data
    momentali from ASH
    now I study viraq_sh script ... I thing this answer your question tottally
    Message was edited by:
    branislav.dobrotka

  • How to find SQL Statements for BW queries ?

    Experts,
    Is there a way, we can see what SQL statement BW queries creates ?
    please Help.

    Hi,
    use sql trace: transaction ST05.
    ask your database admin. He can control the database session.
    => for oracle: you can see the session also in the sap gui.
    Sven

  • Cache hit ratio - index sql statement

    I am reading the note 33833.1 on Metalink web site. I have diffult to understand the part in the last page of the note. In the last page author talk of a situation where the cache hit ratio is near 100% but the system is not good because. the author talk of a bad sql statement using a non selective index.
    Anyone can explain me this situation ?
    thanks for all

    Because it can be spoofed easily, cache hit ration should never be used as an indicator of system performance. I could not find the article you refered to I can explain it this way:
    Repeatedly hitting the same large amount of datablocks to return a small amount of data will show an artificially high buffer cache hit ratio because the same block get hit over and over, even though most of the data in them is irrelavent.
    Another example would be using subquries instead of joins or joins on inline views.
    All that being said, a low buffer cache hit ratio over an extended period of time is an indicator that the cache is too small, however a high buffer cache hit ration does not mean that is the right size.
    (it's Monday, I hope this makes sense.)

  • Find start and end execution time of a sql statement?

    I am have databases with 10.2.0.3 and 9.2.0.8 on HP UNIX 11i and Windows 200x.
    I am not in a position to turn on sql tracing in production environment. Yet, I want to find when a sql statement started executing and when it ended. When I look at v$sql, it has information such FIRST_LOAD_TIME, LAST_LOAD_TIME etc. No where it has information last time statement began execution and when it ended execution.. It shows no of executions, elapsed time etc, but they are cumulative. Is there a way to find individual times (time information each time a sql statement was executed. – its start time, its end time ….)? If I were to write my own program how will I do it?
    Along the same line, when an AWR snapshot is shown, does it only include statements executed during that snapshot or it can have statements from the past if they have not been flushed from shared memory. If it only has statements executed in the snapshot period, how does it know when statement began execution?

    Hi,
    For oracle 10g you can use below query to find start and end time, you can see data for last seven days.
    select min(to_char(a.sample_time,'DD-MON-YY HH24:MI:SS')) "Start time", max(to_char(a.sample_time,'DD-MON-YY HH24:MI:SS')) "End Time", b.sql_text
    from dba_HIST_ACTIVE_SESS_HISTORY a,DBA_HIST_SQLTEXT b where
    a.sql_id=b.sql_id
    order by 1;
    Regards
    Jafar

  • How to find what sql statement is currently running by scheduler job?

    Hi
    I scheduled a stored procedure to run every 5 minutes using dbms_scheduler.
    The stored procedure internally call serveral other stored procedures.
    The scheduled job is in running state and right now I want to find out what is the sql statement the job executing.
    Is there any sql query to find out what is sql query the schedular job is running?? Please help me.
    Thanks in Advance.

    The previous sql id is null in this case.
    I already quoted as I am running a pl/sql block in my scheduler job.
    begin
    usp_test('praram');
    end;
    I am using the pl/sql block as above in my scheduler job. The USP_TEST inturn calls some other stored procedures and each stored procedure has several inserts and update statements.
    The scheduler job is still running. I know the sid of the running scheduler job.
    I want to know the job is at which stored procedure and at which insert/update statement.
    Please let me know is there any query to fulfil my requirement?
    I greatly appreciate your help
    Thanks

  • How to write the sql statement of my finder function in cmp?

    hi,
    I create a cmp ejb from table INFOCOLUMN,and I create a my finder function ,which sql statement is :
    select * from INFOCOLUMN WHERE employee_id=id
    employee_id is a column of the table,and id is the finder function parameter.
    The error is : invalid column name
    So,how to write the sql statement.
    Thanks .

    Mole-
    Bind variables are of the form $1, $2, etc., so your query stmt should look like:
    select * from INFOCOLUMN WHERE employee_id=$1
    -Jon

  • Where to find information about SQL States ?

    Hello,
    I'm trying to find information about X/OPEN SQL States explanation. Can anyone help me. ?

    SQLStates are part of the SQL standard and so you can read up on them from any vendor's site.Here is an IBM explanation that talks about the SQLStates class (first two chars) and subcode.
    http://publib.boulder.ibm.com/pubs/html/as400/v5r1/ic2924/index.htm?info/rzala/rzalaint.html

  • Auditing: Flushing SGA to ensure SQL statement is not cached

    Currently I'm experimenting with Oracle auditing and have noticed that when I audit an object, like a table (AUDIT SELECT ON MY_TABLE), the select on the table is audited only once per session. I.e. When a user connects, and does:
    SQL> select * from my_table;
    SQL> ..
    SQL> ..
    SQL> select * from my_table;
    SQL> ..
    SQL> ..
    .. only the first select statement is audited. I have to reconnect each time for the statement to be audited.
    Is this how auditing works? I was thinking that it could be that the statement is held in memory and when a user does another subsequent select statement, the statement is cached and thus not audited. Could this be the case? I flushed the SGA and I still got the same results above...
    I'd like to hear your opinions about this.

    Raj has provided the solution but I would like to point out that auditing selects by access can generate an alful lot of audit records very quickly. The sys.aud$ table and its index may grow very, very large and fill the system tablespace if you are not careful. Also the updates to sys.aud$ are logged so you will also be generating a lot of extra redo if you make this type of auditing widespread.
    IMHO -- Mark D Powell --

  • How could I find the SQL statement who get this message ?

    ORA-01555 caused by SQL statement below (Query Duration=11191 sec, SCN: 0x0854.723b9c32)
    ... How could I find the SQL statement who got this message ?
    Thanks, Paul

    ORA-01555 means that the UNDO/ROLLBACK space is not large enough.
    This occurs because the SELECT statement is attempting to read the UNDO, but the UNDO has been released (transactions have committed or rolled back) and reused.
    The following are SOME of the reasons I have seen this to occur:
    1) Updates in a loop, with commits happening in the same loop
    - this will mark the UNDO available quickly and quickly reuse it. Then when the SELECT wants to rebuild a block, the UNDO used to rebuild the block has been reused (solution, make the UNDO bigger)
    2) A SELECT cursor used to control a loop in which updates are performed, and a 'done' flag is marked against the current cursor record, and commits are performed at the end of each loop, prior to fetching the next record
    - same problem as above, but it hits the current process. Same solution
    3) A 'month end' activity spike occurs, and all sorts of transactions create updates. There is a report that reports the activity - amusingly it needs to start at the beginning of all the work and updates periodically by doing a huge SELECT up front. This is then used to drive a loop which attempts to get information from the various transactions that have been updated and committed. After a while, the SELECT gets an ORA-01555
    - same problem as above and same solution. Get a bigger UNDO segment.
    You say this only happens once a month. That should give a hint.
    I wouldn't bother with which SELECT statement, as much as which APPLICATIONs are being run when it happens.
    One way around this - use 10g and set the guaranteed retention period. All sorts of other things will break, by no more 1555. <g>

  • Query to find the the sql statements

    Hi,
    Oracle Version: 10.2.0.3
    Can any one please help me how to find which sql statements generate the error "OPEN CURSORS EXCEED ".
    Thanks & Regards,
    Poorna Prasad.S

    1) export the table, drop the table, create the table definition in the new
    tablespace, and then import the data (imp ignore=y).
    2) Create a new table in the new tablespace with the "CREATE TABLE x AS
    SELECT * from y" command:
    CREATE TABLE temp_name TABLESPACE new_tablespace AS SELECT * FROM real_table;
    Then drop the original table and rename the temporary table as the original:
    DROP TABLE real_table;
    RENAME temp_name TO real_table;
    3) Use the one mentioned in previous reply.
    After #1 or #2 is done, be sure to recompile any procedures that may have been
    invalidated by dropping the table.

Maybe you are looking for