Getting the average of two cols into third col when user inserts or updates

I hav a table with three column a,b,c.
now i have to insert the average of the col a & b into c when user inserts or updates
any of the row?
i tried using row level trigger for this but not workin fine..
can anybody of u give me an idea as how to proceed?
thanks in advance..

Sorry to be late to reply....
actually..for the trigger i used i got a mutating error.
if there is any other option for doing this,u teel me how.
i used the followin trigger and placed AT to avoid the mutating error.But still
create or replace trigger trg_xyz after insert or update of m1,m2
on xyz for each row
declare
v1 number;
pragma autonomous_transaction;
begin
v1 := (:new.m1+:new.m2)/2;
if inserting then
update set m3=v1 where m2=:new.m2 and m1=:new.m1;
elsif updating then
update set m3=v1 where m2=:new.m2 and m1=:new.m1;
end if;
commit;
end;
this does not throw any error, but doesnt inserts the value.i checked using dbms_output..i showed the average value for v1..but its not updating..

Similar Messages

  • How to get the difference between two columns in a column group

    Hi All,
    My first time here and really new to programming. I would like to get the difference between 2 columns that are inside 
    a column group.
    Here is my sample table below: The Column Group is PeriodNumber and can only choose 2. like 1 and 2.. I would like to have a third row which will simply calculate the difference between the amounts in PeriodNumber 1 and 2.
                                PeriodNumber          
    Account                    1                            2     
    1) Cash                10,000                15,000
    2) Receivables      12,000                11,500
    3) Equipment          5,000                  5,500
    Total Assets          27,000                32,000

    Hi yabgestopa,
    From your description, you want to get the difference between two columns in a column group. After testing it in my environment, we can use custom code to achieve your requirement. For more details, you can refer to the following steps:
    Copy the custom code below and paste it to your report. (Right-click report>Report Properties>Code)
    Dim Shared Num1 As Integer
    Dim shared Num2 As Integer
    Public Function GetAmount(Amount as Integer, Type as String)
    If Type = "1" Then
    Num1=Amount
    Else
    Num2=Amount
    End If
    Return Amount
    End Function
    Public Function GetDif()
    Return Num1-Num2
    End function
    Right-click the second column to insert a third column with Outside Group-Right.
    Then use the expressions below in the matrix.
    =Code.GetAmount(Fields!Amount.Value,Fields!PeriodNumber.Value)
    =code.GetAmount(Sum(Fields!Amount.Value),Fields!PeriodNumber.Value)
    =Code.GetDif()
    The report looks like below.
    If you have any questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • GETTING THE AVERAGE OF TIME

    Hi,I have the following code which returns day of week name, position and date and time of surgeries.
    SELECT
    DATENAME(WEEKDAY,OPE_START_TIME) AS DOW,
    [OPE_ORDER_IN_SESS_ASC] AS POSITION,
    OPE_START_TIME AS [TIME]
    FROM table1The data looks like thisHow can i group this data so I get the average start time by day of week and position?

    try this
    \declare @table table(c1 varchar(20),c2 int,c3 datetime2(0))
    insert into @table
    values('monday',1,'2015-04-29 02:09:42')
    ,('monday',1,'2015-04-29 02:05:42'),
    ('tuesday',1,'2015-04-29 02:59:42')
    ,('tuesday',2,'2015-04-29 02:55:42')
    ;with cte as (select avg(datepart(second,c3)+((datepart(minute,c3)+(datepart(hour,c3)*60))*60)) as c3
    ,c2,c1 from @table
    group by c1,c2)
    select right('0'+cast(c3/3600 as varchar),2)+':'+right('0'+cast((c3%3600)/60 as varchar),2)
    +':'+right('0'+cast((c3%3600)%60 as varchar),2) as [AvgTime],c2,c1 from cte
    Hope it Helps!!

  • Combine the data of two DSOs into one

    Hello experts,
    how to load the data of two DSOs into a single one using transformations and DTPs?
    Example:
    DSO A keyfields: X,Y,Z / attributes M,N,O
    DSO B keyfields: X,Y,Z / attributes P,Q
    DSO C keyfields: X,Y,Z / attributes M,N,O,P,Q  (result should be a single data record!)
    In the transformation between DSO A and C I map all keyfields and attributes M,N,O (no mapping for P and Q, meaning no transformation rule). For B to C mapping is all keyfields and attributes P, Q (no mapping for M,N,O, no transformation rule).
    When I now load the data of DSO A and DSO B to DSO C I either see the attributes M,N,O or P,Q. This means that only the latest DTP is available and overwrites the attributes with blank values of the first DTP.
    I have a solution using ABAP coding but according to the SAP Training courses (BW330) it should work without using ABAP coding.
    Any help is highly appreciated.
    Thanks in advance.
    Marco

    Hi Marco,
    Thanks again
    I looked into BW330 Business information warehouse - Modelling.
    Course version : 2006 Q2
    Material number : 50079531
    I looked into the page 281 still no luck.
    just an overview i need to create X,Y,Z,M,N,O as info objects characteristics
    and P, O  as infoobjects keyfigure.
    None of them will have attributes and i load XYZMNO to DSO1 and same XYZPO to DSO2.
    Then map DSO1 - DSO3 and  DSO2 - DSO3 and carry out the steps to get the data from DSO1 and DSO2 to DSO3.
    Am i right.
    Regards,
    Harish

  • I-photo:  I used 2 cameras to take pictures on a trip --- i have put the pictures from both cameras into an album --- when i click on view and then sort by date, the pictures do not sort by date --- any ideas on how to get the pics sorted by date?

    I-photo:  I used 2 cameras to take pictures on a trip --- i have put the pictures from both cameras into an album --- when i click on view and then sort by date, the pictures do not sort by date --- any ideas on how to get the pics sorted by date?

    Select all the photos that you need to change, then click the "Photos" menu and choose "Adjust Date and Time".
    If you add a year, it will adjust all the photos that you selected by adding a year (so if you accidentally select one of the photos that already has "2012", that will change to "2013"). 

  • I'm new to Mac and the program/all called Numbers. I'm trying to use both Average and small in the same formula. What's I'm trying to do is take 20 cells, find the 10 lowest numbers, then get the average and after that multiply it by .96

    I'm new to Mac and the program/all called Numbers. I'm trying to use both Average and small in the same formula. What's I'm trying to do is take 20 cells in a column,  find the 10 lowest numbers, then get the average and after that multiply it by .96  I used to use Excel and the formula worked fine in that. Here is my Formula
    =(average(small(H201:H220,{1,2,3,4,5,6,7,8,9,10})))*.96
    This formula worked in Excel and when I converted my spreadsheet over to Numbers, this formula no longer works.
    The best that I have been able to do so far is use small in 10 different cells, then get the average of the 10 cells and finally multiply that average by .96  So instead of using 1 cell, I'm using 12 cells to get my answer.
    This is a formula that I will be using all the time. The next cell would be =(average(small(H202:H221,{1,2,3,4,5,6,7,8,9,10})))*.96
    Hoping I explain myself well enough and that someone can help me.
    Thanks

    You can still do it in one cell but it will be more unruly than the Excel array formula.
    =average(small(H201:H220,1),small(H201:H220,2),small(H201:H220,3),...,small(H201:H220,10))*0.96
    where you would, of course, replace the "..." with the remaining six SMALL functions.

  • How do i get the music on my ipod into my itunes library on new computer

    how do i get the music from my ipod into my itunes library on new computer

    If they are all purchases from the iTunes Store you can transfer the purchases from your iPod to the library by following the steps here: http://support.apple.com/kb/HT1848

  • Getting the Source File name Info into Target Message

    Hi all,
    I want to get the Source file name Info into Target message of one of the fields.
    i followed Michal BLOG /people/michal.krawczyk2/blog/2005/11/10/xi-the-same-filename-from-a-sender-to-a-receiver-file-adapter--sp14
    Requirement :
    1) I am able to get the Target file name as same as the source file name when i check the ASMA in Sender & Receiver Adapter , with out any UDF...............this thing is OK
    2) I took One field extra in the target structure Like "FileName" & I mapped it Like
                              Constant(" " )--UDF-----FileName
    I Checked the Option ASMA in Both Sender & Receiver Adapters
    Here iam getting the Target File name as same as Source file name + Source File name Info in the Target Field " FileName".
    I Dont want to get the Target File name as same as Source file name. I want like Out.xml as Target file name.
    If i de-select the Option ASMA in Adapters means it is showing " null" value in the target field "FileName".
    Please Provide the Solution for this
    Regards
    Bopanna

    Hi All,
    Iam able to do this by checking the Option ASMA in only sender adapter itself
    Regards
    Bopanna

  • How to get the difference of two dates in years,months and days

    Hi friends,
    how to get the difference of two dates in years,months and days
    for ex 2 years 3 months 13 days
    select (sysdate-date_Start) from per_periods_of_service
    thanks

    Something like this...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select to_date('17-nov-2006','dd-mon-yyyy') as c_start_date, to_date('21-jan-2008','dd-mon-yyyy') as c_end_date from dual union all
      2             select to_date('21-nov-2006','dd-mon-yyyy'), to_date('17-feb-2008','dd-mon-yyyy') from dual union all
      3             select to_date('21-jun-2006','dd-mon-yyyy'), to_date('17-jul-2008','dd-mon-yyyy') from dual
      4             )
      5  -- end of test data
      6  select c_start_date, c_end_date
      7        ,trunc(months_between(c_end_date, c_start_date) / 12) as yrs
      8        ,trunc(mod(months_between(c_end_date, c_start_date), 12)) as mnths
      9        ,trunc(c_end_date - add_months(c_start_date, trunc(months_between(c_end_date, c_start_date)))) as dys
    10* from t
    SQL> /
    C_START_D C_END_DAT        YRS      MNTHS        DYS
    17-NOV-06 21-JAN-08          1          2          4
    21-NOV-06 17-FEB-08          1          2         27
    21-JUN-06 17-JUL-08          2          0         26
    SQL>But, don't forget that different months have different numbers of days, and leap years can effect it too.

  • How to get the intersection of two arraylist containing user defined obj??

    How to get the intersection of two arraylist containing user defined obj??
    I can easily get the intersection of two array list which containing some simple class(Integer, String). But how to get the intersection of two arrayList which contain user defined object?
    Here is the sample code..I can not run this out...anybody can help me? thank you very much..
    The correct result should be like this:
    2
    2
    but I can only get this:
    2
    0
    import java.util.*;
    public class testRetain{
         public static void main(String[] args){
              ArrayList a = new ArrayList();
              ArrayList b = new ArrayList();
              a.add( new dog(1,2,2) );
              a.add( new dog(1,2,1) );
    System.out.println(a.size() );
              b.add( new dog(1,2,2) );
              a.retainAll(b);
    System.out.println(a.size() );
    class dog implements Comparable{     
         int head;
         int arms;
         int legs;
         dog(int head, int arms, int legs){
              this.head = head;
              this.arms = arms;
              this.legs = legs;
         public int compareTo(Object o){
              if ( ((dog)o).head > this.head )
                   return -1;
              else if ( ((dog)o).head < this.head )
                   return 1;
              else
                   return 0;
    }

    @Op. Your classes should override equals and hashCode
    Kaj

  • How do you get the average of an array bigdecimels

    how do you get the average of an array bigdecimels... I am looping through the array in a for loop
    for (int i = 0; i < prItems.length; i++) {                                                                                                                                                                                                                                                                                                                  

    int sum = 0;
    for (int i = 0; i < prItems.length; i++) {
    sum = sum + prItems;
    int avg = sum/prItems.length;

  • Ibooks author, how do I get the standard book pages background into my document. I have published one book so far which does not display with a book pages background or options for font size.

    ibooks author, how do I get the standard book pages background into my document. I have published one book so far which does not display with a book pages background or options for font size.

    No on the book title, no problem there.
    The issue is: my book pages appear as on white paper, no background that resembles a open book and also no option to change fonts. The book was created in iBooks author, there was a problem going with the "Publish" menu route so I was instructed my Apple to "export" the file and submit that. I think that's the problem after reading that iBooks author is a hybrid epub file.
    Thanks for getting back to me.

  • Getting the length between two points

    Hi All,
    I am trying to get the distance between two points and came across the SDO_LENGTH function in the manual - however there is no example on how to use it.
    I was expecting the following statement to return me the value 9 but instead I am getting errors along the lines of SDO_GEOM.SDO_LENGTH must be declared etc.
    =============================================
    SDO_GEOM.SD0_LENGTH(
    MDSYS.SDO_GEOMETRY(2
    ,NULL
    ,NULL
    ,MDSYS.SDO_ELEM_INFO_ARRAY(1,2,1)
    ,MDSYS.SDO_ORDINATE_ARRAY(1,1,10,10))
    ,MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X',-180,180,0.0001)
    ,MDSYS.SDO_DIM_ELEMENT('Y',-90,90,0.0001))
    ============================================
    what am I missing
    any help appreciated
    Brent Glover

    I think I have found my answer
    ============================================
    DECLARE
    v_length NUMBER;
    BEGIN
    v_length := SDO_GEOM.SDO_LENGTH(
    MDSYS.SDO_GEOMETRY(2
    ,NULL
    ,NULL
    ,MDSYS.SDO_ELEM_INFO_ARRAY(1,2,1)
    ,MDSYS.SDO_ORDINATE_ARRAY(1,1,10,10))
    ,MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X',-180,180,0.0001)
    ,MDSYS.SDO_DIM_ELEMENT('Y',-90,90,0.0001))
    DBMS_OUTPUT.put_line(v_length);
    END;
    =============================================

  • How can i get the average graph?(DIAdem)

    hi,
    How can i get the average graph(2D-graph) of 10 measures?
    Can someone please help me?
    THX!!!

    Hello Charleen!
    If you want to do it programmatically have a look at the ChnAverage command in the help (see also StatBlockCalc for advanced calculations). Interactive you can use the statistic functions in the ANALYSIS device.
    Matthias
    Matthias Alleweldt
    Project Engineer / Projektingenieur
    Twigeater?  

  • When I stream a movie via Apple TV from my iPad Air into my Samsung TV, I'm getting the "soap opera" effect. This only happens when I use Apple TV, not when I view a movie directly through a cable channel. Is there a way to eliminate this effect?

    When I stream a movie via Apple TV from my iPad Air into my Samsung TV, I'm getting the "soap opera" effect. This only happens when I use Apple TV, not when I view a movie directly through a cable channel. Is there a way to eliminate this effect?

    I'm having the same problem.  It's not an issue with my TV, i've turned this feature off.  I've tried playing with the ATV display settings but nothing works.  When I stream netflix from my Samsung bluray player, I don't get the soap opera effect, but when I stream any video from the ATV, the soap opera effect is there.  I'm thinking it's a choice that Apple made, but I really wish it could be turned off.  Not a lot of people are searching for this, because it can be easy to overlook, but it's driving me nuts!

Maybe you are looking for