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

  • Home
  • SEARCH
  • 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 9096141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:46:26+00:00 2026-06-16T23:46:26+00:00

I am working on a trigger which needs INSERT INTO with WHERE logic. I

  • 0

I am working on a trigger which needs INSERT INTO with WHERE logic.

I have three tables.

Absence_table:

-----------------------------
|  user_id | absence_reason |
-----------------------------
|  1234567 |   40           |
|  1234567 |   50           |
|  1213    |   40           |
|  1314    |   20           |
|  1111    |   20           |
-----------------------------

company_table:

-----------------------------
| user_id  | company_id     |
-----------------------------
| 1234567  |  10201         |
| 1213     |  10200         |
| 1314     |  10202         |
| 1111     |  10200         |
-----------------------------

employment_table:

--------------------------------------
| user_id  |   emp_type    |  emp_no |
--------------------------------------
| 1234567  |   Int         |    1    |
| 1213     |   Int         |    2    |   
| 1314     |   Int         |    3    |
| 1111     |   Ext         |    4    |
--------------------------------------

and finally I have the table out where data should be going only who have emp_type = Int in employment_table and have company_id = 10200

out:

--------------------------------
| employee_id | absence_reason |
--------------------------------
|  1          |    40          |
|  1          |    50          |
|  2          |    40          |
|  3          |    20          |
--------------------------------

Here is my trigger:

CREATE OR REPLACE TRIGGER "INOUT"."ABSENCE_TRIGGER" 
  AFTER INSERT ON absence_table 
  FOR EACH ROW
DECLARE
BEGIN
  CASE
      WHEN INSERTING THEN
           INSERT INTO out (absence_reason, employee_id)
           VALUES (:NEW.absence_reason, (SELECT employee_id FROM employment_table WHERE user_id = :NEW.user_id)
           WHERE user_id IN 
             (SELECT user_id FROM employment_table WHERE employment_type = 'INT') 
             AND user_id IN 
               (SELECT user_id FROM company_table WHERE company_id = '10200');
  END CASE;
END absence_trigger;

It is obviously not working and I can’t figure out what should I do to make it work. Any suggestions?

  • 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-16T23:46:27+00:00Added an answer on June 16, 2026 at 11:46 pm

    change the insert to this:

    insert into out (absence_reason, employee_id)
    select :NEW.absence_reason, e.emp_no
      from employment_table e 
           inner join company_table c
                   on c.user_id = e.user_id
     where e.user_id = :NEW.user_id
       and e.emp_type = 'INT'
       and c.company_id = '10200';
    

    which should work. note you had emp_no in your sample structure yet employee_id in the trigger insert too. i’ve assumed emp_no is right. also emp_type vs employment_type.

    Finally in your trigger you have company_id in quotes. Is it really a varchar2? if so OK, if not, don’t use quotes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a trigger which needs to re-insert its data on another table.
I have a trigger for insert/update/delete. That is working fine. Also, I need the
I am working on a project which needs to extract text form a predefined
I have created an onSharedPreferencesChangeListener which is working correctly. I know this because when
Hi there I have this confirmable button directive which I am working on, The
I have a php file which needs to be executed in CLI from my
I have been working on a project which is about data copy from one
I have a table with an order column which needs to maintain a contiguous
I have a client side app I'm working in which Im' using jQuery 1.7.x,
In an application I am working on, we have actions that trigger when a

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.