Two triggers on same table

Hi Friend.
I have to write two triggers on same table for auditing different columns of different users(may be different modules).
I will have an audit table in which i will insert data such as (user_id,module_id,column_name,old_col_val,new_col_val,timestamp)
Now different users from different modules will update the data on same table may be same columns from different front end forms!
If we write directly, we will not be able to know which column is updated by which user.
My question is in this case how can we control the triggers to raise differently?

You can use WHEN clause to fire a trigger only when some condition is true - you can check an user also,
look at simple example:
- suposse we have two users US1 and US2:
C:\>sqlplus sys as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Pn Gru 6 13:14:22 2010
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Enter password:
Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> create user us1 identified by us1;
User created.
SQL> create user us2 identified by us2;
User created.
SQL> grant connect, resource to us1, us2;
Grant succeeded.
SQL> grant create public synonym to us1, us2;
Grant succeeded.and suposse we have a table with three columns + audit table:
SQL> connect us1
Enter password:
Connected.
SQL> create table tab123(
  2  col1 number,
  3  col2 number,
  4  col3 number);
Table created.
SQL> create table audit_tab123(
  2  username varchar2(100),
  3  col1 number,
  4  col2 number,
  5  col3 number );
Table created.
SQL>  grant select, update, insert on tab123 to us2;
Grant succeeded.
SQL>  grant select, update, insert on audit_tab123 to us2;
Grant succeeded.
SQL> create public synonym tab123 for tab123;
Synonym created.
SQL> insert into tab123 values( 1, 1, 1 );
1 row created.
SQL> commit;
Commit complete.We want a trigger that is fired only by user US1 and only after update of COL1 and COL2
(COL3 is ignored):
SQL> connect us1/us1
Connected.
SQL> CREATE OR REPLACE TRIGGER Trig_123_US1
  2  AFTER UPDATE OF col1, col2 ON tab123
  3  FOR EACH ROW
  4  WHEN ( user = 'US1' )
  5  BEGIN
  6    INSERT INTO audit_tab123( username, col1, col2 )
  7    VALUES( user, :new.col1, :new.col2 );
  8 END;
SQL> /
Trigger created.And we want a second trigger that is fired only by user US2 and only after update of COL2 and COL3
(COL1 is ignored):
SQL> connect us1/us1
Connected.
SQL> CREATE OR REPLACE TRIGGER Trig_123_US2
  2  AFTER UPDATE OF col2, col3 ON tab123
  3  FOR EACH ROW
  4  WHEN ( user = 'US2' )
  5  BEGIN
  6    INSERT INTO audit_tab123( username, col2, col3 )
  7    VALUES( user, :new.col2, :new.col3 );
  8  END;
  9  /
Trigger created.and now let test our triggers:
SQL> connect us1/us1
Connected.
SQL> update tab123 set col1 = 22;
1 row updated.
SQL> update tab123 set col2 = 22;
1 row updated.
SQL> update tab123 set col3 = 22;
1 row updated.
SQL> commit;
Commit complete.
SQL> select * from audit_tab123;
USERNAME         COL1       COL2       COL3
US1                22          1
US1                22         22
SQL> connect us2/us2
Connected.
SQL> update tab123 set col1 = 333;
1 row updated.
SQL> update tab123 set col2 = 333;
1 row updated.
SQL> update tab123 set col3 = 333;
1 row updated.
SQL> commit
  2  ;
Commit complete.
SQL> select * from us1.audit_tab123;
USERNAME         COL1       COL2       COL3
US1                22          1
US1                22         22
US2                          333         22
US2                          333        333As you see, each trigger is fired only once, first triger only for user US1 and columns COL1 and COL2,
and second trigger only for user US2 and only after update of COL2 and COL3.
I hope this will help.

Similar Messages

  • How to write two triggers on same table how it works?

    Hello sir..
    I have to write two triggers on same table for auditing different columns of different pages (may be different modules).
    I will have an audit table in which i will insert data such as (user_id,module_id,column_name,old_col_val,new_col_ val,timestamp)
    Now different users from different pages will update the data on same table may be same columns!
    If we write directly, we will not be able to know which column is updated from different pages.
    My question is how can we control the triggers to raise based on the pages

    A trigger is executed whenever the table is inserted / updated / deleted (depend on trigger definition). It won't know what 'page' caused the operation. You can prepare a trigger for one page.
    In order to fulfill your need, you need some way to tell the trigger where you are. There are many ways to accomplish this. Some possible methods are (please check the documents for detail)
    DBMS_SESSION.SET_IDENTIFIER
    DBMS_APPLICATION_INFO.SET_MODULEFor example, you can call DBMS_SESSION.SET_IDENTIFIER to set an ID from your page, and then call sys_context to read the ID back:
    In Page:
    exec dbms_session.set_identifier('Page1');
    ...In Trigger
    pageid  := sys_context('USERENV', 'CLIENT_IDENTIFIER') ;
    ...Note that if you use a connection pool, you may need to properly reset the session information before return, in order to avoid messing up the session information when the connection is used next time.

  • Compare two rows in same table

    Hi,
    I want to compare two rows (some columns) in the same table, and if the data in the data columns is different, I want to pick the latest one. The table is date tracked. For instance I have an address table with different addresses for an employee with effective date. I want to be able to pick the latest row if the postal code is different for the 2 rows. Is this possible in sql. I can do this in Pl/sql, but dont want to use it. Eg
    address_id, postal_code, person_id,last_update_date
    123, pn123,1,12-JAN-01
    124,pu124,1,13-JAN-01
    I want to be able to retrieve just the second line.
    Any help is appreciated

    Welcome to the forum!
    Whenever you post please provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION).
    >
    The table is date tracked. For instance I have an address table with different addresses for an employee with effective date. I want to be able to pick the latest row if the postal code is different for the 2 rows.
    >
    Your question is a little confusing because you are using terms like 'date tracked' and 'effective date' without explaining exactly what your definitions of those terms is.
    Why do you want the latest record ONLY if the postal code is different? What if the address is different? Then which record do you want?
    Why not just take the record for each person/company that has the latest date? If the data is the same then it doesn't which record you get so the one with the latest date will do. And if the data is different taking the one with the latest date gives you the latest data.
    The classic definition of effective date is 'the date the information becomes effective'. Information with a given effective date is NOT in effect before that date and is SUPERCEDED when data is entered with a later effective date if the actual date is later than or equal to the effective date. Using your data
    >
    123, pn123,1,12-JAN-01
    124,pu124,1,13-JAN-01
    >
    The first record IS NOT effective for dates prior to 12-JAN-01. In fact for a query looking for data prior to that date there isn't any data.
    The first record is also NOT effective for dates on or after 13-JAN-01. Only the second record is effective.
    If you added a record for 14-JAN-01 this record would not be effective until on or after that date (i.e. not for another 4 1/2 months).
    So for the classic definition of effective date the query needs to provide the AS OF date to use to obtain the data. If, as in your system, you are not allowed to create records with dates in the future and you just want the latest record then you can just select the record with the MAX(myDate) value for the given person_id, address_id or whatever your key values are.
    Edited by: rp0428 on Aug 11, 2012 7:50 AM

  • Create ViewCriteria comparing two columns from same table

    Does anyone know how I can create a ViewCriteria where clause that compares two columns from the same table?
    For example if I had two integer columns (MINSAL and MAXSAL) and wanted to see if they are equal. I would normally do the following SQL below.
    SELECT * FROM EMPL
    WHERE MINSAL = MAXSAL

    It works, but it is not ideal.
    Setup a Transient column that performs a groovy evaluation of MINSAL=MAXSAL and then my ViewCriteria evaluates the column to true and I set Query Execution Mode to Both.

  • Link two identical databases, same tables, same fields

    Post Author: CathyH
    CA Forum: Data Connectivity and SQL
    I have two Accpac databases (two different companies, one Canadian one US).  I have created the same report for both companies using their respective data tables and another where I have converted the US funds to Canadian. 
    I would now like to create one report that links the two companies. 
    I will be sorting on Customer.  Whenever a customer is set up in the US company a duplicate is set up in the Canadian company but Canadian customers are not duplicated in the US company (it's just something we have to do for billing purposes) so there will always be many more Canadian customers.
    I would like the report to add together any matching customers in the US and Canadian companies but also report the customers that are strictly Canadian.
    Can anyone help me?  Please!
    Cathy

    Post Author: synapsevampire
    CA Forum: Data Connectivity and SQL
    You might do this using advanced SQL on the database in a View or SP.
    Or another, somewhat fugly solution is to create a main report with the canadian database, group by the company, insert a subreport using the US database at the group level (header or footer), and link by the company.
    You can now respond to no rows in the subreport to indicate those that are not in the US database.
    Ain't purdy, but it'll work.
    -k

  • Two queries on same table in sender JDBC adapter

    Hi all..
    My requirement is as follows....
    query a table and fetch rows where column Error="true"
    If there are no records in the table satisfying the above condition ,i want to send a mail stating  that there are not records with error flag set to "true"
    But the problem is i wont get a message to PI if there are no records.
    If i write a query to get the count of records where column Error="true",Obviously the count would be zero. Using this message from database i can send a mail.
    Now please let me know if i can write both the queries in query SQL statement? if so howshould be the source structure?
    Thanks
    Ram..

    Hello ram,
                     As far as i know it is not possible to use two different SQL statements in the sender adapter, though you can try with the join statement.
    For further information refer this discussion
    [Multiple Select Possible?|How to call multiple SQL using the JDBC adapter;
    Regards,
    Prasanna

  • How to Concatenate two rows of same table

    Hi Friends
    I have table
    No Name Id
    1 Raju 6
    2 Dhanshree 7
    3 Shital 6
    4 Priya 7
    I want the query that should display
    Raju Dhanshree.
    Shital Priya
    That Means whenever 6,7 number come the query should Concatenate The name colume

    1 150 IEEE TRANSA CTIONS ON MICR O W A V E THEOR Y AND TECHNIQ UES, V OL. 50, NO. 1, J ANU AR Y 2002
    Times-Roman 4
    2 A Miniaturized MMIC Analog Phase Shifter Using
    Times-Roman 16
    3 T w o Quarter-W a v e-Length T ransmission Lines
    Times-Roman 16
    4 Hitoshi Hayashi
    Times-Roman 7
    5 , Member , IEEE
    Times-Italic 7
    6 , T adao Nakaga w a
    Times-Roman 7
    7 , Member , IEEE
    Times-Italic 7
    8 , and Katsuhik o Araki
    Times-Roman 7
    9 Abstract—
    Times-BoldItalic 6
    10 This paper describes a miniaturized monolithic-mi-
    Times-Bold 6
    11 cr o w a v e integrated-cir cuit (MMIC) analog phase shifter using tw o
    Times-Bold 6
    12 quarter-wa v e-length transmission lines. A con v entional analog
    Times-Bold 6
    13 phase shifter employs an analog phase-shifter topology using a
    Times-Bold 6
    14 3-dB 90
    Times-Bold 6
    15 branch-line h ybrid r equiring f our quarter-wa v e-length
    Times-Bold 6
    16 transmission lines. Thus, in the f irst stage of our study , w e
    Times-Bold 6
    17 pr esent a new analog phase-shifter topology using only tw o
    Times-Bold 6
    18 quarter-wa v e-length transmission lines. The phase shifter her e
    Times-Bold 6
    19 has only one-half as many transmission lines as a con v entional
    Times-Bold 6
    20 analog phase shifter using a 3-dB 90
    Times-Bold 6
    21 branch-line h ybrid, and the
    Times-Bold 6
    22 cir cuit can be miniaturized to less than one-f ourth as compar ed to
    Times-Bold 6
    23 the con v entional analog phase shifter . Furthermor e, we sho w that
    Times-Bold 6
    24 the operating fr equency range of the phase shifter is v ery wide and
    Times-Bold 6
    25 can obtain lar ge phase v ariation with small capacitance v ariation.
    Times-Bold 6
    26 Next, an experimental
    Times-Bold 6
    27 -band MMIC analog phase shifter is
    Times-Bold 6
    28 pr esented. A phase shift of mor e than 180
    Times-Bold 6
    29 and an insertion loss
    Times-Bold 6
    30 of 3.6
    Times-Bold 6
    31 1.1 dB ar e obtained at the fr equency range fr om 12 to
    Times-Bold 6
    32 14 GHz. The chip size of the experimental MMIC phase shifter is
    Times-Bold 6
    33 less than 3.0 mm
    Times-Bold 6
    34
    How will use on this data

  • Select column 1 into two column from same table

    Dear Sir
    I have a data like
    studid makr tottal credit total average mark semester
    251; 249.84; 41; 6.09; 1
    106; 285.32; 42; 6.79; 1
    285; 263.88; 38; 6.94; 1
    251; 202.40; 28; 7.23; 2
    106; 293.20; 39; 7.52; 2
    285; 228.14; 39; 5.85; 2
    I want to select average mark semester1 and semester 2 in different column
    studid   average_mark_  semester1 average_ mark_ semester_ 2
    251 6.09 7.23
    106 6.79 7.52
    285 6.94 5.85
    please help me
    regards
    sanat kumar
    thanks in advance

    Dear Sir,
    Thank u for your prompt answer.
    But I want to select student id and average mark based on semester
    out put supposed to be
    student id average_makr_sem1 average_mark_sem2
    251     6.09     7.23
    106     6.79     7.52
    285     6.94     5.85
    I want to select the average mark in different column based on semester
    Please look into
    thanks
    regards
    sanat

  • Combine 2 Queries (from SAME table) into a SINGLE query

    I have this two queries (from SAME table), and want to combine into one SINGLE query, how?
    How can we use CASE WHEN THEN for such situation? 
    Query1:
    SELECT t_inner.*,
    Floor(t_inner.ProductiveTime/ 3600) || 'hr:' || LPAD(Floor(Mod(t_inner.ProductiveTime,3600) / 60),2,0) || 'min:' AS Productive_Time,
    Floor(t_inner.OperatorDownTime/ 3600) || 'hr:' || LPAD(Floor(Mod(t_inner.OperatorDownTime,3600) / 60),2,0) || 'min:' AS OperatorDown_Time
    FROM
    (SELECT SYSTEMTYPE,
    sum(TIME_TEST + TIME_STEP) AS ProductiveTime,
    sum(TIME_IDLE) AS OperatorDownTime
    FROM PFODS.PPL_TESTSYSTEMS_UTILISATION
    WHERE (SYSTEMTYPE = '0005-072')
    AND (TS_START >= to_date('13/01/2014', 'DD/MM/YYYY'))
    AND TS_End <= to_date('17/01/2014', 'DD/MM/YYYY') + 1 + (1/1440) +(59/86400)
    AND MONO != '9999999999'
    GROUP BY SYSTEMTYPE ) t_inner
    Query 2:
    SELECT t_inner.*,
    Floor(t_inner.MachineDownTime/ 3600) || 'hr ' || LPAD(Floor(Mod(t_inner.MachineDownTime,3600) / 60),2,0) || 'min' AS MachineDown_Time
    FROM
    (SELECT SYSTEMTYPE,
    sum(TIME_IDLE) AS MachineDownTime
    FROM PFODS.PPL_TESTSYSTEMS_UTILISATION
    WHERE (SYSTEMTYPE = '0005-072')
    AND (TS_START >= to_date('13/01/2014', 'DD/MM/YYYY'))
    AND TS_End <= to_date('17/01/2014', 'DD/MM/YYYY') + 1 + (1/1440) +(59/86400)
    AND MONO = '9999999999'
    GROUP BY SYSTEMTYPE) t_inner
    see http://postimg.org/image/koq87iyyz/  and
    http://postimg.org/image/fv3zxa38n

    with the first query, 
    SELECT t_inner.*,
    Floor(t_inner.ProductiveTime/ 3600) || 'hr:' || LPAD(Floor(Mod(t_inner.ProductiveTime,3600) / 60),2,0) || 'min' AS Productive_Time
    FROM
    (SELECT SYSTEMTYPE,
    --sum(TIME_TEST) AS TIME_TEST,
    --sum(TIME_SYSTEM) AS TIME_SYSTEM,
    --sum(TIME_STEP) AS TIME_STEP,
    --sum(TIME_IDLE) AS TIME_IDLE,
    sum(TIME_TEST + TIME_STEP) AS ProductiveTime
    FROM PFODS.PPL_TESTSYSTEMS_UTILISATION
    WHERE (SYSTEMTYPE = '0005-072')
    AND (TS_START >= to_date('13/01/2014', 'DD/MM/YYYY'))
    AND TS_End <= to_date('17/01/2014', 'DD/MM/YYYY') + 1 + (1/1440) +(59/86400)
    AND MONO != '9999999999'
    GROUP BY SYSTEMTYPE) t_inner
    it gives output as from 
    http://postimg.org/image/koq87iyyz/
    with the second query,
    SELECT t_inner.*,
    Floor(t_inner.MachineDownTime/ 3600) || 'hr ' || LPAD(Floor(Mod(t_inner.MachineDownTime,3600) / 60),2,0) || 'min' AS MachineDown_Time
    FROM
    (SELECT SYSTEMTYPE,
    sum(TIME_IDLE) AS MachineDownTime
    FROM PFODS.PPL_TESTSYSTEMS_UTILISATION
    WHERE (SYSTEMTYPE = '0005-072')
    AND (TS_START >= to_date('13/01/2014', 'DD/MM/YYYY'))
    AND TS_End <= to_date('17/01/2014', 'DD/MM/YYYY') + 1 + (1/1440) +(59/86400)
    AND MONO = '9999999999'
    GROUP BY SYSTEMTYPE) t_inner
    it gives output as from 
    http://postimg.org/image/fv3zxa38n/
    I want to come those 2 queries into a single query, such that it gives both outputs as above. Let me know if you need any other information. thanks.

  • Two triggers in the same table and event

    If I created two triggers on the same table and event (before insert), which of them will be triggered first ?...
    The problem from the beginning is that I created the second one as after insert and in the body of the trigger I wrote (:new.xxx:= value) ... then an error (that it should be before insert trigger or update trigger), so I created it as before update ,,, but I have already before update trigger (for primary key)..... and the problem -I think- which of them start first...
    Can make the second one as after insert and make update statement instead of assigning (:new.xxx:= value).....
    Regards

    If I created two triggers on the same table and event
    (before insert), which of them will be triggered
    first ?...As already mentioned, prior to 11g the order of firing is undetermined.
    The problem from the beginning is that I created the
    second one as after insert and in the body of the
    trigger I wrote (:new.xxx:= value) ... then an error
    (that it should be before insert trigger or update
    trigger), so I created it as before update ,,, but I
    have already before update trigger (for primary
    key)..... and the problem -I think- which of them
    start first...If there is a conflict of interest inside the code then you will have to alter your design principle around this to cater for it. Also consider combining the code into a single before insert trigger to prevent any confusion.
    Can make the second one as after insert and make
    update statement instead of assigning (:new.xxx:=
    value).....Attempting to update or query the same table as is causing the trigger to fire will result in a mutating table error. You can't do this.

  • How can I align two different text row in the same table in two different way (one centered and the other one on the left)?

    Hi,
    I want to center two different text row that are in the same table but one on the center and the other one on the left. I put a <span> tag hoping that it has been overwhelmed the table's class properties The .bottomsel's font-family and the .Cig84's font-family and colour work but the text-align don't: they're both on the left.
    These are my source and CSS codes:
    Source:
    <table width="600" border="0">
      <tr>
        <td class="bottomref"><p><span class="bottomsel">| <a href="index.html" target="_self">Main</a> | <a href="about.html" target="_self">About</a> | <a href="clients.html" target="_self">Clients</a> | <a href="contact.html" target="_self">Contact</a> |</span><br />
          <span class="credits">Credits: <span class="Cig84">Cig84</span></span></p></td>
      </tr>
    </table>
    CSS:
    .bottomsel {
      text-align: center;
      font-family: Georgia, "Times New Roman", Times, serif;
    .credits {
      text-align: left;
    .Cig84 {
      color: #F00;
      font-family: "Comic Sans MS", cursive;

    Use paragraph tags with CSS classes.
    CSS:
         .center {text-align:center}
         .left {text-align:left}
    HTML:
    <table width="600" border="0">
      <tr>
        <td class="bottomref">
              <p class="center">This text is center aligned</p>
              <p class="left">This text is left aligned</p>
        </td>
      </tr>
    </table>
    Nancy O.

  • Two LOVs in same UIX page based on the same table

    Hi group,
    Recently I ran into a problem with a UIX page that has two LOVs based on the same database table. In Emp and Job terminology, here's what I tried to do.
    Suppose we have use the Employees and Jobs tables from the HR scheme with one small modification. Add a column called PREFERRED_JOB_ID of type VARCHAR2(10) which is exactly the same as JOB_ID. Hypothetically speaking, this column will be used to allow Employees to select their preferred job in case they want to change their jobs.
    Next, create business components in JDeveloper based on the Employees and Jobs table. In order to be able to generate the LOVs for Job and PreferredJob create two ViewObjects, one called JobsLookupView and one called PreferredJobsLookupView. These both need to be based upon the same Jobs EntityObject. Also include the Jobs EntityObject twice in the EmployeesView ViewObject and give one the alias PreferredJobs. Include the JobTitle attributes of Jobs and PreferredJobs in EmployeesView so they can contain the JobTitles selected in our future LOVs.
    Next create a ViewController project if it's not already there and enable JHeadstart on it. Create an Application Structure File and create the lookups for the two LOVs. When I run the application I see this happening:
    When I click the flashlight icon next to the PreferredJob LOV and select a job, the PreferredJob field is selected in the UIX page but no job title appears. When I next first select the Job LOV and select a new job and then select the PreferredJob LOV again and select a different job, the job that was selected in the Job LOV is now also entered in the PreferredJob field. When I make sure the PreferredJob field isn't required (remove the required="yes" property on the messageLovInput entry for PreferredJobTitle and remove the PreferredJobTitle field from the addRequiredRowItems list in the UIX page) I can save the changes I made in the Employees.uix page. The same JobId is stored in the database for Job and PreferredJob.
    This behaviour is probably due to cacheing issues because both LOVs and the EmployeesView ViewObject use one EntityObject for four values in three ViewObjects.
    So I then modified my model a bit. I created a new EntityObject called PreferredJobs based on the JOBS table. I modified the EmployeesView ViewObject to use this EntityObject for the PreferredJobTitle attribute and modified the PreferredJobsLookupView to use this EntityObject.
    I needed to modify a few things as well in the Application Structure File (which were prompts and whether or not the attribute should be visible in a table) and after regenerating I made sure the PreferredJob attribute isn't required in the UIX page. When I then run the application again, I never see the JobTitle I select in any LOV allthough the PreferredJob field is selected when I select a Job in the PreferredJob LOV. The correct JobId now is stored in the database though.
    Has anyone ever encoutered this behaviour? Would anyone know how to get two LOVs based on the same table in one UIX page?
    Thanks in advance,
    Wouter van Reeven
    AMIS

    OK I figured it out. When I added the second Lookup ViewObject (PreferredJobs) no additional Association was created. Therefore, ADF BC wasn't able to figure out which field to update. When I added the Association between the PreferredJobs Lookup ViewObject and the Employees ViewObject everything started working ok.
    I then recreated my inital situation: one EntityObject for Jobs and one for Employees, now with two Associations between them. After modifying the Employees ViewObject and making sure the Jobs EntityObject was referred twice and via the corresponding Association, everything started working ok.
    Greets, Wouter
    AMIS

  • Triggers to Update rows in the same table

    Hi,
    I have a table called as "Cal" which has the following fields
    CALID
    Description
    RecurringID
    There will be many records with the same recurring id and If the Description field is Updated, then I would like to Update the same description to all the records with the same recurring id (same table). I have tried it with triggers and the I get the ORA-00036 Maximum number of Recursive SQL reached error.
    I have a a row level trigger which captures the change and I use the statment level trigger to update the description field (same table) and I get the error mentioned above.
    Thx in advance
    Ravi

    I have three kind of suggestion.
    (1) Use session variables in a package as flag for prevention from infinitely recursive calling.
    (2) Use temporary tables for similar reason.
    (3) Use instead-of-trigger (need to create view).

  • SUM two fileds from different rows from the same table

    I would like to SUM two fileds from different rows from the same table but I don't know how to do that.
    E.g.
    BillingTransactionsIndex      CreateDate      UserType      UserIndex      TransType      Reference      Total      Balance
    2      6/5/2008 15:02      1      51      1      150      -288.2      -288.2
    5      6/8/2008 11:55      1      51      1      157      -1.58674      -289.787
    In the table above I want SUM fields Total and Balance for the first row and the the next row SUM 2nd row Total with 1st row Balance
    Please help
    Thanks

    SQL> with tbl as
      2  (select 1 as ID,  90 as total from dual
      3          union all
      4  select 2 as ID,  23 as total  from dual
      5          union all
      6  select 3 as ID,  15 as total  from dual
      7          union all
      8  select 4 as ID,  20 as total  from dual)
      9  select id , total, sum(total) over (order by ID) as balance from tbl
    10  /
            ID      TOTAL    BALANCE
             1         90         90
             2         23        113
             3         15        128
             4         20        148
    SQL>

  • Compare two rows in a same table

    Dear all
    I need to compare two rows in the same table, I dont know hoe to do it in pl/sql. Some one please help me on this.
    example:
    tr br price
    xya0001 ama7 12
    xya0003 ama6 14
    xya0004 ama7 16
    in the table tr is a unique value for each row, I need to compare price column and see whether the first value is less or greater than the next value and, if it is greater put the corresponding br value to a variable and if it is smaller put the corresponding br value to another variable. I dont know a method to do it, as I'm new to pl/sql. Some one please help me in this

    not sure what you intend to do as you have mentioned that "TR" is unique and you just want to compare each record with just the next record. Hope below query helps. The value "G" or "L" in flag would indicate if the current records price is greater than or less than the price in next record.
    select tr,br,price,col4, case when price> col4 then 'G'  when price< col4 then 'L' end flag from (
    select tr,br,price,lag(price,1,0) over(order by tr) col4 from testcomp
    )

Maybe you are looking for

  • Messy Push Notifications on iPhone 4 running iOS 6.0.1

    Well guys, I have an iPhone 4 running iOS 6.0.1. Initially push notifications for all apps worked fine. I never missed a notification on any of the apps especially Facebook. I even got every notification about friends and pages I have liked on facebo

  • Multiple rows in a single table cell - Adobe forms

    Dear All I am developing an adobe form which conatins a table alongwith other screen/ form elements. This table is bound to a data node and contains only two columns. Number of rows will be determined at run time. Each cell of the table will contain

  • Lost recovery key and need to retrieve current data

    Yeah. It's a really nasty situation. In order to get back into Sync i have to generate a new recovery key But the recovery key generator will mangle the synced data. Is there any way to retrieve the data?. I haven't been able to sync with Firefox on

  • Tracking Advance to vendor PO item wise

    Hi I have PO 4500002343 with 4 line items. PO value is 10 crores and advance payment is 20% So i need to pay Rs. 2 Crores on entire PO (i.e 4 items) Is it possible to get the entry PO item wise (i.e 4 line item for advance of Rs.50 LAcs each) One opt

  • Install Trial Versions without a personal Adobe ID

    I have a question: I need to make a demo to a customer, so I need that they got installed Creative Cloud software, trial versions, for just one day, to up to 5 computers. I know that you can download a 30 day trial version using a free Adobe ID, but