Solved

What am I missing in a trigger that I am trying to create on a table

Posted on 2009-05-06
5
448 Views
Last Modified: 2013-12-11
I am trying to create a trigger that inserts a record in table c that is created on table b after dml is performed on table a. If that is confusing let me try this: there are 3 tables, table 1 has records, table 2 creates records everytime a user performs dml on table 1, table 2 is a log table that is used to refresh data in a fast refresh materialized view. So whenever a refresh occurs that table gets purged. I want to keep the records in that table. So I created another table (table 3) and I want the records in table 2 to be written to table 3 whenever a dml statement is done a record in table 1. I am not sure of what the most efficient way of doing this. I have tried the following:

create or replace trigger MVIEW_HOLDINGS_T
AFTER INSERT OR UPDATE OR DELETE ON HOLDINGS
begin
insert into FAST_UPDATE_INDEX (site, name, SNAPTIME$$, DMLTYPE$$, OLD_NEW$$,
 CHANGE_VECTOR$$) VALUES (site, name, SNAPTIME$$, DMLTYPE$$, OLD_NEW$$, CHANGE_VECTOR$$) from MLOG$_HOLDINGS where name.holdings=pdf_name.MLOG$_HOLDINGS and site.holdings=site.MLOG$_HOLDINGS;
end;
/

I type show errors and get the following: Errors for TRIGGER MVIEW_BIB_HOLDINGS_T:

LINE/COL ERROR
-------- -----------------------------------------------------------------
2/1      PL/SQL: SQL Statement ignored
2/174    PL/SQL: ORA-00933: SQL command not properly ended

could someone tell me what is wrong?

create or replace trigger MVIEW_HOLDINGS_T
AFTER INSERT OR UPDATE OR DELETE ON HOLDINGS
begin
insert into FAST_UPDATE_INDEX (site, name, SNAPTIME$$, DMLTYPE$$, OLD_NEW$$,
 CHANGE_VECTOR$$) VALUES (site, name, SNAPTIME$$, DMLTYPE$$, OLD_NEW$$, CHANGE_VECTOR$$) from MLOG$_HOLDINGS where name.holdings=pdf_name.MLOG$_HOLDINGS and site.holdings=site.MLOG$_HOLDINGS;
end;
/

Open in new window

0
Comment
Question by:sikyala
  • 3
  • 2
5 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24318482
not VALUES, but SELECT:
create or replace trigger MVIEW_HOLDINGS_T
AFTER INSERT OR UPDATE OR DELETE ON HOLDINGS
begin
insert into FAST_UPDATE_INDEX (site, name, SNAPTIME$$, DMLTYPE$$, OLD_NEW$$,
 CHANGE_VECTOR$$) 
  SELECT site, name, SNAPTIME$$, DMLTYPE$$, OLD_NEW$$, CHANGE_VECTOR$$ 
    FROM MLOG$_HOLDINGS 
   WHERE name.holdings=pdf_name.MLOG$_HOLDINGS 
     AND site.holdings=site.MLOG$_HOLDINGS;
end;
/

Open in new window

0
 

Author Comment

by:sikyala
ID: 24318563
I changed the trigger and got the following error:

Warning: Trigger created with compilation errors.

SQL> sho errors
Errors for TRIGGER MVIEW_BIB_HOLDINGS_T:

LINE/COL ERROR
-------- -----------------------------------------------------------------
2/1      PL/SQL: SQL Statement ignored
3/176    PL/SQL: ORA-00904: "SITE"."MLOG$_HOLDINGS": invalid
         identifier

The site field does exist in the MLOG$_HOLDINGS table
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24318792
you are missing a join  in the query, indeed..
also, you don't refer to the NEW / OLD information to limit the rows to be inserted...
0
 

Author Comment

by:sikyala
ID: 24319319
how would I do that?
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24319441
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ORA-00923: FROM keyword not found where expected 3 80
Oracle Query - Return results based on minimum value 8 35
Oracle collections 15 27
Checking for column width 8 28
This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question