Clarification in V$SQL and V$sqlarea

Hi Gurus, I have a clarification in V$SQL and V$sqlarea. Is it possible to get the entire set of SQL commands that are executed or run for particular session irrespective of the number of commands that are executed during the session. And can this result be got in a text file.
thanks in advance.

Hello,
with execute dbms_system.set_sql_trace_in_session(session_id, serial_id, {True | False}) you can activate SQL tracing for a specific session. SQL Trace will generate a trace file in udump. With TKPROF you can format the output.
If you want to trace your session: ALTER SESSION SET SQL_TRACE = TRUE
regards,
juergen_klinsmann

Similar Messages

  • V$sql and v$sqlarea

    Go no replies under DB General, trying over here.
    I am trying to understand parsing_user_id and child_number in v$sql and how the numbers roll up into v$sqlarea. Here are some examples:
    SQL> select hash_value, parsing_user_id, child_number, executions, disk_reads, first_load_time
    2 from v$sql
    3 where hash_value = 4282625122;
    HASH_VALUE PARSING_USER_ID CHILD_NUMBER EXECUTIONS DISK_READS FIRST_LOAD_TIME
    4282625122 0 0 525498 0 2003-05-18/01:59:40
    4282625122 0 1 507702 0 2003-05-18/01:59:40
    4282625122 134 2 436535 68546 2003-05-18/01:59:40
    SQL>
    SQL> select hash_value, parsing_user_id, executions, disk_reads, first_load_time
    2 from v$sqlarea
    3 where hash_value = 4282625122;
    HASH_VALUE PARSING_USER_ID EXECUTIONS DISK_READS FIRST_LOAD_TIME
    4282625122 0 1469735 68546 2003-05-18/01:59:40
    SQL>
    SQL> select hash_value, parsing_user_id, child_number, executions, disk_reads, first_load_time
    2 from v$sql
    3 where hash_value = 4256986771;
    HASH_VALUE PARSING_USER_ID CHILD_NUMBER EXECUTIONS DISK_READS FIRST_LOAD_TIME
    4256986771 119 0 22126 93 2003-05-18/00:51:00
    4256986771 28 1 11018 562 2003-05-18/00:51:00
    4256986771 26 2 43804 215 2003-05-18/00:51:00
    SQL>
    SQL> select hash_value, parsing_user_id, executions, disk_reads, first_load_time
    2 from v$sqlarea
    3 where hash_value = 4256986771;
    HASH_VALUE PARSING_USER_ID EXECUTIONS DISK_READS FIRST_LOAD_TIME
    4256986771 119 76948 870 2003-05-18/00:51:00
    Given that uid 0 is SYS, and that each hash_value identifies the same unique sql statement and SGA address, and the second example shows what I would expect when multiple users execute the same cached sql:
    1. Why does the first one report the actual app user (134) associated with child 2, and uid 0 children (0 and 1)?
    2. How do the SYS (puid=0) records get created?
    3. Why are there no stats other than executions associated with the puid of 0? (I just included disk_reads as an example). Are the numbers in v$sqlarea correct?
    Insight appreciated.

    So, kindly let me know the retention period of the queries in the v$sql or v$sqlarea.They remain in SGA, until Oracle overwrites them.
    There is no "rule" on how long or how little they exist.

  • V$session and v$sqlarea is interpreting in different way

    I am using redhad linux 5 version. The db version is oracle11g.
    I am trying to run the below shell script on the linux box
    export ORACLE_SID=chf01
    export ORACLE_HOME=/ora/app/oracle/product/11.1.0/db_1
    export WORKDIR=/ora/app/oracle/admin/chf01/scripts
    cd $WORKDIR
    $ORACLE_HOME/bin/sqlplus scott/tiger@ch01 << EOF
    spool sqlcapture.log
    INSERT INTO scott.T_SQL_CAPTURE
    SELECT MACHINE,
    SQL_FULLTEXT
    FROM
    v$session a,
    v$sqlarea b
    where
    ((a.sql_address = b.address
    and a.sql_hash_value = b.hash_value )
    or ( a.prev_sql_addr = b.address
    and a.prev_hash_value = b.hash_value))
    commit;
    spool off
    exit
    EOF
    ERROR=`grep 'ORA-' sqlcapture.log | wc -l`
    if [ "$ERROR" -gt 0 ]
    then
    cat sqlcapture.log|mailx -s "sqlcapture is failed" \ [email protected]
    else
    cat sqlcapture.log|mailx -s "sqlcapture is successful" \ [email protected]
    fi
    exit
    here is the spool file content. v$session is interpreted as v a and v$sqlarea is interpreted as v b.
    How can i fix this?
    SQL> INSERT INTO scott.T_SQL_CAPTURE
    2 SELECT MACHINE,
    3 SQL_FULLTEXT
    4 FROM
    5 v a,
    6 v b
    7 where
    8 ((a.sql_address = b.address
    9 and a.sql_hash_value = b.hash_value ) 10 or ( a.prev_sql_addr = b.address
    11 and a.prev_hash_value = b.hash_value))
    13 ;
    v b
    ERROR at line 6:
    ORA-00942: table or view does not exist
    SQL> commit;
    Commit complete.
    SQL> spool off

    Because *$* is interpreted by Linux shell. So you need to escape it. I used to escape all $ with \$ but someone in another thread posted a lovely trick. Use this:
    $ORACLE_HOME/bin/sqlplus scott/tiger@ch01 << \EOF
    .

  • V$session and v$sqlarea

    Hi All,
    How can i join the v$session and v$sqlarea? I am trying to find out who has executed the sql statement or still executing the statement. I think without joining with v$session its not possible.
    Is there a way to get this information?
    And I am using Oracle 10g.
    Edited by: Ratna Bikram on Sep 25, 2010 11:45 PM

    Ratna Bikram wrote:
    Hi All,
    How can i join the v$session and v$sqlarea? I am trying to find out who has executed the sql statement or still executing the statement. I think without joining with v$session its not possible.
    Is there a way to get this information?
    And I am using Oracle 10g.
    Edited by: Ratna Bikram on Sep 25, 2010 11:45 PMhttp://download.oracle.com/docs/cd/B19306_01/server.102/b14237/dynviews_2088.htm#REFRN30223
    SQL_ADDRESS      RAW(4 | 8)      Used with SQL_HASH_VALUE to identify the SQL statement that is currently being executed
    SQL_HASH_VALUE      NUMBER      Used with SQL_ADDRESS to identify the SQL statement that is currently being executed
    SQL_ID      VARCHAR2(13)      SQL identifier of the SQL statement that is currently being executed
    SQL_CHILD_NUMBER      NUMBER      Child number of the SQL statement that is currently being executedFrom V$SESSION will map into the column in V$SQLAREA. There they will lose the SQL_ prefix (so HASH_VALUE and ADDRESS), but SQL_ID stays the same.

  • How can I create an csv/excel file using pl/sql and then sending that file

    How can I create an csv/excel file using pl/sql and then sending that file to a clients site using pl/sql?
    I know how to create the csv/excel file but I can't figure out how I would get it to the clients site.

    968776 wrote:
    How can I create an csv/excel file using pl/sql and then sending that file to a clients site using pl/sql?
    I know how to create the csv/excel file but I can't figure out how I would get it to the clients site.You are trying to do it at a wrong place..
    Whay do you want database (pl/sql) code to do these things?
    Anyhow, you may be interested in :
    {message:id=9360007}
    {message:id=9984244}

  • What is the diffrence between package javax.sql and java.sql

    Is javax designed for J2EE?
    And when to use package javax?

    Hi,
    What is the diffrence between package javax.sql and java.sql?The JDBC 2.0 & above API is comprised of two packages:
    1.The java.sql package and
    2.The javax.sql package.
    java.sql provides features mostly related to client
    side database functionalities where as the javax.sql
    package, which adds server-side capabilities.
    You automatically get both packages when you download the JavaTM 2 Platform, Standard Edition, Version 1.4 (J2SETM) or the JavaTM 2, Platform Enterprise Edition, Version 1.3 (J2EETM).
    For further information on this please visit our website at http://java.sun.com/j2se/1.3/docs/guide/jdbc/index.html
    Hope this helps.
    Good Luck.
    Gayam.Srinivasa Reddy
    Developer Technical Support
    Sun Micro Systems
    http://www.sun.com/developers/support/

  • Running Multiple SQL in a Single Worksheet: Can I Selectively Run a Single SQL and Append Output?

    In any release of SD, if I have a single worksheet containing 10 sqls. Is it possible to place the cursor on any of the sql and run only that sql, yet, append its output to existing output window. I can then select another sql and execute it and keep appending output. In other words, do not clear existing output or start a new output tab.
    As it exists today (in any release), I can either 'run script' which does append, but it executes all the sql (non-selective). Alternately, I can 'run statement' to selectively run a single sql, but it will clear the output window (or if pinned), start a new one. None of this is what I want.
    Thank you.

    Select the query you want to run. Execute it via F5. Then highlight the next query and repeat.
    The output will append to the Script Output panel.
    There's no way to get 2 queries to share a grid, unless you were to run them as a single query a la UNION.

  • PL/SQL and Java implementation

    Hi all,
    We need to implement a fast solution for reporting to our existing web application. Application is totally based on stored procedures written in PL/SQL.
    We have already java classes for drawing different types of charts
    named Chartdirector (http://www.advsofteng.com/)
    This library can create chart images in memory.
    I have already read about calling java classes from PL/SQL and SQLJ too.
    My questions are;
    1. Is this safe to include classes to database and create
    reports by using loadjava in real life. I mean not in theory, in real life?
    2. Is there any experiments of the audience about this method?
    3. Would it be any performance problems about this?
    4. Should i prefer to use any Java container and jsps instead of this method?
    I will continue to research for necessary steps after i could see the light :)
    Thank you to all,
    Regards,
    Gokhan

    > 1. Is this safe to include classes to database and create
    reports by using loadjava in real life. I mean not in theory, in real life?
    Yes.
    > 2. Is there any experiments of the audience about this method?
    Experiments and actual implementation - yes. It works. Granted, it does not always work as easy as running the Java code from the command line. But it does work.
    > 3. Would it be any performance problems about this?
    This is a potential problem with any software code.
    4. Should i prefer to use any Java container and jsps instead of this method?
    To be honest, I prefer not using Java for web graphics as I'm not impressed with the quality and flexibility of the graphs generated. I prefer using (and paying for commercial use) for the JPGraph classes for PHP - and using that from PL/SQL (via Zend Core for Oracle).
    Another option is to use SVG and generated SVG directly from PL/SQL. But this requires a browser plugin and SVG also does not look that great. (this is btw what Oracle's HTMLDB does and uses)

  • Dynamic SQL and IN CLAUSE from Pro C code

    Hi Guys,
    Tyring to embed sql in Pro C. Here I don't know in hand how many items will be there in the IN Clause of my dynamic sql. Tried this with a loop and then adding actual values to the stement and then executing it. This worked but as this hard coding makes it literal sql and hence hampers performance. Can any one help me with how to put bind variables where we don't know how many of them will be there in a dynamic sql.
    Thanks,

    Dynamic SQL supports user defined types, try passing a collection and using TABLE(CAST(collection)) in the SQL statement.
    In the current approach (creating IN clause at runtime) keep in mind that in a IN clause you can put a maximum of 255 elements...
    Max

  • Dynamic SQL and Data with Single Quotes in it.

    Hi There,
    I have a problem in that I am using dynamic SQL and it happens that one of the columns does contain single quotes (') in it as part of the data. This causes the resultant dynamic SQL to get confused as the single quote that is part of the data is taken to mean end of sting, when in fact its part of the data. This leaves out a dangling single quote that was meant to enclose the string. Here is my dynamic SQL and the result of the parsed SQL that I have captured:
    ****Dynamic SQL*****
    l_sql:='select NOTE_TEMPLATE_ID '||
    'FROM TMP_NOTE_TEMPLATE_VALUES '||
    'where TRIM(LEGACY_NOTE_CODE)='''||trim(fp_note_code)||''' '||
    'and TRIM(DISPLAY_VALUE)='''||trim(fp_note_text)||''' ';
    execute immediate l_sql INTO l_note_template_id;
    Because the column DISPLAY_VALUE contains data with single quotes, the resultant SQL is:
    ******PARSED SQL************
    select NOTE_TEMPLATE_ID
    FROM TMP_NOTE_TEMPLATE_VALUES
    where TRIM(LEGACY_NOTE_CODE)='INQ' and TRIM(DISPLAY_VALUE)='Cont'd'
    And the problem lies with the single quote between teh characters t and d in the data field for DISPLAY_ITEM. How can I handle this?
    Many thanks,

    I have been reliably informed that if one doesn't enclose char/varchar2 data items in quotes, the right indices may not be usedI am into oracle for past 4 years and for the first time i am hearing this.
    Your reliable source is just wrong. Bind variables are variables that store your value and which are used in SQL. They are the proper way to use values in your SQL. By default all variables in PL/SQL is bind variable.
    When you can do some thing in just straight SQL just do it. Dynamic SQL does not make any sense to me here.
    Thanks,
    Karthick.

  • Dynamic SQL and Bulk Bind... Interesting Problem !!!

    Hi Forum !!
    I've got a very interesting problem involving Dynamic SQL and Bulk Bind. I really Hope you guys have some suggestions for me...
    Table A contains a column named TX_FORMULA. There are many strings holding expressions like '.3 * 2 + 1.5' or '(3.4 + 2) / .3', all well formed numeric formulas. I want to calculate each formula, finding the number obtained as a result of each calculation.
    I wrote something like this:
    DECLARE
    TYPE T_FormulasNum IS TABLE OF A.TX_FORMULA%TYPE
    INDEX BY BINARY_INTEGER;
    TYPE T_MontoIndicador IS TABLE OF A.MT_NUMBER%TYPE
    INDEX BY BINARY_INTEGER;
    V_FormulasNum T_FormulasNum;
    V_MontoIndicador T_MontoIndicador;
    BEGIN
    SELECT DISTINCT CD_INDICADOR,
    TX_FORMULA_NUMERICA
    BULK COLLECT INTO V_CodIndicador, V_FormulasNum
    FROM A;
    FORALL i IN V_FormulasNum.FIRST..V_FormulasNum.LAST
    EXECUTE IMMEDIATE
    'BEGIN
    :1 := TO_NUMBER(:2);
    END;'
    USING V_FormulasNum(i) RETURNING INTO V_MontoIndicador;
    END;
    But I'm getting the following messages:
    ORA-06550: line 22, column 43:
    PLS-00597: expression 'V_MONTOINDICADOR' in the INTO list is of wrong type
    ORA-06550: line 18, column 5:
    PL/SQL: Statement ignored
    ORA-06550: line 18, column 5:
    PLS-00435: DML statement without BULK In-BIND cannot be used inside FORALL
    Any Idea to solve this problem ?
    Thanks in Advance !!

    Hallo,
    many many errors...
    1. You can use FORALL only in DML operators, in your case you must use simple FOR LOOP.
    2. You can use bind variables only in DML- Statements. In other statements you have to use literals (hard parsing).
    3. RETURNING INTO - Clause in appropriate , use instead of OUT variable.
    4. Remark: FOR I IN FIRST..LAST is not fully correct: if you haven't results, you get EXCEPTION NO_DATA_FOUND. Use Instead of 1..tab.count
    This code works.
    DECLARE
    TYPE T_FormulasNum IS TABLE OF VARCHAR2(255)
    INDEX BY BINARY_INTEGER;
    TYPE T_MontoIndicador IS TABLE OF NUMBER
    INDEX BY BINARY_INTEGER;
    V_FormulasNum T_FormulasNum;
    V_MontoIndicador T_MontoIndicador;
    BEGIN
    SELECT DISTINCT CD_INDICATOR,
    TX_FORMULA_NUMERICA
    BULK COLLECT INTO V_MontoIndicador, V_FormulasNum
    FROM A;
    FOR i IN 1..V_FormulasNum.count
    LOOP
    EXECUTE IMMEDIATE
    'BEGIN
    :v_motto := TO_NUMBER('||v_formulasnum(i)||');
    END;'
    USING OUT V_MontoIndicador(i);
    dbms_output.put_line(v_montoindicador(i));
    END LOOP;
    END;You have to read more about bulk- binding and dynamic sql.
    HTH
    Regards
    Dmytro
    Test table
    a
    (cd_indicator number,
    tx_formula_numerica VARCHAR2(255))
    CD_INDICATOR TX_FORMULA_NUMERICA
    2 (5+5)*2
    1 2*3*4
    Message was edited by:
    Dmytro Dekhtyaryuk

  • Dynamic SQL and Sub Query

    I want need to use dynamic SQL, and include a subquery in the where clause.  However, I am getting a syntax error.
    I have code that looks like this.
        SELECT (p_v_sqlobj_select)
            INTO CORRESPONDING FIELDS OF TABLE <matrix>
          FROM (p_v_sqlobj_from)
          WHERE (p_v_sqlobj_where).
    and I pass it the following bold-faced SQL where clause (please ignore whether the statement makes sense and is the best way to do it - this is just to illustrate).   However, it returns an error.
    select tcode from tstc where tcode in <b>( select min( tcode ) as min from tstc )</b>
    Am I correct in concluding that I cannot pass complex statements, or have I just missed something?
    Thanks for any help.

    Hi,
    Please try with order by clause in select statement and also use descending
          select * from (p_table)
                   into corresponding fields of table <ptab>
                  up to p_rows rows
                  order by <fieldname> descending.
    aRs

  • Difference in behavior of sql and pl/sql after migrating from 9i to 11g

    after migrating our database from oracle 9i to oracle11g, the developpers are worry that the behavior of the queries and pl/sql procedures/functions will change
    example :
    in 9i, select salary,count(*) from emp group by salary, it will display the rows sorted by salary
    in 11gi, select salary,count(*) from emp group by salary, it will display the rows not sorted by default, we have to add the clause order by salary.
    somebody could give the list of other difference in behavior (SQL and PL/SQL) agter migrating from 9i to 11g
    Thanks a lot.

    Tell your developers: garbage in - garbage out. In relational databases only ORDER BY ensures row order. If your developers relied on GROUP BY implemented by SORT and therefore returning ordered rows they had to realize code they wrote is Oracle release dependent and sooner or later code would require changes. And that "sooner or later" is now reality. In newer versions ORACLE can do GROUP BY via SORT or via HASH. And if it is done via HASH - don't expect ordered results. So tell your developers "payback time".
    SY.

  • How to execute PL/SQL and branch in APEX 3.0

    I have written an APEX app with the following pages:
    1 - Main page with a "start" button that navigates to page 2
    2 - Page with a Branch "Branch to function returning a page", which has PL/SQL that returns '3' if successful or '4' if there is an error
    3 - Page with HTML to display "Success"
    4 - Page with HTML to display "Error"
    I wrote this as a very simple test to verify how to implement a button to execute a block of PL/SQL and then go to a results page. So, there is almost nothing to it right now - just the four pages described and a small PL/SQL block that actually will always fail because it SELECTs from a table that does not yet exist. The problem is that when I click the button it goes to page 2 properly (the page displays) but I can't tell if the PL/SQL is executed and it does not leave that page. What am I doing wrong? Any help would REALLY be appreciated!

    That's somewhat more complicated. If you create a Page Process (your 'long running process') that fires On Load - After Footer you won't see anything until it's finished.
    So you need an AJAX function to kick off an Application Process and call this AJAX function in the OnLoad of the BODY... And yes, you can show a progress bar or something similar then by checking if your AJAX function is finished yet.
    If you want to go that way you can search this forum on "AJAX ONLOAD" or something similar (or start a new thread).
    Cheers
    Roel

  • Writing into Excel file using PL/SQL and formatting the excel file

    Hi,
    I am writing into a excel file using PL/SQL and I want to make the first line bold on the excel. Also let me know if there are any other formatting options when writing into excel.
    Regards,
    -Anand

    I am writing into a excel file using PL/SQL
    Re: CSV into Oracle and Oracle into CSV
    check that thread or search in this forum...

Maybe you are looking for