![]() |
|
|
| Subject:
How to create a trigger on Oracle for the following table and situation.
Category: Computers > Programming Asked by: virajpurang-ga List Price: $15.00 |
Posted:
27 Jun 2003 10:55 PDT
Expires: 02 Jul 2003 13:30 PDT Question ID: 222439 |
I have a table with the following schema : where builddate and machinename form a primary key. I want to create a row trigger which deletes old records , for a machcine name or every insert ...so that only 100 records remain at any point of time for each machinename. Any suggestions ? SQL> desc buildstat; Name Null? Type ----------------------------------------- -------- ---------------------------- PROJECTNAME NOT NULL VARCHAR2(100) SUCESS NOT NULL VARCHAR2(50) LASTCHANGELIST NOT NULL NUMBER(38) LABEL VARCHAR2(100) BUILDDATE NOT NULL DATE LASTBUILD DATE MACHINENAME NOT NULL VARCHAR2(50) BUILDTIME VARCHAR2(38) | |
| |
|
|
| There is no answer at this time. |
|
| Subject:
Re: How to create a trigger on Oracle for the following table and situation.
From: stephenvakil-ga on 27 Jun 2003 14:05 PDT |
I don't have an exact answer for you, but you can try something like this: FOR EACH ROW buildstat_count number(4); BEGIN select count(*) into buildstat_count from buildstat where machinename = :old.machinename; WHILE buildstate_count > 100 loop delete from buildstat_count where machine_name = :old.machinename and builddate = (select min(builddate) from buildstat where machinename = :old.machinename; select count(*) into buildstat_count from buildstat where machinename = :old.machinename; end loop; END |
| Subject:
Re: How to create a trigger on Oracle for the following table and situation.
From: virajpurang-ga on 02 Jul 2003 13:17 PDT |
Thanks a lot guys ...
But I already coded ... something like
which I call from a shell script.This shell script is added to the
system running Oracle as a cron job.
===============================================================================
DECLARE
macname buildstat.machinename%TYPE;
DATEBUILD buildstat.builddate%TYPE;
CURSOR buildstat_cur IS
SELECT UNIQUE machinename FROM buildstat ORDER BY machinename;
BEGIN
FOR buildstat_rec IN buildstat_cur LOOP
macname := buildstat_rec.machinename;
dbms_output.put_line('Machine name is '||macname);
SELECT MIN(builddate) INTO DATEBUILD FROM
( SELECT builddate FROM buildstat WHERE machinename=macname ORDER BY
builddate DESC )A
WHERE rownum < 102;
dbms_output.put_line('Date is '||DATEBUILD);
delete from buildstat where machinename=macname and builddate <
DATEBUILD;
commit;
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output.put_line('Did not fine any data '||macname);
END;
/
=============================================================================== |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
| Search Google Answers for |
| Google Home - Answers FAQ - Terms of Service - Privacy Policy |