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 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
  • 1 View
  • 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

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in
I have some data like this: 1 2 3 4 5 9 2 6

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.