Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8662189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:40:24+00:00 2026-06-12T16:40:24+00:00

I have a trigger which is supposed to test whether an individual punching a

  • 0

I have a trigger which is supposed to test whether an individual punching a time clock has punched their card within the last 5 minutes. If they have not their info should be left to go on to the table clk_data, otherwise a record should be made in the log table utl_logbook and the insert to clk_data should be aborted.

When I run a good punch the insert works as advertised. When it is a bad punch (within 5 minutes of the last punch) I get the following error:

SQL Error: ORA-20101: Too Soon
ORA-06512: at "TRUTRACK.INSERT_CLK_DATA", line 14
ORA-04088: error during execution of trigger 'TRUTRACK.INSERT_CLK_DATA'

The transaction is stopped but I get no recording of it in utl_logbook.

The trigger code:
create or replace
TRIGGER "INSERT_CLK_DATA" 
BEFORE INSERT ON clk_data 
FOR EACH row 

BEGIN
  DECLARE qty INTEGER := 0;
  BEGIN
    SELECT COUNT(*)
    INTO qty
    FROM clk_data
    WHERE clk_time BETWEEN (:new.clk_time - 5/(24*60)) AND (:new.clk_time + 5/(24*60))
    AND :new.payroll = clk_data.payroll;

    IF qty > 0 THEN

      INSERT INTO utl_logbook (time, source, message) VALUES (sysdate, 'INSERT_CLK_DATA', 'Clock punch within restricted window. Payroll ID:' || :new.payroll || ' Time: ' || :new.clk_time || ' Type: ' || :new.type);

      RAISE_APPLICATION_ERROR(-20101, 'Too Soon');

    END IF;

  END;
END;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:40:25+00:00Added an answer on June 12, 2026 at 4:40 pm

    This is can be one of those rare cases when you can employ pragma autonomous_transaction. It will allow you commit without affecting your main transaction. Use it with caution. Find out more about autonomous transactions and autonomous_transaction pragma

    Here is an example:

       -- our error logging table 
    
       create table tb_log(
          msg varchar2(123)
        )
        /
    
       -- our working table
       create table tb_table(
         col11 number
        )
        /
    
    -- procedure that is going to log errors
    
    
    NK@XE> create or replace procedure log_error(p_msg in varchar2)
      2    is
      3      pragma autonomous_transaction;
      4    begin
      5      insert into tb_log(msg)
      6        values(p_msg);
      7      commit;
      8    end;
    NK@XE> /
    
    Procedure created.
    
    NK@XE> create or replace trigger tr_tb_table
      2    before insert on tb_table
      3    for each row
      4    begin
      5      if mod(:new.col1, 2) != 0
      6      then
      7         log_error('Error!');
      8         raise_application_error(-20000, 'Error has ocurred!');
      9      end if;
     10    end;
     11  /
    
    Trigger created.
    
    NK@XE> select * from tb_log;
    
    no rows selected
    
    NK@XE> select * from tb_table;
    
    no rows selected
    
    NK@XE> insert into tb_table(col1) values(1);
    
    insert into tb_table(col1) values(1)
                *
    ERROR at line 1:
    ORA-20000: Error has ocurred!
    ORA-06512: at "NK.TR_TB_TABLE", line 5
    ORA-04088: error during execution of trigger 'NK.TR_TB_TABLE'
    
    
    NK@XE> select * from tb_log;
    
    MSG
    --------------------------------------------------------------------------------
    Error!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have within my Sql Server 2008 database a trigger which will run on
I have this trigger which works functionally (as far as I can tell by
I have a stored procedure which is called inside a trigger on Insert/Update/Delete. The
I have a situation which has to be simple to solve, I would guess.
I have to create the trigger(s) which will keep the audit of my table.
In have an Oracle (10i) PL/SQL Row-Level trigger which is responsible for three independent
I have the following Style for a Button which is supposed to grow to
I have the following code which supposed to display a TreeView (the original code
I have a view which has an imageview at the bottom but when I
I have the below SQL Trigger on a SQL 2005 box that is supposed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.