How to use trigger to catch the sum of a column is greater than 1

Here is my problem.
I create a table, which is preference( name char, percentage real);
the sum of the percentage for some user(name) should be 1;
And one user can have many records in the table as needed.
I should to validate the insert data which is valid after a series of insert operation? How can I do it?

Exactly what I was thinking:
SQL> create table preference
  2  (
  3  name varchar2(20),
  4  percentage number(3)
  5  );
Table created
SQL> create materialized view preference_mv
  2  refresh on commit
  3  as select name,sum(percentage) total_percentage
  4  from preference
  5  group by name;
Materialized view created
SQL> alter table preference_mv add constraint c_pref_pct check (total_percentage = 100);
Table altered
SQL> insert into preference values ('name1',25);
1 row inserted
SQL> insert into preference values ('name1',50);
1 row inserted
SQL> insert into preference values ('name1',25);
1 row inserted
SQL> commit;
Commit complete
SQL> insert into preference values ('name2',10);
1 row inserted
SQL> insert into preference values ('name2',30);
1 row inserted
SQL> commit;
commit
ORA-12008: error in materialized view refresh path
ORA-02290: check constraint (SCOTT.C_PREF_PCT) violatedSQL>

Similar Messages

  • How to find the sum of a column

    I need to find the sum of a column and use it in a different column. The following is the example.
    Column names: Feedback(Good, Avg, Poor), Count(no of good, no of avg, no of poor) and %age(Feedback/sum(feedback))
    I want to find the sum in Java class and also calculate the last column in java class.
    Please tell me some way to do it.

    oh.. ok ..thanks for letting me know.. i will formulate the question in a proper way:
    This is what my UI should look like:
    Rating Count Percent
    Excellent 2 20
    Good 6 60
    Poor 1 10
    Bad 1 10
    Now i have the following columns in the data base:
    Meaning and feedback_rating.
    So the following SQL Query:
    SELECT hrl.meaning rating,
    sum(decode(bcpi.feedback_rating, null, 0, 1)) counted
    from cmp_cwb_person_info bcpi ,
    hr_lookups hrl
    group by hrl.meaning
    will give me the result as
    rating counted
    Excellent 2
    Good 6
    Poor 1
    Bad 1
    Now I want a third column as percentage : Earlier we were doing this calculation in the sql query itself, so the query was like
    SELECT hrl.meaning rating,
    sum(decode(bcpi.feedback_rating, null, 0, 1)) counted,
    sum(decode(bcpi.feedback_rating, null, 0, 1))/(max (select count (*) from cmp_cwb_person_info bcpi ,
    hr_lookups hrl )) percent
    from cmp_cwb_person_info bcpi ,
    hr_lookups hrl
    group by hrl.meaning
    Hence the third column (percent) was calculated in the sql query itself.
    But now i feel that the performance of the query could be improved if we get the first two columns from the database and the calculate the third column programatically in the java code.
    So this is what I want to know. How can i do that?

  • Any one knows how to use Axis Framework in the SOAP Adapter Modules

    How to use Axis Framework in the SOAP Adapter?
    How to add custom handler modules?
    http://help.sap.com/saphelp_nw04/helpdata/en/45/a4f8bbdfdc0d36e10000000a114a6b/frameset.htm
    I went through the above link on help.sap.com. But still could not create a working example.
    I have created a wc on some 3ed party app server using apaches axis. I am trying to call that web service from XI using SOAP receiver? I need to add some security related headers to the soap message, SO I am trying to use a handler.  I want to know how to configure this handler in SOAP axis adapter module.
    Thank you
    Moni

    Ravi ,
    I am trying exactly the same. Hers is the scenario.
    ABAP Proxy --> PI (7.0) SP 12 ---> WebService.
    Since This is service is secured, means it is using OASIS web servie securyty user name token,
    I am trying to use AXIS adapter. and I want to configure HandlerBean in which I want to use apache wss4j api to add the userNameToken. I am looking for some documentation on this.
    I need to add SOAP action element too as I can not configure this one on the communication channel.
    Thanks for any inputs in this regard.
    Moni

  • How to use bind variables in the following query

    CREATE OR REPLACE PROCEDURE MMDB.test IS
    sel_qtn VARCHAR2 (10);
    CURSOR PT_QUANTITY IS select * from mmdb.product_tree WHERE QUANTITY_CHECK ='E'
    AND run_id = 100
    a PT_QUANTITY%ROWTYPE;
    BEGIN
    FOR i IN PT_QUANTITY
    loop
    sel_qtn := i.quanttity-1;
    While sel_qtn>=1
    loop
    insert into mmdb.product_tree (BILLING_ACCOUNT_NO ,S_CODE) values (i.BILLING_ACCOUNT_NO ,i.S_CODE||'E');
    sel_qtn :=sel_qtn -1;
    End loop;
    commit;
    end;

    Don't duplicate threads: How to use bind variables in the following query

  • How to use SQL functions in the queries

    hey guys i wanna know how to use SQL functions in the queries is it possible or not .

    Hi,
    Wat exactly that set values are?
    those from sql query?
    How to use count():
    The COUNT() function returns the number of rows that matches a specified criteria.
    SQL COUNT(column_name) Syntax
    The COUNT(column_name) function returns the number of values (NULL values will not be counted) of the specified column:
    SELECT COUNT(column_name) FROM table_name
    SQL COUNT(*) Syntax
    The COUNT(*) function returns the number of records in a table:
    SELECT COUNT(*) FROM table_name
    SQL COUNT(DISTINCT column_name) Syntax
    The COUNT(DISTINCT column_name) function returns the number of distinct values of the specified column:
    SELECT COUNT(DISTINCT column_name) FROM table_name
    The IN function helps reduce the need to use multiple OR conditions.
    The syntax for the IN function is:
    SELECT columns
    FROM tables
    WHERE column1 in (value1, value2, .... value_n);

  • [Forum FAQ] How to use parameter to control the Expand/Collapse drill-down options in SSRS report?

    In SQL Server Reporting Services (SSRS), drill-down is an action we can apply to any report item to hide and show other report items. They all are ways that we can organize and display data to help our users understand our report better. In this article,
    we are talking about how to use parameter to control the Expand/Collapse drill-down options in SSRS report.
    Consider that the report has a dataset (dsSales) with following fields: SalesTerritoryGroup, SalesTerritoryCountry, CalendarYear, SalesAmount.
    1. The report has the following group settings:
    Parent Group: SalesTerritoryGroup
     Child Group: SalesTerritoryCountry
      Child Group: CalendarYear
       Details: SalesAmount
    2. Add three parameters in the report:
    GroupExpand:
    Available Values: “Specify values”
    Label: Yes           Value: Yes
    Label: No            Value: No
    Default Values: “Specify values”
    Value: Yes
    CountryExpand:
    Available Values: “Specify values”
    Label: Yes           Value: =IIF(Parameters!GroupExpand.Value="No",Nothing,"Yes")
    Label: No            Value: No
    Default Values: “Specify values”
    Value: =IIF(Parameters!GroupExpand.Value="No","No","Yes")
    YearExpand:
    Available Values: “Specify values”
    Label: Yes          
    Value: =IIF(Parameters!GroupExpand.Value="No" or Parameters!CountryExpand.Value="No",Nothing,"Yes")
    Label: No            Value: No
    Default Values: “Specify values”
    Value: =IIF(Parameters!GroupExpand.Value="No" or Parameters!CountryExpand.Value="No","No","Yes")
    3. Right click SalesTerritoryCountry icon in the Row Groups dialog box, select Group Properties.
    4. Click Visibility in the left pane. Select “Show or hide based on an expression” and type with following expression:
    =IIF(Parameters!GroupExpand.Value="Yes", False, True)
    Select “Display can be toggled by this report item” option, and select “SalesTerritoryGroup” in the drop down list.
    5. Use the same method setting CalendarYear, (Details) drill-down with following expression:
    =IIF(Parameters!CountryExpand.Value="Yes", False, True)
    =IIF(Parameters!YearExpand.Value="Yes", False, True)
    6. Click SalesTerritoryGroup text box in the tablix. Select InitialToggleState property in the Properties dialog box, and type following expression:
    =IIF(Parameters!GroupExpand.Value="Yes", True, False)
    7. Use the same method setting SalesTerritoryCountry, CalendarYear text box with following expression:
    =IIF(Parameters!CountryExpand.Value="Yes", True, False)
    =IIF(Parameters!YearExpand.Value="Yes", True, False)
    After that, when we preview the report, we can use these three parameters to expand/collapse drill-down.
    Note:
    In our test, we may meet following issue. We can check the expression of InitialToggleState property to troubleshooting the issue.
    Applies to
    Reporting Services 2008
    Reporting Services 2008 R2
    Reporting Services 2012

    In SQL Server Reporting Services (SSRS), drill-down is an action we can apply to any report item to hide and show other report items. They all are ways that we can organize and display data to help our users understand our report better. In this article,
    we are talking about how to use parameter to control the Expand/Collapse drill-down options in SSRS report.
    Consider that the report has a dataset (dsSales) with following fields: SalesTerritoryGroup, SalesTerritoryCountry, CalendarYear, SalesAmount.
    1. The report has the following group settings:
    Parent Group: SalesTerritoryGroup
     Child Group: SalesTerritoryCountry
      Child Group: CalendarYear
       Details: SalesAmount
    2. Add three parameters in the report:
    GroupExpand:
    Available Values: “Specify values”
    Label: Yes           Value: Yes
    Label: No            Value: No
    Default Values: “Specify values”
    Value: Yes
    CountryExpand:
    Available Values: “Specify values”
    Label: Yes           Value: =IIF(Parameters!GroupExpand.Value="No",Nothing,"Yes")
    Label: No            Value: No
    Default Values: “Specify values”
    Value: =IIF(Parameters!GroupExpand.Value="No","No","Yes")
    YearExpand:
    Available Values: “Specify values”
    Label: Yes          
    Value: =IIF(Parameters!GroupExpand.Value="No" or Parameters!CountryExpand.Value="No",Nothing,"Yes")
    Label: No            Value: No
    Default Values: “Specify values”
    Value: =IIF(Parameters!GroupExpand.Value="No" or Parameters!CountryExpand.Value="No","No","Yes")
    3. Right click SalesTerritoryCountry icon in the Row Groups dialog box, select Group Properties.
    4. Click Visibility in the left pane. Select “Show or hide based on an expression” and type with following expression:
    =IIF(Parameters!GroupExpand.Value="Yes", False, True)
    Select “Display can be toggled by this report item” option, and select “SalesTerritoryGroup” in the drop down list.
    5. Use the same method setting CalendarYear, (Details) drill-down with following expression:
    =IIF(Parameters!CountryExpand.Value="Yes", False, True)
    =IIF(Parameters!YearExpand.Value="Yes", False, True)
    6. Click SalesTerritoryGroup text box in the tablix. Select InitialToggleState property in the Properties dialog box, and type following expression:
    =IIF(Parameters!GroupExpand.Value="Yes", True, False)
    7. Use the same method setting SalesTerritoryCountry, CalendarYear text box with following expression:
    =IIF(Parameters!CountryExpand.Value="Yes", True, False)
    =IIF(Parameters!YearExpand.Value="Yes", True, False)
    After that, when we preview the report, we can use these three parameters to expand/collapse drill-down.
    Note:
    In our test, we may meet following issue. We can check the expression of InitialToggleState property to troubleshooting the issue.
    Applies to
    Reporting Services 2008
    Reporting Services 2008 R2
    Reporting Services 2012

  • I need to program a Hittite Fractional​-N Synthesize​r Evaluation Kit with a HMC702LP6C​E an external YIG oscillator​. Not sure how to use Labview to control the PLL.

    I need to program a Hittite Fractional-N Synthesizer Evaluation Kit with a HMC702LP6CE an external YIG oscillator.  Not sure how to use Labview to control the PLL.

    Here is how to use the PLL. But I don't know of how to interact with that device
    http://zone.ni.com/devzone/cda/tut/p/id/3781
    And for thouse who don't know what a PLL is a free bonus link is here:
    http://digital.ni.com/public.nsf/allkb/07BC8D77D4E​9AE258625708B007CE74F?OpenDocument
    and a second one on what that device is: http://www.hittite.com/products/view.html/view/HMC​702LP6CE
    Now we are all caught up to speed.
    Sam S
    Applications Engineer
    National Instruments

  • How to use bexweb analyser in the webbrowser

    Hi ALL,
    Suggest me .how to use bexweb analyser in the webbrowser?
    Regards,
    Suman

    Hi,
    A useful link for you..!!
    http://help.sap.com/saphelp_nw04s/helpdata/en/0d/af12403dbedd5fe10000000a155106/frameset.htm
    -Pradnya

  • How to use application item in the page template

    How to use application item in the page template.
    Thanks,
    rajendra

    Hi,
    You can refer application item value in template like &MY_ITEM. (note period at end)
    http://docs.oracle.com/cd/E37097_01/doc/doc.42/e35125/concept_sub.htm
    Regards,
    Jari

  • How to use TYPE addition with the OPEN DATASET ?

    Hi,
    How to use TYPE addition with the OPEN DATASET and what is the use ?
    For Example:
    OPEN DATASET 'test.dat'
      TYPE 'lrecl=80, blksize=8000, recfm=FB'
      FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    Also, if I wish to do the same for a .CSV file how can we do it.
    Thanks,
    -Sid

    Hi,
    OPEN DATASET 'test.dat'
      TYPE 'lrecl=80, blksize=8000, recfm=FB'
      FOR OUTPUT IN TEXT MODE ENCODING DEFAULT
    For more information press F1 on OPEN DATASET.
    Thanks

  • How to use glob search with the wildcard in command find?

    How to use glob search with the wildcard in command find?
    I want to find any file its names begin with "readme" string using command find. Why the following command cannot work?
    $find /usr/share/doc -name readme*
    However, the following commands can work?
    $find /usr/share/doc -name readme\* or
    $find /usr/share/doc -name readme'*'
    I want to know: After using the “\” or ' ', why the wildcard do not become a character "*"?(still a metacharacter).
    Another question:
    I want to find any file its names begin with "readme*" string using the command find.What command should I use?

    I want to know: After using the “\” or ' ', why the
    wildcard do not become a character "*"?(still a
    metacharacter). The backslash is known as an escape character. It means 'use the character value of the next character, not the special meaning' It is used in a lot of places such as command line, global regular expression patterns, and editors such as vi.
    In a typical shell, the splat (*) expands to all file names before passing the file names to the current command. So a \* sequence tells the shell to pass a *, not a list of file names, to the command.
    Demo - OpenSuSE Linux 10.3
    - I have a bunch of files. Let's list those that end in grid. Create one called *grid, and list again
    pops@fuzzyVM:~/pops> ls 
    a  b  c  startgrid  stopgrid
    pops@fuzzyVM:~> ls *grid
    startgrid  stopgrid
    pops@fuzzyVM:~> ls \*grid
    ls: cannot access *grid: No such file or directory
    pops@fuzzyVM:~> touch '*grid'
    pops@fuzzyVM:~/pops> ls
    a  b  c  *grid  startgrid  stopgrid
    pops@fuzzyVM:~/pops> ls *grid
    *grid  startgrid  stopgrid
    pops@fuzzyVM:~/pops> ls \*grid
    *grid
    pops@fuzzyVM:~/pops>In the above, how would I remove the file *grid, and only that file?
    Another question:
    I want to find any file its names begin with
    "readme*" string using the command find.What command
    should I use?What were the results of the two versions you tried? And why?

  • How to use PS to judge the existence of a folder in the specified directory and how to use PS in the specified directory to create to create the folder?(javascript)

    1,How to use PS to judge the existence of a folder in the specified directory?(use javascript)
    2, how to use PS in the specified directory to create to create the folder?(use javascript)
    Thanks you!

    Thanks you!

  • How do you get the sum of two columns multipied together?

    I can't seem to figure out how to get the sum of two columns multiplied together without having to manually type out each location (example: A1*B1+A2*B2+A3*B3, etc..).  Though the idea seems to be rather simple, everything I have tried has only given me an error.  I know there must be an easier way of doing this, but I get lost in the explanations given in 'help' area of numbers, can someone help me?

    C3=SUMPRODUCT(A3:A18, B3:B18)
    the function SUMPRODUCT() takes ranges and multiplies corresponding cells in the ranges, then adds them together.
    I the case I show SUMPRODUCT() performs:
    A3*B3 + A4*B4 + A5*B5 + A6*B6 + ... +  A18*B18
    If you want to perform the same operation on the whole column (s) you could modify the formula:
    C3=SUMPRODUCT(A, B)

  • I have deploy an EJB in weblogic 6.1,but how to use jsp to invoke the EJB's method?

    i have deploy an EJB in weblogic 6.1,but how to use jsp to invoke the EJB's method?
    thanks!

    You'd do something like:
    <%
    //vvv this part can potentially be done in initialization
    Context ctx = getInitialContext();
    BeanHome home =
    (BeanHome)PortableRemoteObject.narrow(ctx.lookup("the.jndi.name"),
    BeanHome.class);
    Bean b = home.create();
    //^^^
    Result r = b.invokeMethod();
    %>
    "toxin" <[email protected]> wrote in message
    news:3d2e95e5$[email protected]..
    >
    i have deploy an EJB in weblogic 6.1,but how to use jsp to invoke theEJB's method?
    thanks!

  • How to used apple ID in the iTunes store?

    how to used apple ID in the iTunes store?always the problem was this " This apple ID has not yet  been used in the iTunes store?

    Why can’t I select None when I edit my payment information?
    also you can
    Create a NEW account/ID for her using these instructions. Make sure you follow the instructions. Many do not and if you do not you will not get the None option. You must use an email address that you have not used with Apple before. Make sure you specify a birthdate that results in being at least 13 years old
      Creating an iTunes Store, App Store, iBookstore, and Mac App Store account without a credit card
    More details of how:
      http://ipadhelp.com/ipad-help-tips-tricks/how-to-get-free-apps-from-the-app-stor e-without-a-credit-card/

Maybe you are looking for

  • Spry Menu Bar lost formating

    Hi, Using DW CS3, I was cleaning up my site and wanted to place my main css file in the css folder (for some reason, it was in the root folder). I assumed DW would keep all links, etc. in tact. Everything else is fine, including my horizontal Spry Me

  • Search help results of cost center

    Hi everybody Cost center is normally assigned to SC item based on the attribute set in PPOMA_BBP (attribute CNT). Now, when you're in the item details screen and want to change that default cost center you can search for other ones using the "glasses

  • Dreamweaver Extensions Greyed Out

    Help!  I'm beating my head against a wall . . . I'm somewhat incompetent and am stuck on this problem. I'm working on a mac and have CS5 working on the design view with Dreamweaver.  I am not comfortable with coding at all. I have downloaded the kaos

  • Why Google maps is not on Egypt store ?

    I searched App Store to download Google maps but it's not there. I got the link from a web page and when it tried to open the itunes store I was told that this app is not available for the Egyptian store ... why ???

  • Should the TC be left on all the time?

    Ok - this may be a daft question - but should the TC be left on all the time or is it ok to switch it off at the mains each time I shut down my iMac?