How to insert a sql query statement in the table

I have a stored procedure which has different insert,update statements on different tables. I am writing a trigger on these tables such that when the record is updated or inserted in these tables a trigger should fire and should write the old value,new value and the query (insert or update) that caused the trigger to fire in the seperate table. Is there any way to find out the exact query statement that fired the trigger?

Rather than inventing your own demi-donkeyed solution I recommend you consider using Oracle's Fine-Grained Auditing which does precisely this.
Cheers, APC

Similar Messages

  • Give me the sql query which calculte the table size in oracle 10g ecc 6.0

    Hi expert,
    Please  give me the sql query which calculte the table size in oracle 10g ecc 6.0.
    Regards

    Orkun Gedik wrote:
    select segment_name, sum(bytes)/(1024*1024) from dba_segments where segment_name = '<TABLE_NAME>' group by segment_name;
    Hi,
    This delivers possibly wrong data in MCOD installations.
    Depending on Oracle Version and Patchlevel dba_segments does not always have the correct data,
    at any time esp. for indexes right after being rebuild parallel (Even in DB02 because it is using USER_SEGMENTS).
    Takes a day to get the data back in line (never found out, who did the correction at night, could be RSCOLL00 ?).
    Use above statement with "OWNER = " in WHERE for MCOD or connect as schema owner and use USER_SEGMENTS.
    Use with
    segment_name LIKE '<TABLE_NAME>%'
    if you like to see the related indexes as well.
    For partitioned objects, a join from dba_tables / dba_indexes to dba_tab_partitions/dba_ind_partitions to dba_segments
    might be needed, esp. for hash partitioned tables, depending on how they have been created ( partition names SYS_xxxx).
    Volker

  • Neea a sql query for inverting the table

    Hi,
    I am facing the problem in forming a SQL statement in oracle 10g
    Table structure:
    user field1 field2 field3 field4 field5 field6 .......
    one 11 12 13 14 15 16
    two 21 22 23 24 25 26
    three 31 32 33 34 35 36
    i want a SQL query where the out put is
    field1 11 21 31
    field2 12 22 32
    field3 13 23 33
    field4 14 24 34
    Regards,
    Balu CH

    check this Forums page
    <http://forums.oracle.com/forums/search.jspa?threadID=&q=Rows+to+Columns&objID=f75&dateRange=last90days&userID=&numResults=15>
    will help u.
    Rgds
    Sudar

  • How to execute an SQL query present in a string inside an ABAP program?

    hello,
    How to execute an SQL query present in a string inside an ABAP program

    Raut,
    You can execute Native SQl statements.
    Ex: To use a Native SQL statement, you must precede it with the EXEC SQL statement, and follow it with the ENDEXEC statement as follows:
    EXEC SQL [PERFORMING <form>].
      <Native SQL statement>
    ENDEXEC.
    There is no period after Native SQL statements. Furthermore, using inverted commas (") or an asterisk (*) at the beginning of a line in a native SQL statement does not introduce a comment as it would in normal ABAP syntax. You need to know whether table and field names are case-sensitive in your chosen database.
    In Native SQL statements, the data is transported between the database table and the ABAP program using host variables. These are declared in the ABAP program, and preceded in the Native SQL statement by a colon (:). You can use elementary structures as host variables. Exceptionally, structures in an INTO clause are treated as though all of their fields were listed individually.
    If the selection in a Native SQL SELECT statement is a table, you can pass it to ABAP line by line using the PERFORMING addition. The program calls a subroutine <form> for each line read. You can process the data further within the subroutine.
    As in Open SQL, after the ENDEXEC statement, SY-DBCNT contains the number of lines processed. In nearly all cases, SY-SUBRC contains the value 0 after the ENDEXEC statement. Cursor operations form an exception: After FETCH, SY-SUBRC is 4 if no more records could be read. This also applies when you read a result set using EXEC SQL PERFORMING.
    EXEC SQL PERFORMING loop_output.
      SELECT connid, cityfrom, cityto
      INTO   :wa
      FROM   spfli
      WHERE  carrid = :c1
    ENDEXEC.
    Pls. Mark If useful

  • How to get physical SQL query

    Hi All,
    How to get the physical SQL query for the OBIEE reports.
    Thanks in advance,
    Haree.

    Hi Anitha,
    Thanks for your reply,
    I am getting XML script in log file. (Settings > Administration > Manage Sessions > View Log).
    How to get physical SQL query ?
    Thanks,
    Haree

  • How to tune past SQL query??

    Hi Team,
    Straight to issue --> I am seeing an query running for long time. When i begun to trace that particular query it got over by the time and now how to trace that specific SID and QUERY..
    I am working on 10.2.0.4 version DB..
    How to trace an sql query after its execution?? pls provide steps how to begin with..
    regards
    dkoracle

    dkoracle wrote:
    Hi Team,
    Straight to issue --> I am seeing an query running for long time. When i begun to trace that particular query it got over by the time and now how to trace that specific SID and QUERY..
    I am working on 10.2.0.4 version DB..
    How to trace an sql query after its execution?? pls provide steps how to begin with..Can not be done.
    ALTER SESSION SET SQL_TRACE=TRUE;
    -- run query again

  • How to write a sql query to retrieve data entered in the past 2 weeks

    Hi,
    I have file names and last accessed date(java.sql.Date format) stored in my database table, I would like to know how I can write a query to get the name of files accessed in the past 2 weeks,I use open sql server at the back end.
    Thanks in advance.

    This has essentially nothing to do with JDBC. JDBC is just an API to execute the SQL language using Java and thus interact with the databases.
    Your problem is related to the SQL language, you don't know how to write the SQL language. I suggest you to go through a SQL tutorial (there is one at w3schools.com) and to read the SQL documentation which come along with the database in question. A decent database manfacturer has a website and probably also a discussion forum / mailinglist as well.
    I'll give you a hint: you can just use equality operators in SQL like everywhere. For example: "WHERE date < somedate".

  • How to write a SQL query in SAP B1 2007 B with input parameters?

    How to write a SQL query in SAP B1 2007 B with input parameters, on execution of which will ask for some input value from the user and the values will be selected from a list such as item list?

    The syntax like
    SELECT * FROM OITM T0 WHERE T0.ItemCode = '[%0\]'
    Thanks,
    Gordon

  • How to execute this SQL Query in ABAP Program.

    Hi,
    I have a string which is the SQL Query.
    How to execute this sql Query (SQL_STR) in ABAP Program.
    Code:-
    DATA: SQL_STR type string.
    SQL_STR = 'select * from spfli.'.
    Thanks in Advance,
    Vinay

    Hi Vinay
    Here is a sample to dynamically generate a subroutine-pool having your SQL and calling it.
    REPORT dynamic_sql_example .
    DATA: BEGIN OF gt_itab OCCURS 1 ,
    line(80) TYPE c ,
    END OF gt_itab .
    DATA gt_restab TYPE .... .
    DATA gv_name(30) TYPE c .
    DATA gv_err(120) TYPE c .
    START-OF-SELECTION .
    gt_itab-line = 'REPORT generated_sql .' .
    APPEND gt_itab .
    gt_itab-line = 'FORM exec_sql CHANGING et_table . ' .
    APPEND gt_itab .
    gt_itab-line = SQL_STR .
    APPEND gt_itab .
    gt_itab-line = 'ENDFORM.' .
    APPEND gt_itab .
    GENERATE SUBROUTINE POOL gt_itab NAME gv_name MESSAGE gv_err .
    PERFORM exec_sql IN PROGRAM (gv_name) CHANGING gt_restab
    IF FOUND .
    WRITE:/ gv_err .
    LOOP AT gt_result .
    WRITE:/ .... .
    ENDLOOP .
    *--Serdar

  • How to insert into SQL server table form oracle forms

    I created a form with oracle as my database. But there one trigger where I need to insert the data into a sql server table.
    Is this possible. If so can any help me out.
    Thanks in advance.
    Asha

    Hi,
    You can insert into sql server database using the following steps
    Note: Check wether you are using Forms 32 bit drivers. If not the Odbc data source will not work.
    step 1: Create ODBC data source for SQL server(one time creation);
    step 2: Logout from Oracle and login to SQL server giving the user name,password and host string as odbc:<odbc datasource name>;
    step 3: use EXEC SQL statement to insert the values into the SQL server and then logout and login again to your oracle database.
    Second Method.
    Check the sql server documentation to insert the values using command line parameters. Then you can call the host command to execute this.
    Third Method.
    Write a VB exe to enter the values in the sql server making two connections one to oracle another to SQL server and then getting values from Oracle and putting in the SQL server database. You can call this exe using the Host command.
    Hope this will help You.
    Regards
    Gaurav Thakur

  • How to build an SQL Query to print Week ranges of a Month

    Hi Gurus!!
    I have a requirement to create a query to display the Week periods of a month.
    The inputs will be Year and month.
    The result should be some thing like this:
    If Year = 2009 and Month = June
    The SQL Query should return the following:
    01-Jun-2009 to 06-Jun-2009
    07-Jun-2009 to 13-Jun-2009
    14-Jun-2009 to 20-Jun-2009
    21-Jun-2009 to 27-Jun-2009
    27-Jun-2009 to 30-Jun-2009
    I am confused how to do this. Please help me. Any help would be grately Appreciated.
    Thanks
    Ahmed

    This is how My Final Query Looks Like:
    SELECT TO_CHAR(SYSDATE+7*(level-1),'DD-MON-RRRR')
    ||' to '
    ||TO_CHAR(SYSDATE+7*(level-1)+6,'DD-MON-RRRR') RANGES
    FROM dual
    connect by level<=5
    --Ahmed                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How Can I find SQL Query in Database

    Dear Experts,
    How Can I find SQL Query in Database.

    Hi,
    U mena what query got executed in db? u can try V$SQL for it.
    Regards
    Bharath

  • How to retrieve generated sql query from interface using groovy

    Hi All,
    I'm new to odi and i need the generated sql query code from the interface using groovy.

    Hi All,
    I'm new to odi and i need the generated sql query code from the interface using groovy.

  • SQL query to populate the records, the maximum processed should be less than 10 records per week.

    Dear All,
    I have a requirement, to write a SQL query to populate the records which are inserted less than 10 no of records.
    The tables has the cretaed_date column and along with other key column which will have unique values.
    Ex1:  The user might have inserted records from application, per week basis, between the date range '01-jun-2013' - 08-jun-2013  , the no of records created by the user during this week may be less than 10 records or more.
    But I want to populate the records by giving date range that too, it should pick the records the count which fall with in 10 records.
    I dont want the query to populate the records if the user has inserted more than 10 records in a week.
    Ex2:
    User 1 has created 15 records during the week 1 ( the query should not populate this ).
    User 2: has cretaed less than 10 records from the UI during the week 2. ( This details should get populated ).
    Thanks

    Use COUNT to find how many rows where inserted in a week.
    If this does not answer your question then please read Re: 2. How do I ask a question on the forums? And provide necessary details.

  • Sql query to achive the running division

    Hi all, plz help me out with the sql query to achive the below output
    create table emp_a (empno number, deptno number, sal number)
    insert into emp_a values(901, 10,100);
    insert into emp_a values(902, 10,400);
    insert into emp_a values(901, 20,300);
    insert into emp_a values(902, 20,2100);
    i want the ouput in below format
    empno deptno sal div_sal
    901 10 100 (300/100)
    901 20 300 (300/100)
    902 10 400 (2100/400)
    902 20 2100 (2100/400)
    the div_sal column should have the output of greatest sal/second smallest sal for each empno

    Hi,
    781649 wrote:
    Hi all, plz help me out with the sql query to achive the below output
    create table emp_a (empno number, deptno number, sal number)
    insert into emp_a values(901, 10,100);
    insert into emp_a values(902, 10,400);
    insert into emp_a values(901, 20,300);
    insert into emp_a values(902, 20,2100);
    i want the ouput in below format
    empno deptno sal div_sal
    901 10 100 (300/100)
    901 20 300 (300/100)
    902 10 400 (2100/400)
    902 20 2100 (2100/400)
    the div_sal column should have the output of greatest sal/second smallest sal for each empnofor empno=901, then second smallest sal is 300. For empno=902, the second smallest sal is 2100.
    Instead of "second *smallest* ", do you mean "second *greatest* "?
    What if there's a tie (e.g.
    INSERT INTO emp_a (empno, deptno, sal) VALUES (903, 10, 300);
    INSERT INTO emp_a (empno, deptno, sal) VALUES (903, 20, 300);
    INSERT INTO emp_a (empno, deptno, sal) VALUES (903, 30, 200);) Would you count 200 or 300 as the second greatest?
    Here's one way:
    WITH     got_r_num     AS
         SELECT     empno, deptno, sal
         ,     ROW_NUMBER () OVER ( PARTITION BY  empno
                                   ORDER BY          sal     DESC
                           )         AS r_num
         FROM    emp_a
    SELECT       e.empno
    ,       e.deptno
    ,       e.sal
    ,       '(' || TO_CHAR (r1.sal)
               || '/'
               || TO_CHAR (r2.sal)
               || ')'          AS div_sal
    FROM       emp_a           e
    JOIN       got_r_num     r1  ON      e.empno     = r1.empno
    JOIN       got_r_num     r2  ON   e.empno     = r2.empno
    WHERE       r1.r_num     = 1
    AND       r2.r_num     = 2
    ;

Maybe you are looking for

  • Cant install os x after erase ssd on macbook pro retina display

    i cant reinstall os x after i erase my ssd. it says restoring from internet but didnt work

  • Problem with Access 2000

    Hi everyone, I have a problem to update information for a table in Access 2K that contains spaces in the field's name. e.g. Main Phone instead of MainPhone. I can hear right then a bunch of people who will suggest to change the field name right away.

  • Shared shows an unrecognized user on my network

    Hi there, I recently purchased my first Mac (Macbook Pro) running Leopard. I have a home network currently shared with a PC. In finder under "shared" it shows my PC and I can access the shared files there. But it also shows another user called "user3

  • Can you programmatically change properties of the Detailed Navigation?

    Is there an SAP EP6.0 API call to allow one to programmatically change the width of the Detailed Navigation, or programmatically hide or unhide it?  I realize that this can be preset, but I am interested in dynamically changing these values. Thanks,

  • Can't install OS, computer keeps crashing.  Ideas?

    I am trying to do a fresh install of OSX 10.4 on my G5 Quad.  I put the install disc into the DVD slot and restarted the computer as directed.  But the computer will not restart, I keep getting a gray screen that starts off with "unresolved kernel tr