DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: help with pl/sql

  1. #1
    Join Date
    Feb 2000
    Location
    New York,U.S.A.
    Posts
    245
    Hi, all
    I have a situation here, I have a table called messagearchive,which grows too big too fast,
    SQL> desc messagearchive;
    Name Null? Type
    ----------------------------------------- -------- ----------------------------
    MSGID NOT NULL CHAR(16)
    SERVICEID NOT NULL CHAR(16)
    MSGTEXT VARCHAR2(4000)
    MSGDATE NOT NULL DATE

    based on our business requirements, we only need to keep two(latest) msgtexts for each serviceid. I can do it in a very clumsy way, which is that I do a
    select unique(serviceid),max(msgdate) from messagearchive group by serviceid; and put it into a temp table, and get results by joining messagearchive and temp and put it into temp_messagearchive table and then truncate table messagearchive and put back the data from temp_messagearchive to messagearchive.
    I know there must be a better way to do it, but I just can not come up with it. I would appreciate if anyone can help me out with PL/SQL packages to do the same job. Thanks for help.

    Dragon

  2. #2
    Join Date
    Jan 2001
    Posts
    515

    Try a trigger

    Try a before insert trigger. Check if there are two message text in there already. If there is don't insert.

  3. #3
    Join Date
    Oct 2000
    Posts
    123

    Re: Try a trigger

    [QUOTE][i]Originally posted by lesstjm [/i]
    [B]Try a before insert trigger. Check if there are two message text in there already. If there is don't insert. [/B][/QUOTE]
    ---------------------------------------------------------------------
    In the Before Insert Triger:

    IF NoOfMessage >= 2 THEN
    delete ones which has not the latest date on it;
    insert into the new message;
    ELSE
    insert into the new message;
    END IF;

  4. #4
    Join Date
    Feb 2000
    Location
    New York,U.S.A.
    Posts
    245
    Thanks for the advice. But do you think it would be too expensive to place a trigger on it on the performance side? because there are at least of 100,000 messages were inserted into that table. I have no idea which one is more efficient, put on trigger on it, or insert a delete later( with 100,000 records inserted every day).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width