Question

Dynamic Create Trigger: Success with compilation error?

Asked by: thuannc

I have a Stored Procedure which create a trigger dynamic. When I run it is created trigger with following error:

Error -24344: ORA-24344: success with compilation error
ORA-24344: success with compilation error
ORA-06512: at line 8
Then I open that trigger change any character, For example: add a blank anywhere in trigger body (not change trigger's content) then re-compile so it is valid
--> What happen with it?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2002-04-02 at 22:15:12ID20284371
Tags

trigger

Topic

Oracle Database

Participating Experts
3
Points
50
Comments
8

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. trigger
    1- i'm using trigger befor and inside of the trigger i'm using output from the :new and :old tabes, but iven i have the singl line dbms_output, some how trigger display the same values 2 times. If i use after, the trigger display only 1 time, why? 2- How can i terminat the u...
  2. trigger
    Oracle9ias does not support trigger on web ? What can we do?Give me any suggestion. Thank you
  3. When/IF does a trigger compile
    Please help settle an office discussion. One of my colleagues states that a trigger is only stored. Another states that a trigger is compiled because if you try to create a trigger which has an error it returns "success with compilation error". I've trolled throug...
  4. Trigger
    Fits of all, I'm a beginner in Oracle and my management'd like to use triggers. So, I've created the following trigger : CREATE TRIGGER UPD_HISTORY AFTER INSERT ON amHistory FOR EACH ROW DECLARE TheNewId NUMBER(8) ; BEGIN If :old.HistObjTable = 'amApplication' Then T...
  5. Trigger problems
    I'm having problems with a procedure that i want to implement in my database .... Oracle 8 I created a procedure for the database but the triggers don't work.. Here is my procedure ... It compiles fine but when I try to run it I get the following errors. CREATE OR REPLAC...
  6. truncating trigger and pl/sql character numeric conversion …
    I am getting this error basically this trigger updates the information of table 'x' into table 'y' everytime the x.column is updated. I did not get the error the first time..It works for some rows and for some rows it gives the below error ERROR at line 1: ORA-06502: PL/SQL:...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: DrSQLPosted on 2002-04-03 at 06:21:41ID: 6915349

thuannc,

   Try posting a before and after example of the trigger code.  Also try posting the stored procedure.

   Something for you to check while we all look at that is the syntax of your create trigger:

  Since you are changing the stored trigger (when you "open that trigger change any character...then re-compile so it is valid") there could be a syntax error in the create-trigger-string that isn't making it into the stored trigger and the only reason it is "working" is because you recompiled it.  Did you put a trailing "/" at the end (you shouldn't) or some other extraneous character(s) that aren't showing up in the trigger you later "open"?

Good luck!

 

by: markgeerPosted on 2002-04-03 at 14:09:47ID: 6916437

This could be a security issue.  When you "open the trigger.. [and] recompile" it, which tool or application do you use for that?  Whichever tool you use likely gets the benefit of role-based security.  This is different than your PL\SQL procedure has when it runs, since PL\SQL does not have the benefit of role-based grants.  It uses only direct (user-based) grants and/or system privileges (like "alter any table", etc.).  

To build or modify a trigger dynamically with PL\SQL you may need to grant the owner of your PL\SQL procedure the "create any trigger" and "alter any trigger" system privileges.  I'm not sure I would want that risk in a production database.  Is modifying the trigger text the only way to accomplish what you need?  It may be safer and easier to modify data in a control table, and have the trigger read from the control table to modify its action based on the data it finds there.

 

by: thuanncPosted on 2002-04-03 at 17:15:31ID: 6916839

1. user who excute that proc has create and alter any trigger system privileges and DBA
2. There isn't any trailing "/" at the end
3. This is my code

PROCEDURE CREATE_AUDIT_TRIGGER
  (p_table_name IN VARCHAR2)
AS
  CURSOR c1 IS SELECT * FROM audit_info WHERE table_name = UPPER (p_table_name);
  v_sql            VARCHAR2 (4000) := NULL;
  v_table_name     VARCHAR2 (30)   := NULL;
  cid2             INTEGER;
  result_set       INTEGER;
  column_fix      VARCHAR2(200);
  value_fix      VARCHAR2(200);
  column_list      VARCHAR2(200);
  value_list      VARCHAR2(200);
BEGIN
  v_table_name := RTRIM(LTRIM(SUBSTR(RPAD(p_table_name, 30),1,21)));
  cid2 := DBMS_SQL.OPEN_CURSOR;  
  v_sql :=
      'CREATE OR REPLACE TRIGGER ' || v_table_name || '_audit_trig' || CHR(13)|| CHR(10)
  ||  ' AFTER INSERT OR DELETE OR UPDATE ON ' || v_table_name || CHR(13)|| CHR(10)
  ||  ' FOR EACH ROW' || CHR(13)|| CHR(10)
  ||  ' DECLARE' || CHR(13)|| CHR(10)
  ||  ' s_id VARCHAR2(10);' || CHR(13)|| CHR(10)
  ||  ' usr VARCHAR2(20);' || CHR(13)|| CHR(10)
  ||  ' BEGIN ' || CHR(13)|| CHR(10)
  ||  ' s_id:=AUDIT_PKG.GET_SESSION_ID;' || CHR(13)|| CHR(10)
  ||  ' usr:=AUDIT_PKG.GET_USER_NAME;' || CHR(13)|| CHR(10);
  column_fix:='INSERT INTO audit_log(rec_id,table_name,session_id,user_name,action_date,action';
  for rec in c1 loop
  column_list:='';
  value_list:='';
  if rec.key_column_1 is not null then
    column_list:=column_list || ',key_column_1';
    value_list:=value_list || ',' || ' :NEW.' || rec.key_column_1 ;
  end if;
  if rec.key_column_2 is not null then
    column_list:=column_list || ',key_column_2';
    value_list:=value_list || ',' || ' :NEW.' || rec.key_column_2;
  end if;
  if rec.key_column_3 is not null then
    column_list:=column_list || ',key_column_3';
    value_list:=value_list || ',' || ' :NEW.' || rec.key_column_3;
  end if;
  if rec.c_column_1 is not null then
    column_list:=column_list || ',c_column_1';
    value_list:=value_list || ',' || ' :NEW.' || rec.c_column_1;
  end if;
  if rec.c_column_2 is not null then
    column_list:=column_list || ',c_column_2';
    value_list:=value_list || ',' || ' :NEW.' || rec.c_column_2;
  end if;
    if rec.c_column_3 is not null then
    column_list:=column_list || ',c_column_3';
    value_list:=value_list || ',' || ' :NEW.' || rec.c_column_3;
  end if;
    if rec.c_column_4 is not null then
    column_list:=column_list || ',c_column_4';
    value_list:=value_list || ',' || ' :NEW.' || rec.c_column_4;
  end if;
 if rec.c_column_5 is not null then
    column_list:=column_list || ',c_column_5';
    value_list:=value_list || ',' || ' :NEW.' || rec.c_column_5;
  end if;
  if rec.n_column_1 is not null then
    column_list:=column_list || ',n_column_1';
    value_list:=value_list || ',' || ' :NEW.' || rec.n_column_1;
  end if;
  if rec.n_column_2 is not null then
    column_list:=column_list || ',n_column_2';
    value_list:=value_list || ',' || ' :NEW.' || rec.n_column_2;
  end if;
    if rec.n_column_3 is not null then
    column_list:=column_list || ',n_column_3';
    value_list:=value_list || ',' || ' :NEW.' || rec.n_column_3;
  end if;
    if rec.n_column_4 is not null then
    column_list:=column_list || ',n_column_4';
    value_list:=value_list || ',' || ' :NEW.' || rec.n_column_4;
  end if;
    if rec.d_column_1 is not null then
    column_list:=column_list || ',d_column_1';
    value_list:=value_list || ',' || ' :NEW.' || rec.d_column_1;
  end if;
  if rec.d_column_2 is not null then
    column_list:=column_list || ',d_column_2';
    value_list:=value_list || ',' || ' :NEW.' || rec.d_column_2;
  end if;
  if rec.d_column_3 is not null then
    column_list:=column_list || ',d_column_3';
    value_list:=value_list || ',' || ' :NEW.' || rec.d_column_3;
  end if;
  exit;
  end loop;
  for rec in c1 loop
      if rec.audit_insert is not null then
          value_fix:='VALUES(audit_seq.nextval,'''|| v_table_name ||''',s_id,usr,SYSDATE,''I''';
          v_sql:=v_sql || 'IF INSERTING THEN '|| CHR(13)|| CHR(10);
          v_sql:=v_sql || column_fix || column_list || ') ';
          v_sql:=v_sql || value_fix || value_list || '); ' || CHR(13)|| CHR(10);
          v_sql:=v_sql || 'END IF;' || CHR(13)|| CHR(10);
      end if;
      if rec.audit_delete is not null then
          value_fix:='VALUES(audit_seq.nextval,'''|| v_table_name ||''',s_id,usr,SYSDATE,''D''';
          v_sql:=v_sql || 'IF DELETING THEN '|| CHR(13)|| CHR(10);
          v_sql:=v_sql || column_fix || column_list || ') ';
          v_sql:=v_sql || REPLACE(value_fix || value_list || '); ',':NEW.',':OLD.') || CHR(13)|| CHR(10);
          v_sql:=v_sql || 'END IF;'|| CHR(13)|| CHR(10);
      end if;
      if rec.audit_update is not null then
          value_fix:='VALUES(audit_seq.nextval,'''|| v_table_name ||''',s_id,usr,SYSDATE,''O''';
          v_sql:=v_sql || 'IF UPDATING THEN '|| CHR(13)|| CHR(10);
          v_sql:=v_sql || column_fix || column_list || ') ';
          v_sql:=v_sql || value_fix || value_list || '); '|| CHR(13)|| CHR(10);
          value_fix:='VALUES(audit_seq.currval,'''|| v_table_name ||''',s_id,usr,SYSDATE,''N''';
          v_sql:=v_sql || column_fix || column_list || ') ';
          v_sql:=v_sql || REPLACE(value_fix || value_list || '); ',':NEW.',':OLD.')|| CHR(13)|| CHR(10);
          v_sql:=v_sql || 'END IF;'|| CHR(13)|| CHR(10);
      end if;
      exit;
  end loop;
  v_sql := v_sql  ||  'END;';
  DBMS_SQL.PARSE(cid2,v_sql,DBMS_SQL.NATIVE);
  result_set := DBMS_SQL.EXECUTE (cid2);
  DBMS_SQL.CLOSE_CURSOR (cid2);
END;

and this is trigger created

CREATE OR REPLACE TRIGGER chuc_vu_audit_trig
AFTER INSERT  OR DELETE  OR UPDATE
ON chuc_vu
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
 s_id VARCHAR2(10);
 usr VARCHAR2(20);
 BEGIN
 s_id:=AUDIT_PKG.GET_SESSION_ID;
 usr:=AUDIT_PKG.GET_USER_NAME;
IF INSERTING THEN
INSERT INTO audit_log(rec_id,table_name,session_id,user_name,action_date,action,key_column_1,key_column_2) VALUES(audit_seq.nextval,'chuc_vu',s_id,usr,SYSDATE,'I', :NEW.MA_SO, :NEW.TEN);
END IF;
IF DELETING THEN
INSERT INTO audit_log(rec_id,table_name,session_id,user_name,action_date,action,key_column_1,key_column_2) VALUES(audit_seq.nextval,'chuc_vu',s_id,usr,SYSDATE,'D', :OLD.MA_SO, :OLD.TEN);
END IF;
IF UPDATING THEN
INSERT INTO audit_log(rec_id,table_name,session_id,user_name,action_date,action,key_column_1,key_column_2) VALUES(audit_seq.nextval,'chuc_vu',s_id,usr,SYSDATE,'O', :NEW.MA_SO, :NEW.TEN);
INSERT INTO audit_log(rec_id,table_name,session_id,user_name,action_date,action,key_column_1,key_column_2) VALUES(audit_seq.currval,'chuc_vu',s_id,usr,SYSDATE,'N', :OLD.MA_SO, :OLD.TEN);
END IF;
END;

Please help me

 

by: markgeerPosted on 2002-04-04 at 14:14:02ID: 6919391

It looks like you are using PL\SQL to generate (potentially at least) lots of triggers for you dynamically.  That should work, in fact it looks like you have almost everything right.  You may be missing something very small, like maybe a "/" on the last line.

I would suggest creating a very simple test procedure first to create just one simple trigger on one table using all hard-coded values.  If you can get that to work successfully, then you most likely can get his much more complex process to work as well.

I have a couple other comments and questions though:
1. Which version of Oracle do you have?  If you have 8.1.5 or higher you can use the simpler, faster "execute immediate" syntax instead of "dbms_sql".

2. Triggers like this may generate a huge volume of audit data.   You may be able to reduce that and still have what you need.  If your records all have timestamps and user_id, then you wouldn't need any audit data for inserts, and you wouldn't need the ":new" values for updates, since all of that data is available in the triggering table.

3. Another way that can greatly reduce the volume of audit data is to have a history table for each table being audited that contains all of the column of the base table, plus a timestamp and user_id column if they are not already part of the base table, instead of one central audit table to track records for all tables.  Then (assuming that the base table captures the timestamp and user_id when records are inserted or updated) you only need a post-update trigger to write the primary or unique key field(s) plus  the :old values only for the column(s) actually changed.  You can use "decode" in your trigger to to do this.  You don't need to write anything to the audit tables following an insert then.  If the table allows deletes, you will need a pre-delete trigger as well to write all the field to the audit table.

 

by: thuanncPosted on 2002-04-04 at 17:19:32ID: 6919745

1. the "/" is not need because when I append / to last line of trigger. The compilation still error.
2. I'm using 8.0.4 so it does'nt support execute immediate
3. if create history table for each I have to control a lot of tables dynamicly.

 

by: soraPosted on 2002-04-04 at 22:05:48ID: 6920117

when you get this error ORA-24344, did you check the status of the trigger in DBA_TRIGGERS? What was it?

sora

 

by: DrSQLPosted on 2002-04-05 at 06:24:44ID: 6920832

thuannc,
   Get rid of the chr(13), chr(10).  You don't need them (just a space between words is needed).  These are probably the illegal characters, but they're stripped off by the program that reads the trigger later and resubmits it.  That's the reason for the mysterious "change and character and it works" behavior.

Good luck!

 

by: thuanncPosted on 2002-04-05 at 17:40:46ID: 6922182

1. DrSQL, you are right but trigger body is a bit argly. Thank a lot

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...