Trigger with Condition problem - insert only when not exists

Hello experts!
I have a problem with a trigger I'm trying to create. It compiles but I receive an error message when the trigger fires.
The scenario is as follows:
I have a table TBL_PUNKTDATEN. Whenever the status for a record in that table is changed to 3 or 4 I need the trigger to insert a dataset into my target table (TBL_ARBEIT_ZU_GEBIET).
However, the trigger must only insert data when there's no existing record in the target table. The condition that specifies whether there is a dataset or not, is the field LNG_GEBIET, which exists in the source as well as in the target table. Hence, for each LNG_GEBIET there can be only one dataset in the target table!
I created a trigger using the following code. However it doesn't work.
Maybe you'll see what I want to achieve when having a look at my code.
Can you please help me out on this one?
Thanks a lot!
Sebastian
create or replace
TRIGGER set_status_arbeit_zu_gebiet AFTER
  UPDATE ON TBL_PUNKTDATEN FOR EACH ROW WHEN(new.INT_STATUS=3 or new.INT_STATUS=4)
declare
    cursor c is select LNG_GEBIET from TBL_ARBEIT_ZU_GEBIET where PNUM = 1114 and LNG_GEBIET=:new.LNG_GEBIET;
    x number;
begin
    open c;
    fetch c into x;
    if c%NOTFOUND  then 
    INSERT INTO TBL_ARBEIT_ZU_GEBIET
        LNG_GEBIET,
          LNG_ARBEITSSCHRITT,
          PNUM,
          INT_BEARBEITER,
          DATE_DATUM,
          GEPL_DATUM
        VALUES
        (:new.LNG_GEBIET,
         52,
         1114,
         895,
         sysdate,
         to_date('01.01.1990', 'DD.MM.YYYY')
    end if;
end;Well, on the first insert the code works properly and inserts the recordset as expected. However, if there is an existing recordset where :new.LNG_GEBIET matches LNG_Gebiet in my target table, I receive the ORA-06502 error!
Maybe that spcifies it a little bit???
Hope you can help me!
Thank you!
Edited by: skahlert on 23.09.2009 10:26
Edited by: skahlert on 23.09.2009 10:28

Thank you very much Peter G!
That %Rowtype mod did the trick! Great solution! Thanks! The trigger works principally if there wasn't the fact that it fires also when the status of one individual record is 3 or 4.
I need it to fire only when all records with the same attribute LNG_GEBIET (by the way, you guess was right - it's not a number) are of status 3 or 4.
Is it possible to use the cursor function for the trigger's when condition?
Such as:
declare
    cursor c3 is select COUNT(*) from TBL_PUNKTDATEN where LNG_GEBIET=:new.LNG_GEBIET;and
declare
    cursor c4 is select COUNT(*) from TBL_PUNKTDATEN where INT_STATUS = 3 and  LNG_GEBIET=:new.LNG_GEBIET or INT_STATUS = 4 and  LNG_GEBIET=:new.LNG_GEBIET;
  And then subsequently somehow compare the results of both cursors?
... WHEN c3=c4
declare
    cursor c2 is select LNG_GEBIET from TBL_ARBEIT_ZU_GEBIET where PNUM = 1114 and LNG_GEBIET=:new.LNG_GEBIET;
    v_c2  c2%ROWTYPE;
begin
open c2;
fetch c2 into v_c2;
if c2%notfound then
        INSERT INTO TBL_ARBEIT_ZU_GEBIET
        LNG_GEBIET,
          LNG_ARBEITSSCHRITT,
          PNUM,
          INT_BEARBEITER,
          DATE_DATUM,
          GEPL_DATUM
        VALUES
        (:new.LNG_GEBIET,
         52,
         1114,
         895,
         sysdate,
         to_date('01.01.1990', 'DD.MM.YYYY')
        end if;
        close c2;
end;Please excuse me if the attempt is simply stupid!
Sebastian
Edited by: skahlert on 23.09.2009 15:36
I just saw your reply Max! Thank you! Now I understand far better! Seems to be a successful day! I'm learning a lot! Will also test that method!
If we could find a solution to the problem I described above it would make it a perfect day! I'm continously trying different attempts to have the trigger only fire when all records are 3 or 4.
Not that you think I'm just waiting for your answers! That's not the case!
Thank you all!
Edited by: skahlert on 23.09.2009 17:30

Similar Messages

  • Powerpoint presentation I have stored in icloud until recently were syncing to Keynote on my iPad with no problem.  Now when I open Keynote on my iPad there is nothing.  I could use some help with this problem.

    powerpoint presentation I have stored in icloud until recently were syncing to Keynote on my iPad with no problem.  Now when I open Keynote on my iPad there is nothing.  I could use some help with this problem.

    Morning AndreD86,
    Thanks for using Apple Support Communities.
    These articles explain exactly what is backed up by using their method.
    iTunes: About iOS backups
    http://support.apple.com/kb/ht4946
    and
    iCloud: Backup and restore overview
    http://support.apple.com/kb/ht4859
    Also we want to double-click the Home button and swipe the Task Bar to the right.
    Then make sure the button on the far left of Task Bar is not muted.
    Best of luck,
    Mario

  • I HAVE A MAC G5 WITH V10.4 TIGER OS, I AM HAVING TROUBLE WITH THE LETTER "N" ONLY WHEN I USE CAPS AND SHIFT KEYS DOSE IT TYPE THE LETTER "N"SE

    HAVE A MAC G5 WITH V10.4 TIGER OS, I AM HAVING TROUBLE WITH THE LETTER "N" ONLY WHEN I USE CAPS AND SHIFT KEYS DOSE IT TYPE THE LETTER "N". I HAVE CONNECTED A NEW KEYBOARD BUT THE PROBLEM STILL EXIST. WHAT ELSE CAN I DO?

    You might look at "Keyboard Shortcuts" in the Keyboard and Mouse preference pane and see if somehow the lower case n has been inadvertently assigned to something.
    Probably the best solution would be to click the "Restore Defaults" button.

  • The table with Name of 'Table Name' does not exist.An error occurred when loading the Model.

    The table with Name of 'Table Name' does not exist.An error occurred when loading the Model.
    We get this error when we try to check the properties of an analysis server using SQL Server Management studio(right click the instance name
    and check properties). We have resolved this issue twice by Stopping the SQL Server analysis service,removing db folders from Analysis Server Data folder and starting the services back on. The db folder that we removed was advised by the BI team.
    The SQL Server Analysis Server is 2012 SP1

    Hi RB_ORIPW,
    The table with name of 'XXX' doesn't exist.
    An error occurred when loading the model(Micorsoft.AnalysisServices)
    If I understanding correctly, you encounter the error randomly, now what you want it that avoid this issue completely, other than stop the services, detele the db filder and restart the services, right?
    The error might be caused by that the data file is corrupted. However, we cannot give you the exact reason that cause this issue. You can troubleshoot this issue by using the Windows Event logs and msmdsrv.log.
    You can access Windows Event logs via "Administrative Tools" --> "Event Viewer".  SSAS error messages will appear in the application log.
    The msmdsrv.log file for the SSAS instance that can be found in \log folder of the instance. (C:\Program Files\Microsoft SQL Server\MSAS10.MSSQLSERVER\OLAP\Log)
    Here is a blog about data collection for troubleshooting Analysis Services issues, please see:
    Data collection for troubleshooting Analysis Services issues
    Besides, here is fix that describe the similar issue, and it was fixed in Cumulative Update 7 for SQL Server 2012 SP1, please refer to the link below to see the details.
    http://support.microsoft.com/kb/2897263/en-us
    Regards,
    Charlie Liao
    If you have any feedback on our support, please click
    here.
    Charlie Liao
    TechNet Community Support

  • IDoc error - Condition type & tax code & does not exist

    Hi,
    I have the problem with CANADA tax codes. I have a few documents sent from external SAP to different SAP. In the source system documents were posted. In the target system i have error "Condition type & tax code & does not exist". I have compared the tables A003 and A053 in both systems and the settings are the same for specific Condition type and tax code... So where to find the reason Idocs are in error ? The only thing which is different is validity from (in the source system is earlier than in the target but the docs are created after both validation start)...
    I would appreciate advice.
    Tomek

    Hi Tomasz,
    Please go to T.code WE02 and check the reason for the error.
    The failed IDocs will be in status "51" and will also give you the reason for errors.
    Regards,
    Shiv

  • Condition type & tax code & does not exist

    Hi,
    I have a problem to find out the reason why i can not process documents which came via IDocs from Sales SAP system. The error is "Condition type & tax code & does not exist". Following places i have already checked :
    1. FTXP - tax code for which error exists the same in both systems
    2. Table A053 - Condition types for specific tax codes and country are created in both systems.
    The tax determination is under billing and in Sales system it is ok, document is posted and when comes to our FInance system via Idoc it is in error even we have the same entries in the table A053.
    Maybe someone knows what can be also checked ?
    Thanks
    Tomek

    Hi Tomasz,
    Please go to T.code WE02 and check the reason for the error.
    The failed IDocs will be in status "51" and will also give you the reason for errors.
    Regards,
    Shiv

  • Business Management Error: You are attempting to create a user with a domain logon that does not exist. Select another domain logon and try again.

    Hello,
    Suddenly the working CRM is being stopped for some group of users.
    I drilled down to the issue and have checked that the users from Domain in which CRM is installed are having CRM access.
    But for other domain user having problem to access CRM.
    I tried to add a user from a domain which is not of CRM domain then it gives following error.
    "Business Management Error: You are attempting to create a user with a domain logon that does not exist. Select another domain logon and try again.
    <Message>LookupAccountNameW failed with error</Message> "
    The change is made - AD group have upgraded Activer Directory server to 2012 R2
    Please help as the Production CRM is not working for other domain user.

    We have Activer Directory Structure like below.
    One Root Domain says A
    and there are multiple child domain like B,C,D etc...
    B,C and D are all in same level,they are child of A domain.
    There are two way transitive trusts between A and all the child Domain.
    But there is no trust in between B and C and so on.
    Our CRM server is in B domain and B domain's user can access CRM but users of Domain C,D and so on can not access CRM.
    If this post answers your question, please click &quot;Mark As Answer&quot; on the post and &quot;Mark as Helpful&quot;

  • How to create an object only if not exist?

    how to create an object only if not exist? is it possible?
    if not what can I do?
    Thanks.

    Well, the jsp:useBean tag is a great way to do things.
    But another way is:
    <%  
          MyObjectType myObject = null;
          if(session.getAttribute("myObject"))==null) {
             myObject = ... ; //initiate your object
             session.setAttribute("myObject", myObject);
          myObject = (MyObjectType) session.getAttribute("myObject");
    %>As you can see, this is more messy, but you can do it.

  • Master-detail page with form layout -- insert only -- not in create mode

    JDeveloper 10.1.3.1 with JHeadstart
    I have the following master-detail structure in JHeadstart:
    Group 1, Table a, Layout: table-form
    Group 2, Table b, Layout: table-form
    Group 3, Table c, Layout: form
    Group 4, Table d, Layout: form (on same page as master table c)
    Table a, b and c are updatable (insert, update and delete).
    I have problems with the last page, tables c and d, master-datail both in form layout.
    The master-table (c) is not an insert-only table, the detail table needs to be an insert-only form on the same page as the master table c.
    Settings Table d:
    Advanced search and quick search: none
    Autoquery: disabled
    Single row insert allowed (other options in Operations disabled)
    In my view object I have used the settings in the JDeveloper guide 8.1.2 ('no rows...' in tab Tuning).
    I run my application in JDeveloper (with the option run in my ViewController-project, which means that I am not running my detail page directly in JDeveloper??) and when I open this last page, the detail form is not in create mode (I see no rows found and a create rows button).
    I have read several threads in this forum, but I do not know how to solve this problem.

    This does not work.
    In my first post I made an mistake in describing my application, it is not a table-form, but a tree-form application:
    Group 1, Table a, Layout: tree-form
    Group 2, Table b, Layout: tree-form
    Group 3, Table c, Layout: tree-form
    Group 4, Table d, Layout: form (on same page as master table c)
    If I override the executeQueryForCollection method in the ViewObjectImpl of table d I get a message ('JBO-27122: SQL-fout tijdens voorbereiding van statement' and 'java.sql.SQLException: OALL8 is in an inconsistent state').
    while clicking on the tree (with table b and c). It seems that the QueryForCollection method is being executed to early.

  • Automatic app updates in iOS 8, only when not signed in with Apple ID?

    Just updated to iOS 8, and discovered an odd issue, as follows:
    One of my favorite additions of iOS 7 was the automatic app updates, because I do not have access to the app store. My app store is locked under restrictions, but with automatic updates I had no need for the app store in order to update my existing apps.
    Well, I just updated to iOS 8, and I find that there is only an option for automatic app updates when the app store is open, but as soon as the app store is locked through restrictions, the automatic updates option disappears. And to add to the mystery, the only way to get it back is by SIGNING OUT of my Apple ID. When I do that, the automatic music downloads option disappears, and it is replaced by an option for automatic app updates.
    Is this intentional? Why on Earth is there no option for auto updates when signed in, only when signed out? I can't make any sense of it. Any help would be appreciated.
    Other than that, iOS 8 is awesome so far.

    Just updated to iOS 8, and discovered an odd issue, as follows:
    One of my favorite additions of iOS 7 was the automatic app updates, because I do not have access to the app store. My app store is locked under restrictions, but with automatic updates I had no need for the app store in order to update my existing apps.
    Well, I just updated to iOS 8, and I find that there is only an option for automatic app updates when the app store is open, but as soon as the app store is locked through restrictions, the automatic updates option disappears. And to add to the mystery, the only way to get it back is by SIGNING OUT of my Apple ID. When I do that, the automatic music downloads option disappears, and it is replaced by an option for automatic app updates.
    Is this intentional? Why on Earth is there no option for auto updates when signed in, only when signed out? I can't make any sense of it. Any help would be appreciated.
    Other than that, iOS 8 is awesome so far.

  • Problem with 5.2 install - idsgroup does not exist

    All,
    I am trying to install Sun ONE Directory Server 5.2 on a new Cluster. The idsuser and idsgroup have been both setup with the id 10000.
    I have created a silent install file to work with the ./setup -noconsole -nodisplay -state silent.inf command.
    When I run the command as idsuser - but the setup command has been sudo-ed - I get the following error:
    Idsgroup does not exist.
    Ive done a grpck and a idchk and both have come back as being OK? Is there an issue where the install will only work if you run it as Root and not sudo-ed?
    Both group and idsuser show in the correct way in /etc/group and /etc/passwd.
    Any ideas would be gratefully received as this is now becoming quite urgent.
    Thanks
    og

    All,
    I am trying to install Sun ONE Directory Server 5.2
    on a new Cluster. The idsuser and idsgroup have been
    both setup with the id 10000.
    I have created a silent install file to work with the
    ./setup -noconsole -nodisplay -state silent.inf
    command.
    When I run the command as idsuser - but the setup
    command has been sudo-ed - I get the following
    error:
    Idsgroup does not exist.
    Ive done a grpck and a idchk and both have come back
    as being OK? Is there an issue where the install will
    only work if you run it as Root and not sudo-ed?
    Both group and idsuser show in the correct way in
    /etc/group and /etc/passwd.
    Any ideas would be gratefully received as this is now
    becoming quite urgent.
    Thanks
    ogHi ,
    Did you get this figured out yet? I'm facing the exact same problem. Doesn't seem to make any sense.
    Thanks,
    Tito

  • Query Governor - Summary Data - Only when not out of date?

    In Oracle Discoverer Desktop edition the user can choose how Summary Data are used:
    1. Always, when available
    2. Only when summary data are not out of date (stale)
    3. Never
    What exactly is the meaning of "Only when summary data are not out of date"?
    In previous versions of Discoverer you had the opportunity to specify how old (in days) summary tables were acceptable to you.
    (By the way: In the Danish translation of Discoverer the word "not" has been omitted, so you have the opportunity to use summary data only when they are out of date :-)
    Best regards
    Torben

    Actually it doesn't matter if you have Applecare or not because Apple simply isn't recognizing this as an issue even though multitudes of people have experienced it. If they don't see it as a problem, then they obviously don't have a solution, and so taking your laptop in through apple care is totally useless.
    I've talked to 3 customer support representatives over the phone and they all said they were 'unaware of the issue' and would not even attempt to help. It's very disappointing.

  • Problem with PGI - Sales Order stock does not exist

    Hi
    I created order 58161 with 1 item line (10).
    Did a delivery and created a Picking Request (which i released via transaction VL08).
    When i try to do PGI i get following message:
    Sales order stock 58161 000010 does not exist.
    I have previously done a similar order with same material and so on and it went through the system without a hitch.
    I have checked the other threads, is this where i have to use MB1B and mov.type 412 E to move unrestricted goods to sales order stock?
    Thx
    RM

    Hi,
    first u check stock at tcode:MMBE for ur material ,plant and storage location.If u dont have stock than create stock through goods receipt:mb1c.[movement type 501 e,enter ur sales order no.,item no.],I think it will solve than

  • Insert when not exists

    Is there anyway of getting owb to implement the following sql without
    resorting to using a insert update operation:
    insert into desttable
    (select * from myview where not exists (select null from b where desttable.emp_id=myview.emp_id)
    This sounds almost like the perfect application for an insert/update (or merge)
    operation. But in my case, I do not want to update the destination tables if I get
    a match, I am only interested in using the insert part of a merge operation. I could
    create a dummy update clause, but that would be a waste of resources.
    Any ideas?
    Graeme

    What I've done in this situation, and there might be a better way, is use an outer join. Essentially, I do this:
    insert into desttable (
    select a.*
    from mytable a, desttable b
    where a.emp_id = b.emp_id(+)
    and b.emp_id is null
    I believe this accomplishes the same thing as "not exists".
    Message was edited by:
    user631136

  • I have been using xfinity for some time with no problem. Now when I open it, it shuts down. I have reset, restarted, and done a sync. I also deleted and reloaded to no avail

    I have been using the xfinity ap for some time with no problem. Now every time I open the ap it shuts down. I have updated software, reset, done a sync, rebooted to no avail any ideas

    My Xfinity App does the same thing.  Hope they are coming out with a app update.

Maybe you are looking for

  • Forms system potential migration questions.

    We have a forms and reports based system built in 10g. We are considering migrating to 11g forms and reports but long term moving to ADF or APEX. We are generally a data entry system run on intranet so my prefernence has always been APEX but manageme

  • Cannot locate iphone in itunes

    Cannot locate iphone 4S in Itunes, using Windows vista, device driver in-compatible driver thinks its digital camera.Please help

  • Advanced datagrid question

    Hi All, I have an ADG displaying items in groups showing totals for each group using:           private function summFunc(cursor:IViewCursor, dataField:String, operation:String):Number{                 var sumAll:Number = 0;                 while (!c

  • Why i can't download on Nokia C2-03?

    I try to download files such as games or applications, but i got the errorr 006. What is that

  • Can I add additional lenses to Lens Peripheral Illumination Correction?

    Can I add an additional lens, one that is not listed in the Canon 7D, Lens Peripheral Illumination Connection?  Specifically I am interested in adding the Tamrom 18-270 lens.