Condition in trigger

Dear All,
I wrote a trigger and i used conditions, but it doesn´t work.
i use oracle 11g .
would you please recorrect it?
thanks, if u need i can provide trable information but i just want to correct it syntactically.tnx.
i want to check, if the population of capital in a country is a city with the most population , then it sends use the first error message, other wise it means that there are some cities with population more that the capital city and we give another error message.
{code}
create or replace
trigger capital city
before update or insert or delete on country
for each row
when exists ((select population from city ci where ci.name=capital)<(select max(population) from city ci2 where ci2.country=code))
begin
raise_application_error(-20000,'verletzung der integrität');
end;
when ((select population from city ci where ci.name=capital)=(select max(population) from city ci2 where ci2.country=code))
begin
raise_application_error(-20000,'die Hauptstadt sind die größten städte der jeweiligen länder');
end;
{code}
or i also wrote this one, but both of them don´t work.
{code}
create or replace trigger bigcapital
after insert or update of population on city
for each row
when exists( select count(*) from country co where co.capital<> (select ci.name from city ci where ci.country=co.code and ci.population= (select max(population)from city ci1 where ci1.country= ci.country) ) )
begin
raise_application_error(-200002,'Verletzung der Intergrität');
end;
{code}
Message was edited by: 1006212

So your requirement is that in your CITY table the population of a city should be always less than that of the capital city for a given country?
The best way would be to implement the constraint using Transaction-API build using PL/SQL.
But any way here is another approach using materialized view.
SQL> create table city
  2  (
  3    name        varchar2(100),
  4    capital     varchar2(1),
  5    country     varchar2(100),
  6    population  integer
  7  );
Table created.
SQL> create materialized view log on city
  2  with rowid, sequence(country, capital, population)
  3  including new values;
Materialized view log created.
SQL> create materialized view city_mv refresh fast on commit with primary key
  2  as
  3  select country
  4       , max(case when capital = 'Y' then population end) capital_population
  5       , max(case when capital = 'N' then population end) other_population
  6    from city
  7   group
  8      by country;
Materialized view created.
SQL> alter materialized view city_mv add constraint city_mv_check_1
  2  check (other_population < capital_population);
Materialized view altered.
SQL> insert into city (name, capital, country, population)
  2  values ('DELHI', 'Y', 'INDIA', 100000);
1 row created.
SQL> commit;
Commit complete.
SQL> insert into city (name, capital, country, population)
  2  values ('MUMBAI', 'N', 'INDIA', 1100000);
1 row created.
SQL> commit;
commit
ERROR at line 1:
ORA-12008: error in materialized view refresh path
ORA-02290: check constraint (ARBORU.CITY_MV_CHECK_1) violated
SQL> insert into city (name, capital, country, population)
  2  values ('MUMBAI', 'N', 'INDIA', 10000);
1 row created.
SQL> commit;
Commit complete.

Similar Messages

  • How to reset a count variable in a conditional format trigger

    I am using a conditional format trigger to eliminate sections of a report where there is no data. The trigger is automatically generated by reports (shown below). the condition is :com_count = '0' therefore no record, no display of section - if :com_count>0 then data present and display record.
    It works fine eliminating the sections - until actual data is found - and count is set to 1 and it displays the record. The problem is that once :com_count >0, then the section displays throughout the rest of the report whether there is actually data or not.
    It seems that :com_count needs to be reset to 0, but when I try to do that, it throws an error stating that :com_count is a read only variable.
    I am new to PL/SQL so can anyone suggest how I can reset the :com_count to 0 each time the trigger fires with :com_count = 1?
    Any help would be appreciated. Thanks,
    Glenn
    The conditional format trigger is:
    function M_G_COM_RANK_GRPFRFormatTrigge return boolean is
    begin
    -- Automatically Generated from Report Builder.
    if (:COM_COUNT = '0')
    then
    return (FALSE);
    end if;
    return (TRUE);
    end;
    The count
    It works perfectly

    wher is your COM_COUNT defined?
    If should be defined in the datamodel in the "mastergroup" of the "detailgroup" of which you want to count the records.
    If you do so, there is a property of the item "Reset at" ( which is by default set to "Report") and you then can change it to the name of the mastergroup. So every time a new record is "active" in the mstergroup, the count-item will be reset to 0.
    hope this helps

  • How to create conditional update trigger in sql server

    How to create conditional update trigger in sql server

    You cant create a conditional update trigger. Once you create an update trigger it will get called for every update action. However you could write logic inside it to make it do your activity based on your condition using IF condition statement
    Say for example if you've table with 6 columns and you want some logic to be implemented on update trigger only if col3 and col5 are participating in update operation you can write trigger like this
    CREATE TRIGGER Trg_TableName_Upd
    ON TableName
    FOR UPDATE
    AS
    BEGIN
    IF UPDATE(Col3) OR UPDATE (Col5)
    BEGIN
    ....your actual logic here
    END
    END
    UPDATE() function will check if column was involved in update operation and returns a boolean result
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Override Update condition with trigger

    Hi
    I 've web app, and it runs an update command. But i realize in midnight, my update command's where condition is wrong. Can i manipulate this update command with instead of update trigger ?
    for example
    update mytable set sometext = 'bla' where field1= a;
    bu my filed1=a condition always empty, can we change this condition ith trigger ?
    thanks in advance.

    UPDATE is a statement and not a command; big difference. 
    Use an INSTEAD OF trigger??! Yes, and you can drive screws into furniture with big rocks. Do you know the word "kludge"? 
    Clean up your mess and write a correct update statement. In the old days, we had a joke about the "should have been" comparison operator for bad programmers. IF (x SHOULD HAVE BEEN 5) THEN..
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • What condition to trigger import PO?

    Hi I have some doubts about how to trigger import PO? Let's say if country code of vendor and receiving plant is different, so the system will consider it as import PO? then there will be import tab in THIS PO? But when I am testing in IDES, the vendor is set up as countriy code CN, and plant is 1000 which is from DE, and system does not trigger it as import PO, why ,help.

    Hi Allen,
    The import views in the PO are normally shown (in standard SAP) when the vendor and the purchasing plant reside in different EU countries. This is in order to facilitate Intrastat reporting.
    However, this can be changed in config. for MM -> Purchasing -> Foreign Trade/Customs -> Control Foreign Trade Data in MM and SD Documents -> Import Screens In Purchasing Document.
    If you have more doubts in this regard, please ask.
    BR
    Raf

  • Condition to Trigger ActionBox

    Dear Experts,
    I have a requirement to trigger the Action box in the Notification, only when a particular  value is filled in the Maint. Work Center field.
    How do I achieve this?
    Regards
    Jogeswara Rao
    (All other IMG setting are in place through IMG -> Plant Maintenance and Customer Service -> Maintenance & Service Processing -> Notification Processing -> Additional functions -> Define action box.
    Using FM QM06_FM_TASK_CREATE_QM_NOTIFIC  and Task TS20000304)

    Thank you both.
    In fact it's like this:
    One type of Notification has the feature of having Action box activated (in which Create Notification icon is there) once it is NOPR and saved. But this action box is available only when the Maint. work Center field is having one particular value.
    In the absence of the persons who configued this, I am trying to reach at the settings which are making this possible.
    (There are no signs of any FM modifications)
    Regards
    Jogeswara Rao

  • Action with start condition always triggers

    Functionality required: "when its 4 days from the actual date an
    Audit is to take place an e-mail should be triggered to the
    audit attendees"
    I have created a new date rule (4 days before - reminder) and
    added this date rule to the date profile 000000000003.  I am
    using this date profile in my actions and have set a new start
    condition to trigger an e-mail alert when "todays date" = my new
    date rule.  I have set up scheduled conditions which are met.
    when i create transactions which meet both the scheduled and
    start conditions (from my perspective) the action is getting
    triggered to send the e-mail reminder.  My new date rule is as
    follows:
    <?xml version="1.0"?>
    <TimeRule>
       <TimeRuleSource>
          <ruleline>
             <AssignTimeExp displaytype="AssignTime">
                <VarTimeExp displayType="VarTime"
                                   name="RESULT"
                               position='B'>
                  <VarObjectExp displaytype="VarObject"
                                    name="SYSTEM"/>
                </VarTimeExp>
                <MoveTimeExp displaytype="MoveTime" direction="-">
                   <VarTimeExp displayType="VarTime"
                                      name="ORDERACTUAL"
                                      position="B">
                     <VarObjectExp displaytype="VarObject"
                                    name="SYSTEM"/>
                   </VarTimeExp>
                   <ConstDuraExp displaytype="ConstDura"
                                    duration="4" timeunit="DAY">
                      <VarObjectExp displaytype="VarObject"
                                    name="SYSTEM"/>
                   </ConstDuraExp>
                </MoveTimeExp>
             </AssignTimeExp>
          </ruleline>
       </TimeRuleSource>
    When i test it using various dates it seems to work as expected, it returms false when it should fail and true when it should suceed  When tested from within the date rule for the FROM and TO date for todays dates i get the following:
    Deadlines
    Appointment Type RESULT
    From SA 10.02.2007 14:27:52 GMTUK
    From
    Appointment Type ORDERACTUAL
    From WE 14.02.2007 14:27:52
    To WE 14.02.2007 14:27:52
    Duration
    Reference Objects
    SYSTEM GMTUK CL_TIMECALENDAR_SIMPLE
    In my start condition i am testing for my date rule (4 days
    before - reminder) = todays date. 
    Can anyone explain why my start condition is always being triggered
    Thanks in advance
    Ed

    Hello Easwar Ram,
    Thanks for your reply.
    No, I didn't create an Action Profile. I use standard profile: /SCWM/TU (Shipping & Receiving - Transportation Unit).
    I only have created a new Action Definition, Schedule and Start Conditions for this Definition. All work correctly with the exception of the button 'Start Condition Parameter'.
    I don't know why the button appears because I didn't define a Condition Parameter for the Start Condition. And when I click on this button I get an error in standard SAP code:
    1) li_bor_object ?= l_context->appl.
    2) ls_bor_handle = li_bor_object->get_bor_object( ip_objtype = l_objtype ).
    L_context->appl has value '' in the debugger. After line 1 the value of the li_bor_object is '' therefore line 2 terminates the transaction with error.
    Maybe this occurs because the Action Profile uses a Persistent Class for Object Type instead of a Business Object Repository?

  • Logical OR condition check in xpath - Documaker v 12.x

    Hello,
    We are looking to trigger images based on a logical OR condition between XML node values within the Xpath. This was possible using the flat file extract with offset referencing, say, Search mask (counter) - 10,31,12,(a,b). A similar change done for the Xpath reference does not seem to work. Thanks.

    Hello,
    If we give two manual triggers with 2 different Xpath conditions for applicable image, then documaker executes an OR condition between the conditions to trigger the image.
    Thanks.

  • Trigger in a same step of sequence ...

    Hello.
    I use a PCI-MIO-16E-1 acquisition card with LABView 7.0 on a Celeron 333 MHz with 256 Mo RAM, and I 've a big problem with a trig. I explain.
    I generate a square waveform with a determinated time of emission on DACOUT 1, and this signal (by external hardware) can increase the voltage on PFI0 in less than 1 µs.
    Then, if PFI0 is upper than 0.7 volt, it trigs DACOUT 0 which emit an other signal.
    That's the theory and there's no problem to do this simply, but I must to do it on one step of a "pilled up sequence". Indeed, the time between the 2 events of my step have to be smaller than about 10 microseconds. Actually, it's works at 75% of time (sometimes the trig falls) with a delay of 40 microseconds, and it's to
    o long ! Why the synchronization is so long ?!
    I can't separate the two events because I need to trig DACOUT 0 BEFORE DACOUT 1 finish its emission, and I can't change the structure.
    How can I do with DAQmx or assistant ??
    Thanks a lot.
    (I join too an example of what I try to expose)
    Attachments:
    Example.vi ‏371 KB

    Monsieur,
    Comme vous utilisez une seule et même carte, il ne peut pas y avoir de synchronisation entre vos 2 opérations. L'armement de la génération sur DACOUT0, ne peut s'effectuer que lorsque la génération sur DACOUT1 est terminé. Aisni, vous aurez toujours une latence temporelle entre les 2 générations.
    Si vous voulez vraiment que la génération DACOUT0 soit trigée avant la fin de de DACOUT1, vous n'avez d'autre choix que de travailler avec 2 cartes de générations indépendantes. Ainsi, les 2 cartes pourront être armées en même temps: la première carte génèrera le signal carré, et la seconde carte attendra la condition de trigger pour acquérir.
    Avec une seule carte, vous pouvez envisager de générer votre signal carré (uniquement TTL) avec un compteur de
    la carte (Il existe de nombreux exemple dans Lv permettant de mettre en oeuvre les compteurs dans ce mode). Ainsi, il suffit de configurer la génération de DACOUT0, puis d'armer le compteur qui va générer les pulses qui créeront le bon niveau sur votre matériel externe.
    Raphael TILLET
    NI FRANCE
    Cordialement,
    Raphael T

  • How to include a time condition in a Vi?

    Hi,
    I need to run an event for one hour and after this time interval has elapsed, I need to stop this event (let�s call it event A) and go for event B. I have been trying to work with the Elapsed Time (LabView 7.0) sub-vi with no success. That sub-vi sounded perfect as I could even work with a boolean condition to trigger event B. Basically what I would like to know is how to generate a time condition in which I can input the time and after that time has elapsed I can generate an action to pass to another event? Would it be an simple way of doing so?
    Thanks for the help.
    Adriana

    I may be missing something here, but I think your problem is not the Elapsed Time VI, but the way your events are triggered/controled or chained. Or may be you just forgot to wrap the Elapsed time vi into a loop ?
    See the attached example...
    The "Run event A" sub.vi is intended to trigger event A. Something like commuting a switch or launching a dynamically loaded vi. It should not wait until event A finishes (of course...).
    There are many possibilities... and I'm sure that you will get other solutions.
    Keep wiring !
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Elapsed_time_and_events.tif ‏16 KB

  • Error message 'The Condition evaluates to false' using Form Personalisation

    Hi,
    In Oracle HRMS
    Under Assignment screen 2 fields are there 'Grade' and 'Payroll'
    w.r.t Grade field Payroll field should display
    i.e. If we enter grade field '1' by default Payroll field should display value' MANAGEMENT PAYROLL'
    NAVIGATION: India HRMS Manage--->People Enter and Maintain--> Click on Assignment button
    I done the process using form personalisation:
    Under  CONDITION TAB*****
    Trigger Event: WHEN-NEW-ITEM-INSTANCE
    Trigger Object: ASSGT.PAYROLL_NAME
    Condition-- :ASSGT.GRADE_NAME IN (1,2,3,4,5,6,7,8,9,10,11,'MT','4A')
    Processing Mode: both
    Under  ACTIONS TAB***
    Seq--10
    Type--Property
    Object Type: Item
    Target Object: ASSGT.PAYROLL_NAME
    Property Name : VALUE
    VALE: MANAGEMENT PAYROLL
    After that i press APPLY NOW button
    and also Validate button on condition tab
    But i display error message 'The Condition Evaluates to false'
    After that i save all setups then logout & log in the instance
    and UNDER Oracle HRMS Responsibility open the assignment screen when i enter in grade field 1,2,3,4,5,6,7,8,9,10 w.r.t that values Payroll field dispaling MANAGEMENT PAYROLL correctly
    But when i enter '4A' or MT on grade field and enter tab it
    showing error :The condition :ASSGT.GRADE_NAME IN(1,2,3,4,5,6,7,8,9,10,'4A','MT') could not be evaluated because of error ORA-01722 INVALID NUMBER .
    I tried for differen combination in condition field
    i.e.
    :ASSGT.GRADE_NAME IN('1','2','3','4','5','6','7','8','9','10','4A','MT')
    ${item.ASSGT.GRADE_NAME.value IN (1,2,3,4,5,6,7,8,9,10,'4A','MT')
    BUT SAME ERROR DISPLAYING
    Could you pls provide me the solution ASAP
    Thanks,
    AKULA                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Hi Felipe,
    I understand that using the "Instantiation" tab in GP DesignTime, the process opens in a new window. Can you confirm whether your process opens in a new window even by using GP RunTime?
    While making a callable object from a Web Dynpro application, you might get this error when your process opens in a new window (A window which somehow no longer exists in the Portal environment. You can check this as you would not be able to see the Portal masthead and roles etc. at the top)
    For more information, see this SAP Note:
    [Error when executing a GP task - Page builder|https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes/sdn_oss_bc_gp/~form/handler%7b5f4150503d3030323030363832353030303030303031393732265f4556454e543d444953504c4159265f4e4e554d3d393831353137%7d]
    Bye
    Ankur

  • How to trigger datagrid doLater()

    I'm developing with Flash 8. I'm trying to figure out what
    conditions will trigger the datagrid to call doLater(). I am not
    dynamically creating a datagrid with "new" or createObject(). The
    datagrid is already placed on the stage and I'm simply adding
    columns and populating it with data through a data_set component.
    Here's what I'm trying to accomplish. After I edit a value in
    a cell and hit enter (and leave the focus of that cell), I do not
    want the focus to be on the next cell or any other cell for that
    matter. In the cellFocusOut listener function, I make the datagrid
    not editable and register a function to be called by doLater().
    However, the do later is never executed. I have also tried adding
    and removing columns/rows to try and trigger the doLater() call but
    with no success. Could someone please explain to me when the
    datagrid calls doLater?

    let me clarify what I was planning to do with the doLater().
    Once it's called, I was going to make the datagrid editable
    again.

  • Conditional navigation to popups

    Hi Masters,
    I have a form through which iam passing the values to the web service, depending on the return value i should show the popups. If the value is 0 i should navigate to first popup else to other popup. Please help me out..
    Thanks & Regards,
    Kaushik Sreeram

    Hi,
    May be, you can use a hidden checkbox in one of the fomr s in layer two, with the query result makes it true/false.
    The popup can be triggered based on the value of the hidden checkbox in layer2.
    I Saw system action "Dynamic Action" for submit button, with an action formula. Not sure whether you can use it. But just give a try.
    Else, Use two buttons (One placed over other) with mutually exclusive hidden conditions to trigger events based on checkbox value in layer2
    Hope it helps.
    Regards,
    Sooraj

  • NI 6115, triggering AO & AI simultaneously from 2 different trigger sources?

    I am using NI 6115. Can I trigger my AI and AO simultaneously and independently (at different times) from 2 different trigger sources?

    This is possible to do. What Software are you using to program this? (CVI, LV, ...) So, what your are trying to do is a triggerd generation, adding hte functionality of a triggered acquisition. In general, I would think that the easiest way of doing this is just to have continuous AO, then trigger the AI when needed with the PFI0/TRIG1 line. If you need to trigger both the AO and AI, I can think of 2 ways of doing this:
    1. use the PFI0/TRIG1 to trigger the AO and one of the other PFI lines that are not in use to trigger the AI. Take a look at the daqmx examples in the language you are using for triggered AO, Triggered AI, copy and paste the necessary portions into a new Programm, you might want to adjust the error inputs and outputs in LV so t
    he components get acomplished in the order you require. Daqmx is fully multithreadding compatible, so I would strongly suggest you use Daqmx.
    2. Trigger your AO with PFI0/TRIG1 and use an analog edge condition to trigger at a specific value in your generation. The backdraw of this is that you would have to input the signal you are giving out into one of your AI channels which you probably are not interested in doing.
    For all these options, you are going to find examples in LV or CVI, but you will need to take parts of one example and paste it into the other.

  • Conditional formatting based on page number that resets on repeating frame

    Hello everyone,
    I have searched through multiple forums on multiple sites and haven't come across anyone who has accomplished this.
    I have a report with pages numbers that reset on a repeating frame.
    I have a text boiler plate that I want to only show up on page 1. On every occurrence of page 1.
    SRW.GET_PAGE_NUM does not work because it returns physical page number.
    I'm trying to access the value of the field for my page number. The value comes from "source" drop down with value of "Page Number".
    I've tried accessing the <&page number> in the PL/SQL of my conditional formatting trigger but no luck.
    This report is 14K plus pages so I'd rather not be inserting and selecting the value back out of the database.
    Does anyone have any ideas??
    Thanks,
    Alan

    To avoid inserting/selecting from the database
    Maybe you could create a small package on the database to store page numbering information.
    Then use get/set routines per your requirements.
    CREATE OR REPLACE PACKAGE rep_page_no IS
       gPageNo NUMBER;
       PROCEDURE set_it(pPage NUMBER);
       FUNCTION get_it RETURN NUMBER;
    END rep_page_no;
    CREATE OR REPLACE PACKAGE BODY rep_page_no IS
       PROCEDURE set_it(pPage NUMBER) IS
       BEGIN
          gPageNo := pPage;
       END set_it;
       FUNCTION get_it RETURN NUMBER
       IS
       BEGIN
          RETURN(gPageNo);
       END get_it;
    END rep_page_no;Then in your repeating frame you could access this package rather than insert/select from any database table.
    Let me know if this works, I might like to try it.
    Thanks

Maybe you are looking for

  • AHHHH...

    ok so i just got a mac mini, i used my old ipod as a hard drive. i transfered songs over to new mac, and all my play counts are gone.... this majorly ***** because, some of my songs have 100 plus plays on them and my top 25 played songs are gone now.

  • Report generation failed

    when i try to generate the report using the Oracle BIP 11g services from Jdeveloper it is failing. I have set the DynamicDatasource in the report request, following are the error log [2012-03-20T11:05:12.720+05:30] [bi_server1] [WARNING] [] [oracle.x

  • Where i can found the ocs singlebox installation downloadable file?

    hi all, from where i can download the ocs single box on windows 2000 software? Provide me the link from where download that software? What are the hardware requirements &ram capacity, HD capacity, etc...regards, kumaraswamy.n

  • Small code example

    I have a project where I have to compile assembly code (i.e. mov ax,[bx] ) in java. I have my code read in each line and pick out the label, opcode and operands of each line and put them in an array of classes called lineInfo. Each class has line#,la

  • Do I need additional RAM?

    Hello to all, Though I am not presently facing any trouble while editing, yet I am feeling discomfortable seeing the free space remaining on my 8 GB RAM which sometimes drops to less than 500 GB when I have just my internet and FCPX on. Do I have to