It does not work when you use the trigger to check the data of the other table.

Please help me with this, I put a trigger on a table, but it can not work as I expect.

case study: a class has many students, one of them is going to match.
The purpose of this trigger is to check when to choose a student going to match, this student has in his class where it belongs to.
Oracle version is 10.2.0.1.0.
--table:
DROP TABLE STU;
DROP TABLE CLASS;

create table CLASS(
CID     VARCHAR2(5)   PRIMARY KEY,
CNAME   VARCHAR2(20)  NOT NULL,
SCHOSEN VARCHAR2(5));
 
create table STU(
SID     VARCHAR2(5)   PRIMARY KEY,
SNAME   VARCHAR2(20)  NOT NULL,
CID     VARCHAR2(5)   NOT NULL REFERENCES CLASS(CID) ON DELETE CASCADE);

--data:
--CLASS
INSERT INTO CLASS(CID,CNAME) VALUES(1,'SUN');
INSERT INTO CLASS(CID,CNAME) VALUES(2,'MOON');
INSERT INTO CLASS(CID,CNAME) VALUES(3,'EARTH');
--STU
INSERT INTO STU VALUES(1,'JACK',1);
INSERT INTO STU VALUES(2,'TOM',1);
INSERT INTO STU VALUES(3,'LILY',2);
INSERT INTO STU VALUES(4,'DUSTIN',3);

--TRIGGER
CREATE OR REPLACE TRIGGER CHECK_SCHOSEN
BEFORE INSERT OR UPDATE OF SCHOSEN ON CLASS
FOR EACH ROW WHEN (NEW.SCHOSEN IS NOT NULL)

DECLARE
DUMMY INTEGER;
INVALID_STU EXCEPTION;
VALID_STU EXCEPTION;
MUTATING_TABLE EXCEPTION;
PRAGMA EXCEPTION_INIT(MUTATING_TABLE, -4091);

CURSOR DUMMY_CURSOR (ST VARCHAR2, CL VARCHAR2) IS
  SELECT SID FROM STU, CLASS
  WHERE STU.SID=ST AND STU.CID=CLASS.CID AND CLASS.CID=CL
    FOR UPDATE OF CLASS.SCHOSEN;

BEGIN
  OPEN DUMMY_CURSOR(:NEW.SCHOSEN, :NEW.CID);
  FETCH DUMMY_CURSOR INTO DUMMY;
  IF DUMMY_CURSOR%NOTFOUND THEN
    RAISE INVALID_STU;
  ELSE
    RAISE VALID_STU;
  END IF;
  CLOSE DUMMY_CURSOR;
EXCEPTION
  WHEN INVALID_STU THEN
    CLOSE DUMMY_CURSOR;
    DBMS_OUTPUT.PUT_LINE('PLEASE RE-ENTER CLASS ID AND STUDENT ID AS CLASS OR STUDENT IS NOT VALID.');
  WHEN VALID_STU THEN
    CLOSE DUMMY_CURSOR;
    DBMS_OUTPUT.PUT_LINE('STUDENT CHOOSE SUCCEFULLY!');
  WHEN MUTATING_TABLE THEN
    NULL;
END;
/
Just copy and paste on it and try to run next:
UPDATE CLASS
SET SCHOSEN = 3
WHERE CID = 1;
Clearly, you can't student who is 3 as to Member of class 1. Please help me. Thank you.

Published by: 991096 on March 1st, 2013 02:36

Published by: 991096 on March 1st, 2013 03:03

Published by: 991096 on March 1st, 2013 03:11

Hello

991096 wrote:
1. the purpose of this trigger is to check when to choose a student going to match, this student has in his class where it belongs to. Then, when I try to choose 3 student-member of correspondence of class 1, should give me "PLEASE RE-ENTER ID AND STUDENT ID AS CLASS or STUDENT not IS NOT VALID."

Then do something like this:

CREATE OR REPLACE TRIGGER CHECK_SCHOSEN
BEFORE INSERT OR UPDATE OF SCHOSEN ON CLASS
FOR EACH ROW WHEN (NEW.SCHOSEN IS NOT NULL)
DECLARE
    sid_found     stu.sid%TYPE;
BEGIN
    dbms_output.put_line (:NEW.schosen || ' = schosen entering check_schosen');             SELECT  sid
         INTO    sid_found
     FROM      stu
     WHERE     sid     = :NEW.schosen
     AND     cid     = :NEW.cid
     AND     ROWNUM     = 1     -- to avoid TOO_MANY_ROWS
     ;
EXCEPTION
    WHEN  NO_DATA_FOUND
    THEN
     RAISE_APPLICATION_ERROR ( -20000
                    , 'Please re-enter class id and student id as class ('
                      || :NEW.cid
                      || ') or student ('
                      || :NEW.schosen
                      || ') is not valid.'
                    );
end;
/

DBMS_OUTPUT creates only a message. The message may not be displayed, and if this is the case, then the user cannot see it. The DML will still take place.
I used instead, RAISE_APPLICATION_ERROR to keep the DML does not happen. It displays a message like

ORA-20000: Please re-enter class id and student id as class (1) or student (3) is not valid.

' 2 ' game ' means ' an official competition in which two several people or teams competing.

What individuals or teams are competing in this case?
In any case, the question wasn't 'that 'game' means', but

Frank Kulash wrote:
What do you mean when you say "going to match?

I think that now you're saying that the new values of (class.cid, class.schosen) must be equal to (or "fit") some existing (stu.cid, stu.sid).

3. thanks for your tip, I learned how to use '{code} '.

4. it's really goes with the exception of MUTATING_TABLE. So, how do to fix the trigger to show me INVALID_STU EXCEPTION when I try to choose a student does not belong
a class?

Don't refer to the table of class in the trigger, and the error table mutation occur. All the information you need are in the stu table, so there is no need to query the table of class, anyway.

Tags: Database

Similar Questions

  • setActionListener does not work when you use the pop-up

    Hello

    My requirement I need to send a value to the front to call popup.

    < af:commandButton text = 'empty '.
    Binding = "#{backingBeanScope.backing_authorizationLookup2.CB1} '"
    ID = "cb1" disabled = "#{securityContext.userInRole [' survey internal-cardauthui '] or links.}" Don't AuthorizationStatus.inputValue 'NEW' or links. "{ParentAuthNum.inputValue don't row.bindings.AuthorizationNumber.inputValue}" partialTriggers = "t1" >
    < af:setActionListener from = "#{false}.
    to = "#{pageFlowScope.cancelResultFlag}" / >
    < af:showPopupBehavior popupId = "p4" / >
    < / af:commandButton >

    This indicator is not set, can any help me how can set this flag value before calling to the pop-up window.

    Try to set triggerType = 'click' on the showPopupBehavior and contentDelivery = "lazyUncached" on the context menu.

    Pedja

  • Acer toggle display does not display when you use the Fn + F5 key secret on my Acer Aspire 5560

    What it does:

    When you use the Fn + F5 key combination on my Acer Aspire 5560, it brings up a screen changes on the laptop screen for the selection of an external monitor, I am currently using Windows 7 Ulitmate

    Before the problem:

    Display mode switch Acer existed prior to the upgrades of the drivers

    The problem:

    The toggle screen Acer does not display when you use the Fn + F5 key secret on my Acer Aspire 5560?

    Additon Information needed to solve the problem or any other information:

    I would like to know what driver or software operates the Acer toggle display Mode?

    Also where can I find this driver for computer: Acer Aspire 5560 to bring this Acer toggle display Mode function?

    Acer Toggle display Mode: this is a picture of it when you use the Fn + F5 combination:

    Thank you very much Ironfly Ace, it has worked Acer hero of the day

  • SpeedGrade CC14 does not open when you use the "Direct Link to Adobe SpeedGrade... "of PremierePro CC14.

    SpeedGrade CC14 does not open when you use the "Direct Link to Adobe SpeedGrade... "of PremierePro CC14.

    I can open the SG of start menu/desktop computer and I can open the PP project in SG very well. The PP project contains 3 deadlines and I take one I want without any problem. Returning to the SG PP works fine as well. It seems only thing doesn't work does not automatically open the PP file and selecting the correct timeline in the Official Journal of the project.

    I had a glance at the "C:\Users\john Bishop images\AppData\Roaming\Adobe\SpeedGrade\8.0\logs\SpeedGrade.log ' but it is not updated when I try to use the link Direct from PP. command It updated when I invoke the start menu/desktop computer SG. Note that none of the other newspaper, the files are updated either (Plugin Loading.log, Database.txt Trace and Debug Database.txt). All these get updated when I run the desktop/start. It would appear that SG is not yet known.

    I uninstalled the SG and the PP and re-installed (all in the directories by default) and everything seemed to go OK but no change.

    I also added 2 political profile the NVIDIA Control Panel, just display a message when loading SpeedGrade.exe and another for a slightly different message when loading SpeedGradeCmd.exe. SG invoking the desktop/start causes the SpeedGrade.exe message to display. Using the 'Direct link' PP file option does not display anything, reinforcing my thought that SG is just never called from PP.

    SP1 Windows 7 Professional 64 bit

    12 GB OF RAM

    2-Intel Xeon E5640 (16 sons) processors

    NVIDIA GeForce GTX580 1536 MB memory graphics

    PS... I used the Adobe cleaning tool noted elsewhere and tried NVIDIA workarounds as well - all to nothing does not.

    Problem solved!

    My Antivirus software was in the way. Once I have updated, things work fine.

    Thanks for your help!

  • Microsoft Pinball Arcade, everything works except the right flipper does not work when you run the game. __Keyboard is very good

    Microsoft Pinball Arcade, everything works except the right flipper does not work when you run the game.
    Keyboard is fine.  Is this a compatibility issue?

    ---------------

  • Call the native browser blackberry OS6 does not work when you use this line Browser.getDefaultSession () .displayPage (url);

    Hello

    I need to invode a native browser showing a Web site using the code below

    Browser.getDefaultSession () .displayPage (url);

    She works in OS5, but does not work for the OS6. Please, someone knows how to solve this problem, too much to guide me

    regards + thank you

    codemobiles.com

    Oh, thanks for your response. (the browser is not called, there is nothing happen)

    Hoowever, the problem is resolved. That's my problem forget to add the "http://" in the url.

    regards + thank you

  • Satellite A100 - line number on the keyboard does not work when you enter the password

    I have an A100 / Pro A100 series satellite laptop, what ever that means.
    Anyway, when you turn the laptop on and asked for a password, I am unable to put in number.
    It appears to the integer line, including BACKSPACE don't work.

    I can use the mouse to select and remove, but that leaves a mark of character in the password box.
    Other buttons work except the row number.

    If I need to connect an external keyboard to verify where I connect (if I can)?
    Any help would be great.

    Can I change the keyboard?

    Hello

    trying to connect a keyboard external usb to check it out. Yes, you can change the keyboard of laptop and it is not a complicated procedure.
    Details how to change keyboard, you can find here

    irisvista.com

    Welcome them

  • Narrative does not work when you create the Windows Movie Maker project

    The narration does not work

    I made 2 projects of film making. Narating was good. Remove all the two projects. Photos as well. And began a 3rd movie, project. This time the narration does not work.

    I made 2 projects of film making. Narating was good. Remove all the two projects. Photos as well. And began a 3rd movie, project. This time the narration does not work.

    ======================================
    I was wondering... work your tape recorder of Windows?

    Windows Vista - sound recording
    http://Windows.Microsoft.com/en-us/Windows-Vista/record-sound

    The following article might be worth a visit:

    How to: Add narration to a movie using Windows Movie Maker in Windows Vista. :-add-a-narration-to-a-movie-using-windows-movie-maker-in-windows-vista https://ask.qut.edu.au/app/answers/detail/a_id/4499/~/how-to.

    John Inzer - MS - MVP - Digital Media Experience - Notice_This is not tech support_I'm volunteer - Solutions that work for me may not work for you - * proceed at your own risk *.

  • Bland Muse - States Panel - Adobe does not work when you use images of filling

    Hi all

    I have a filled rectangle with an image using the control panel of the padding in Muse. I want the rollover State to present a slightly modified image. I have change the rollover State in the States Panel and check the option melted and set it for ease in/out to 0.5 s.

    When I preview/publish my site, the fade does not work. The image flashes just as he would have before the last update.

    The works of bland on the text very well or if I wanted to reduce the opacity of the image in the rollover State, but not one filling to another. Why is this?

    Thanks in advance.

    I see in Firefox, it isn't the transition but Safari it is. So I suspect that this is probably the browser compatibility to have a transition of filling.

  • Windows 7 turn off the display does not work when you use empty screen saver.

    My friend is running Windows 7 x 64 on a desktop and x 32 on a laptop.  He found that if he chooses the screensaver empty (set to 5 minutes) and will display at 10 minutes, the screen never goes round.

    On my laptop, I use the screensaver of ribbons with the same settings and my laptop screen goes off as planned.  However when I go to the screen saver, the display is never off (actually so that empty screen saver was active, my mouse reappears after a certain time).

    There seems to be a Bug with the Windows 7 built in empty screen saver.

    Thoughts, other experiences, etc.? Alex

    Hi archimedes027,

    I hope you are well, I understand you want to listen to music but have no display on your pc.

    If this is correct, there are two options that are available to you first open windows media player, right-click in an empty space at the bottom of the player and select options in the verification of the Advanced box section to enable the screensaver during playback,

    the second option you have is if you use another music player ie itunes then in the section Customization via right click on a empty space on your desktop, select the screen saver options and set it to none, and then click battrey you and together turn display both you need , windows 7 will be dim your office after a short period and in your turn to your screen settings.

    hope this helps let me know

    your

    Ashley

  • Submitting a form does not work when you use form fields

    Hi Topliners,

    We strive to create a POST of an external page to an active form Eloqua.  We spend the Type of preference (Subscribe /Unsubscribe) and the name of Group of email in our POST request so that, when we can drive the presentation of these values for the group by e-mail with the correct Type of preference in Eloqua, and it seems not work. See attachment for the snapshot of our processing steps. We missing something here?

    On another note, what form values are expected when submitting to subscribe or unsubscribe?

    Thank you

    -Syed.

    I could find the answer to that, however, it is of no use in our application.

    We need instead to pass the name of e-mail group, pass id e-mail group.  They are not easy to retrieve and we have our group ID changed so that they cannot be changed or in correspondence.

    To answer the other part of my question, the Subscribe value is '1' and unsubscribe is '0 '.

    -Syed.

  • LOV cascading does not work when you set the value of the parent LOV with DA

    Hi all

    Using APEX 4.2.2.

    I have tow LOVs

    LOV parent article is: P50_TYPE

    Child element LOV is: P50_PROJECT_ID

    In other words in the attributes of the element P50_PROJECT_ID, we have:

    > Cascade LOV Parent article (s): P50_TYPE

    > The items to show page: P50_TYPE

    > The list of values definition: something similar to:

    Select * from mytable where type =: P50_TYPE

    I use DA as run of the JS code to set the value of the P50_TYPE element

    something similar to:

    > $('#P50_TYPE').val (2);

    After doing this, the P50_PROJECT_ID element does not get updated when the P50_TYPE value changes. Namely, P50_PROJECT_ID remains empty, unless the end user manually changes the value of P50_TYPE.

    Any help please?

    Kind regards

    I had a similar experience, he expected a change event, so you can extend the jQuery to be included

    $('#P50_TYPE').val (2) .changes ();

  • Portege M200: registering does not voice when you use the handwriting recognition

    When I'm in "tablet mode" using handwriting text recognition that my Portege M200 regularly presents a message to say, he could not save the speech recognition and I have to switch off the microphone if I do not use it. I often use it to take notes of the meeting so there is always background noise. Usually, text is lost when this message appears. The message will also appear when I save.

    How to turn off the microphone while maintaining the functional handwriting recognition please?

    Just a question: what software do you use for text recognition?

  • The function does not properly when you use the shortcut to insert

    Hello everyone. I am using first Pro CC V9.2 on a PC.  I am as well as a Lynda tutorial and told me quite clearly that using the comma key insert a subclip in my sequence.  However, using the shortcut brings in the full clip, not the sub.  I just bring my subclip using a drag and drop, which is really slow me down.  Anyone know what this could be?

    When you perform your subelements, you Restrict toppings to the limits of a verified subitem?

    MtD

  • Flash does not load when you use the standard account in Windows 7

    I use the latest version of Flash on IE9 RC and on some sites, while that connected to Windows 7 (64-bit) as a standard user, does not Flash, but if I go to my Windows 7 Administrator account and go to the very site where the content Flash won't load, it does not load.

    It's Fancast.com on IE9 RC connected with my standard account of Windows 7:

    http://img695.imageshack.us/i/20110224093054.jpg/

    It's Fancast.com on IE9 RC connected with my Windows 7 admin account:

    http://img403.imageshack.us/i/20110224093021.jpg/

    I tried to uninstall and reinstall Flash and disabling hardware acceleration, but nothing happens.

    Flash sites like YouTube videos, no matter which account I'm connected to.

    Also, when I go to NESN.com on IE9 RC in standard mode, content Flash does not load: http://img684.imageshack.us/i/20110224092957.jpg/

    It started happening yesterday when I upgraded to Windows 7 (64-bit) SP1. I don't know if that has anything to do with it, but it was the last major change made to my system.

    Post edited by: A340-600 - Edit to add correct link.

    It's a matter of current Flash, here is your answer

    http://forums.Adobe.com/thread/729200?TSTART=0

Maybe you are looking for

  • My MacBook 12 regularly gets an analysis of needs of Unix executable file names in her basket

    My MacBook 12 regularly gets a Unix executable file named 'needsanalysis' in his trash. Anyone have any idea why? What is it? What can I do to stop what is happening? I have two laptops on a an environment MBA 2011 and a 2016 MB and it happens on the

  • Satellite Pro A40 can't install windows without using recovery dvd?

    HelloI can't install windows xp pro on my A40 Pro sitting unless I have to use the recovery DVDs including family XP Edition pro.I own a copy of xp pro, but I just can not format the hard drive either through the xp pro Setup or using third party sof

  • Qosmio G30 - 177 broken graphics card

    Hello It seems that I have a broken in my G300 graphics card.The start screen (choice of the bootable media) resembles the matrix ;-(While windows starts, it looks like vertical stripes. The boot process stops with a blue screen.It is also on the int

  • Structural case problem?

    Hello I have a vi in which I three structures (true or false, elected by a button on the front panel). The first case structure works correctly but the second and third do not select properly. (IE, do not loop properly when selected from the front pa

  • Make a key code

    I want a code for my wireless but does not know where to go. Can anyone help?