How can I retrieve the condition in an update or delete using instead of trigger

I have 2 tables, on which a view is created. To distinguish the tables within the view trigger, a column "source" had been added in the view creation. I want to be able to delete row(s) in table t1 or table t2 through the view, depending on a condition. The problem is that I don't know how I can get back the delete condition IN the INSTEAD of trigger :
CREATE TABLE t1(m NUMBER, n VARCHAR2(10), o date);
CREATE TABLE t2(a NUMBER, b VARCHAR2(10), c date);
-- The view is created based on the 2 tables.
CREATE OR REPLACE VIEW vt12 AS
SELECT 't1' source, m, n, o
FROM t1
UNION
SELECT 't2' source, a, b, c
FROM t2;
-- The trigger will fire whenever INSERT is performed on the tables through the view
create or replace trigger tvt12 instead of insert or delete on vt12
begin
if inserting then
if :new.source = 't1' then
insert into t1 values (:new.m, :new.n, :new.o);
else
-- will insert a default value of -1 for the fourth column "d"
insert into t2(a,b,c,d) values (:new.m, :new.n, :new.o, -1);
end if;
elsif deleting then
-- We don't know the condition for the deletion, so all rows from the
-- table from which the current row is coming will be deleted
if :old.source = 't1' then
delete t1;
else
delete t2;
end if;
end if;
end;
show error
insert into vt12 values ('t1',1,'1',sysdate);
insert into vt12 values ('t2',2,'2',sysdate+1);
insert into vt12 values ('t1',3,'3',sysdate+2);
insert into vt12 values ('t2',4,'4',sysdate+3);
insert into vt12 values ('t1',5,'5',sysdate+4);
insert into vt12 values ('t2',6,'6',sysdate+5);
commit;
select * from vt12;
select * from t1;
select * from t2;
delete vt12 where m = 1;
commit;
select * from vt12;
select * from t1;
select * from t2;
When I execute this script, the delete statement seems to recognize that the condition is affecting a row in table t1, and therefore deletes all rows from the table, as specified in the delete statement of the trigger... But, what I want to do is ONLY to delete the row affected by the original condition. So my question is to know how I can get back the original condition for the delete, and still use it in the trigger, that will be executed INSTEAD of the delete statement.. I checked in the doc, and everywhere an example of INSTEAD OF trigger can be found, but it's always and only using an INSTEAD OF INSERT trigger, which doesn't need a condition.
Can anyone help ?
null

I've never faced this case myself, but from the documentation it would seem that the INSTEAD OF DELETE is also a FOR EACH ROW trigger. Therefore, you don't really have to worry about the actual "where" clause of the original "delete" operation: Oracle has it all parsed for you, so you just need to redirect, in turn, each view record being deleted to the appropriate table.
In extenso: for your
delete vt12 where m = 1;
=> the INSTEAD OF trigger fires once for all records in vt12 where m=1, and I would guess that you trigger code should look like:
begin
delete from t1 where m = :old.m and n = :old.n and o = :old.o;
delete from t2 where a = :old.m and b = :old.n and c = :old.o;
end;
It's a bit of overkill compared to the "where" clause of the original "delete" statement, but it should do the job...
BTW, if by any luck you do have some primary key on tables t1 and t2 (say: columns o and c respectively), then obviously you can make the thing simpler:
begin
delete from t1 where o = :old.o;
delete from t2 where c = :old.o;
end;
HTH - Didier

Similar Messages

  • How can we retrieve the Payload information from B2B

    Hello,
    We are trying to send the payload information back to the client for a failed BPEL Transaction from B2B's b2b_instancemessage view. We are enqueing messages to IP_OUT_QUEUE using BPEL. We see the payload coming correctly in the B2B Business Message Reports. But we don't see the payload coming in the b2b_instancemessage view for failed B2B transactions. How can we see the payload in b2b_instancemessage view for failed B2B transactions as well? or How can we retrieve the Payload information from B2B?
    Any help is greatly appreciated! Thanks. - Sam.
    Edited by: user12049162 on Dec 4, 2009 2:04 PM

    I am not sure about the PDK API to get the group name. But using LDAP API its easy to get the User Group.
    If you find the answer to get the group name using PDK API, Please update in forum. It will really help others.
    --Balaji S                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How can I select the condition one by one

    I attaching a VI in which I have two condition less than or equal and greater than or equal. With respect to the input value 0f 125 the condition should be greater than or equal and if it is 175 then it should be less than or equal. So how can I exchange the conditions. Please reply
    Attachments:
    24.1.14 data acquisition reverse corrected-1.vi ‏116 KB

    Hi perumpadapu,
    Can you show me in your code where is this "175" and "125" is coming from? Where do you want to implement your flip logic?
    " I need to relpace the greater than equal to to lesser than equal sign as the 175 becomes 125.So there should be a flip in conditions to be considered. "
    If you want to do some sort of flip conditions based on the integer value received, you can use case structure as below:
    Unless you are very certain that you will not receive any values other than 175 and 125, you can use Select. 
    "Becaus if i use case structure as you said, for the true as well as false case I have to include all these commands to execute in each case. I can't wire the both cases to the same case structure after that."
    Can you provide a screenshot to this issue?
    It would be great if you can explain what you want to do and what your code does.
    Warmest regards,
    Lennard.C
    Learning new things everyday...

  • How can I retrieve a mail message that was accidentally deleted.  It's not in the trashcan.

    How can I retrieve a mail message that was accidentally deleted.  It's not in the trashcan. 

    Which trashcan, mail or osx

  • When importing a CD, the CD Lookup Results dialogue box came up and I choose the wrong CD title.  Now iTunes is importing a different song list than the one on my CD.  How can I retrieve the CD Lookup Results to choose the correct title?

    When importing a CD, the "CD Lookup Results" dialogue box came up and I choose the wrong CD title.  Now iTunes is wanting to import a different song list than the one on my CD.  I've shut down my computer and opened iTunes from the hard drive Program Files and tried to import the CD again with the same problem.  How can I retrieve the "CD Looup Results" diaglogue box to choose the correct CD title to fit the song list on my original CD?

    You might also be able to do it without importing the songs again I think. Just highlight the tracks, right click them and choose "Get Track Names". This feature only works on CDs that were imported via iTunes.

  • I have mistakenly deleted a mail folder which I had created. Can't remember if it was located to 'iCloud' or 'On My Mac'. How can I retrieve the emails contained in this deleted folder? Your help will be immensely appreciated!

    I have mistakenly deleted a mail folder in which I had created. I can't remember if it was located to 'iCloud' or 'On My Mac'. How can I retrieve the emails contained in this deleted folder? Your help will be immensely appreciated!

    Yeah not a problem. It does seem though that if you did not have a Time Machine backup then you may not be able to recover the deleted folder :/ But for future reference to prevent any of this, a Time Machine backup is a great investment.
    What it does is create an entire backup of your computer anything from personal information down to the screen saver.
    What you first need is a new external hard drive (I would recommend a 1TB or higher just to prevent running out of space soon).
    after that, just plug in the drive to your computer.
    once it is plugged in, in the top right hand corner, close to the wi-fi symbol, you should see a symbol that looks like a clock with a backwards arrow around it.
    click on that and select "open time machine preferences"
    just turn the button to the "on" position, and select the backup drive and Time Machine does the rest
    very great tool

  • TS3274 How can I retrieve the iTunes and App icons to my home screen?

    How can I retrieve the missing iTunes and App icons to my iPad home screen?

    If you can't find them on any of your homescreens or app folders, and you can't find them via the spotlight search screen (swipe your first home screen to the right), then are they hidden by Settings > General > Restrictions > Installing Apps and iTunes being set 'off' ?
    If not then have you tried a reset to see if you can find them after the iPad has restarted ? Press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.

  • I am working in the Develop module of Lightroom 5 and have accidentally bumped a setting and lost the Basic menu and the option to retrieve it.  "Tone curve" is directly under the tool bar now.  How can I retrieve the "Basic" menu?

    How can I retrieve the "Basic" menu on Lightroom 5?  I accidentally bumped something while working in the Develop module of Lightroom 5, and now the Tone Curve menu is directly under the Tool Bar, with no option to click on "Basic." 

    Right-click on Tone Curve and choose basic again or press Ctrl+1 in Develop.
    On Mac (Control-Click or Cmd+1)

  • How can we retrieve the name of the Parent Space from the subspace?

    We wish to use a hyperlink in a subspace template which allows a user to link back from the subspace to its parent space.
    This hyperlink should show the name of the parent space.
    These Expression Language Expressions return parent information, but they so not show the Name of the parent space or other details like the Parent Space URL.
    #{spaceContext.currentSpace.parent}
    #{spaceContext.space['bpo'].parent}
    How can we retrieve the name of the Parent Space?

    I agree!
    I can't top this approach.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Satellite A505 - How can I retrieve the registration information

    I purchased a Toshiba A505 in March 2010. At this time I registered the product with Toshiba. This laptop has been stolen. How can I retrieve the registration information. Unfortunately I do not have the serial or product number.
    Thank you.

    Hi
    You should get in contact with Toshiba using the Stolen Units interface.
    http://eu.computers.toshiba-europe.com/innovation/generic/STOLEN_UNITS_SUPPORT
    Here you should go to point: *DEREGISTER*
    Hope I could help you.
    Greets

  • I made a DVD slideshow with premiere elements 4, in 2008. How can I retrieve the photos?

    I made a DVD slideshow with premiere elements 4, in 2008. How can I retrieve the photos?

    Install the excellent 'Search Everything' utility and enter 'extreme' as a search term. Note that when you first run 'Everything' it takes time to index your drive(s). After that though it is a nearly instantaneous start.
    Cheers,
    Neale
    Insanity is hereditary, you get it from your children

  • How can i retrieve the vallue of a component's attribute while enhancing?

    Hi...
    I am new to SAP...and am working with WEB UI Enhancement...
    Can anyone help me to know how can i retrieve the value of the Opportunity status in the component of survey ICCMP_SURVEY?
    And also, which is the field taht i need to change to make the survey non editable?
    I came across an attribute CHANGEABLE in method IS_CHANGEABLE which is being checked before the survey template is opened up..But is it possible to update this field?
    Any helpful pointers would be rewarded...
    Thanks....

    Thanks for the quick replies guys, I will work on that. Wish I could have thought of that before haha, well the only thing that I will need to check later on is gathering all the file paths within one array. Since the main gets called several times with each file selected, I have to gather them all with the serversocket and then when they are all gathered I can begin another piece of code. Dunno if that will be doable. Since I don't know if the user selects 5 or 400 at the same time, I think the serversocket will append to an arraylist every incoming file paths and the UI viewing the file paths will update itself if other file paths are appended.
    Thanks a lot, I will return on that as soon as I am finished.

  • How can I retrieve the inbound XML messages (invoices) by ABAP program?

    Where are the inbound XML messages (invoices) saved in XI box?
    How can I retrieve the inbound XML invoices in XI box by ABAP program?
    Is there any method/BADI/function module to retrieve these XML invoices, so I can output these XML invoices in an ABAP report?
    Thanks in advance for your help!

    Hello Fisher,
    This Webblog will help you.
    /people/alessandro.guarneri/blog/2006/02/14/super-message-monitor-for-sap-xi
    From this blog you will understand the code behind SXMB moni .. which performs the selection from database. You can write a report as well.
    Cheers,
    Himadri

  • How can we retrieve the Porta User in the Webdynpro Application

    Hi,
    How can we retrieve the portal user information in the webdynpro applications?.
    Thanks in Advance
    Chandra.

    Hi Chandra,
    In the init() funtion of your View use client USER API below is the usage of it..
         String Username = "";
         IWDClientUser wdUser = null;
                   try {
                   wdUser = WDClientUser.getCurrentUser();
                   } catch (WDUMException e) {
                   e.printStackTrace();
         IUser user = wdUser.getSAPUser();      
         Username =user.getUniqueName()
    Thanks Raj.
    xxxxxxxxxxxxxxxxxxxxxxxxx
    Edited by: Armin Reichert on Feb 18, 2008 7:27 PM

  • How can i retrieve the lost bookmarks on my ipad ?

    How can i retrieve the lost bookmarks from my ipad ?

    See if this gets them back.
    Quit Safari completely and reboot the iPad. Go to the home screen first by tapping the home button. Double tap the home button and the recents tray will appear with all of your recent apps displayed at the bottom. Tap and hold down on any app icon until it begins to wiggle. Tap the minus  sign in the upper left corner of the app that you want to close. Tap the home button or anywhere above the task bar.
    Reboot the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider if it appears on the screen - let go of the buttons. Let the iPad start up.

Maybe you are looking for

  • DVD from TS folder

    Hi, I created a DVD and kept the video TS folder but deleted the original video assets. Is there a way to burn a new DVD from the data in the video TS folder? Steve.

  • Error while Using RequestResponseBean Module

    hi All, I am trying to use RequestResponseBean Module in one of the scenario as given in these links: http://wiki.sdn.sap.com/wiki/display/XI/UsingRequestResponseBeanModuleinFILE+Adapter http://wiki.sdn.sap.com/wiki/display/XI/File-RFC-File(Without%2

  • Just FYI, new blog post "Windows Server Networking Resources"

    Hi there - Just FYI, new blog post "Windows Server Networking Resources" at http://aka.ms/vrigwx Thanks - James McIllece

  • SAP MM all Tables

    Helo SAP Experts, Kindly tell all kind of tables in SAP MM related. than Edited by: Csaba Szommer on Aug 18, 2011 12:02 PM

  • IPhoto is crashing (v 9.2.2)

    Hi there, I have seen some previous discussions from people with crashing iPhoto software. I am unfortunately having a very frustrating time with this software!! I have followed the instrutions in previous discusssions and have reloaded the software,