Home » SQL & PL/SQL » SQL & PL/SQL » Multiple Records in single xml with compound trigger
Multiple Records in single xml with compound trigger [message #624292] Sat, 20 September 2014 07:21 Go to next message
shannu
Messages: 1
Registered: September 2014
Location: India
Junior Member
I am working in a java application with Oracle as DataBase.
I have a new requirement of generating customised xml instantaneously on insert /update of records in a table.
I have to even log the details of ids in another table.
Below is the detailed structure of codes available as of now.

/*table 1*/
create table table1(
id NUMBER NOT NULL, -->pk
code VARCHAR2(50) NOT NULL);

/*table 2*/
create table table2(
id NUMBER NOT NULL, --->pk
referred_id NUMBER NOT NULL, --->fk(pk of table1)
action_mode VARCHAR2(20) NOT NULL,
xml_to_be_generated VARCHAR2(1) NOT NULL);

I have compound trigger on each tables.

/*Trigger on Table1*/
Before Statement --> Initialised variables;
After Each Row --> Inserting into type;
After Statement --> Inserting into Table2(Used FORALL to insert the records from table1)

/*Trigger on Table2*/
Before Statement --> Initialised variables;
After Each Row --> Inserting into type;
After Statement --> Call to xml generation Procedure which generates the xml and places in a folder.


I am saving three records from screen in a single transaction/session as below.
insert into table1 values(1,'C1');
insert into table1 values(2,'C2');
insert into table1 values(3,'C3');
commit;

But the records are getting saved individually hence generating 3 xmls.
insert into table1 values(1,'C1'); --> insert into table2 values(1,1,'INSERT','Y');---> xml-1
insert into table1 values(2,'C2'); --> insert into table2 values(2,2,'INSERT','Y');---> xml-2
insert into table1 values(3,'C3'); --> insert into table2 values(3,3,'INSERT','Y');---> xml-3

But my requirement is to generate single xml as

insert into table1 values(1,'C1');
insert into table1 values(2,'C2');
insert into table1 values(3,'C3');--> xml-1

Please share your inputs on this.
Re: Multiple Records in single xml with compound trigger [message #624293 is a reply to message #624292] Sat, 20 September 2014 07:36 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
Welcome to the forum. Please read our OraFAQ Forum Guide and please read How to use [code] tags and make your code easier to read

I cannot offer a solution to your problem, other than to say that the whole design looks weird. Doing things like that is not the way a relational engineer would do it. Why two tables? If you must have two, why do you not use a single multitable insert statement, instead of messing about with triggers? Why are you storing the XML doc as a file, rather than in the database?

Generally speaking, if you find that you are doing complex logic in a trigger, you are probably doing something wrong. But I know that Java programmers often use the database in ways for which it was not intended - perhaps someone else can advise.
Re: Multiple Records in single xml with compound trigger [message #624303 is a reply to message #624293] Sat, 20 September 2014 09:35 Go to previous message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
why do you insist that the solution involves Oracle triggers as opposed to being done directly by this wonderous Java application directly?
Previous Topic: Table LOCK in PeopleSoft Program
Next Topic: Reference for values in SYS.AUD$.STATEMENTID
Goto Forum:
  


Current Time: Thu Apr 25 04:38:23 CDT 2024