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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:20:12+00:00 2026-05-12T14:20:12+00:00

I’d like to automatically update a database column with an aggregate of another column.

  • 0

I’d like to automatically update a database column with an aggregate of another column.
There are three tables involved:

T_RIDER
  RIDER_ID
  TMP_PONYLIST
  ...

T_RIDER_PONY
  RIDER_ID
  PONY_ID

T_PONY
  PONY_ID
  PONY_NAME
  ...

T_RIDER and T_PONY have an n:m relationship via T_RIDER_PONY.
T_RIDER and T_PONY have some more columns but only TMP_PONYLIST and PONY_NAME are relevant here.

TMP_PONYLIST is a semicolon spararated list of PONY_NAMES, imagine something like "Twisty Tail;Candy Cane;Lucky Leaf".
I’d like to keep this field up to date no matter what happens to T_RIDER_PONY or T_PONY.

My first idea was to have triggers on T_RIDER_PONY and T_PONY.
The problem is that it seems to be impossible to read T_RIDER_PONY within the trigger, I always get ORA-04091. I found some hints about working with three triggers and package variables, but this sounds way too complicated.

Maybe you think I’d better change the schema or get rid of TMP_PONYLIST completely.
These are options but not the topic of this question.
For the moment I’m only interested in answers that don’t require any change to my applications (no application works with the tables directly, only views, so trickery with views is allowed).

So, how can I keep TMP_PONYLIST up to date automatically?
How to concatenate the string is an interesting subproblem I also have not yet found an elegant solution for.

I’m using Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 – 64bi.

UPDATE

I like the idea of using a materialized view.
What I have is:

CREATE MATERIALIZED VIEW
  V_TMP_PONYLIST 
BUILD IMMEDIATE
REFRESH COMPLETE ON COMMIT
AS SELECT 
  R.RIDER_ID, string_agg(P.PONY_NAME) AS TMP_PONYLIST
FROM
  T_PONY P, T_RIDER R, T_RIDER_PONY RP
WHERE 
  P.PLOTGROUP_ID=RP.PLOTGROUP_ID AND
  R.QUEUE_ID=RP.QUEUE_ID 
GROUP BY R.RIDER_ID;

string_agg is not shown because it is long and the I think it is not relevant.

It won’t compile with ON COMMIT, I get ORA-12054.
As I understand the documentation aggregates are only forbidden with
REFRESH FAST, so what’s the problem here?

UPDATE
Vincents and Tonys answers were different but both helpful.
I accepted Tonys but be sure to read Vincents answer also.

  • 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-05-12T14:20:12+00:00Added an answer on May 12, 2026 at 2:20 pm

    Why do you need to read the T_RIDER_PONY table in the trigger? You will have either inserted or deleted a row, so all the trigger needs to do is look up the pony name in T_PONY and update table T_RIDER, either appending the name to or removing it from TMP_PONYLIST like this

    create trigger t_rider_pony_trg 
    after insert or delete on t_rider_pony
    for each row
    begin
       if inserting then
          select pony_name
          into   l_pony_name
          where  pony_id = :new.pony_id;
    
          update t_rider
          set    tmp_ponylist = tmp_ponylist || ';' || l_pony_name
          where  rider_id = :new.rider_id;
       elsif deleting then
          select pony_name
          into   l_pony_name
          where  pony_id = :old.pony_id;
    
          update t_rider
          set    tmp_ponylist = ltrim ( 
                                   rtrim ( 
                                      replace(';' || tmp_ponylist || ';',
                                              ';' || l_pony_name || ';',
                                              ';'),
                                      ';', ';')
          where  rider_id = :old.rider_id;
       end if;
    end;
    

    That update in the delete section is rather unpleasant I admit; it might be preferable to use utilities like apex_util.string_to_table and apex_util.table_to_string to deal with it! See this SO answer for details.

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

Sidebar

Ask A Question

Stats

  • Questions 316k
  • Answers 316k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The proper way to do this is to give the… May 13, 2026 at 11:36 pm
  • Editorial Team
    Editorial Team added an answer If the only point of the loop is to collect… May 13, 2026 at 11:36 pm
  • Editorial Team
    Editorial Team added an answer I agree with you in general: Classes are much cleaner… May 13, 2026 at 11:36 pm

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.