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 9120185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:34:16+00:00 2026-06-17T05:34:16+00:00

I have posted this question before. But now my project manager came back and

  • 0

I have posted this question before. But now my project manager came back and gave me a new set of instructions. Again, I am a bit lost now and tried to fix it to some extend.

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    |  employee_id |
-------------------------------------------
| 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 |  user_id |
-------------------------------------------
|  1          |    40          |  1234567 |
|  1          |    50          |  1234567 |
|  2          |    40          |  1213    |
|  3          |    20          |  1314    |
-------------------------------------------

Here is my trigger:

CREATE OR REPLACE TRIGGER "INOUT"."ABSENCE_TRIGGER" 
   AFTER INSERT ON arc_hrcs.absences_data 
   FOR EACH ROW
DECLARE
BEGIN
  CASE
      WHEN UPDATING THEN
           MERGE INTO out o USING DUAL ON (out.user_id =:NEW.user_id)
           WHEN MATCHED THEN UPDATE SET
                      out.employee_id = (SELECT employee_id FROM employment_table WHERE user_id = :NEW.user_id),   
                      out.absence_reason = :NEW.absence_reason,
                      out.user_id = :NEW.user_id
           WHEN NOT MATCHED THEN 


     insert into out (absence_reason, employee_id)
select :NEW.absence_reason, e.employee_id
  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';
  END CASE;
END absence_trigger;

I can’t figure out how to change the code after WHEN NOT MATCHED THEN code according to the merging syntax. A bit of guide would help me out 🙂

Thanks in advance.

  • 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-17T05:34:17+00:00Added an answer on June 17, 2026 at 5:34 am

    My previous answer was a bit too quickly.

    I would rewrite the merge as:

    MERGE INTO out o USING (select e.employee_id, :NEW.user_id as user_id
                            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') S
    ON (out.user_id =S.user_id)
    WHEN MATCHED THEN UPDATE SET
         out.employee_id = s.employee_id,   
         out.absence_reason = :NEW.absence_reason,
         out.user_id = :NEW.user_id
    WHEN NOT MATCHED THEN 
         insert (absence_reason, employee_id)
         values (:NEW.absence_reason, S.employee_id);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off I apologize... I have posted this question before, but I did a
I little while back I posted this question . I have updated that question
I have already posted a question about this, but the situation has changed sufficiently
I posted a thread about this earlier and have made some progress but now
I've actually posted this question before, but it hasn't been answered. Maybe I wasn't
I have already posted another question about this, but no one seemed to know
(I've posted a similar question before but now it is more targeted..) I am
I know a similar question has been posted before but I think this is
I know that this question has been posted before but I'm still not able
I posted a similar question earlier, but I now realize I should have been

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.