January 13, 2008 at 12:12 pm
Hello all!
Example trigger:
CREATE OR REPLACE TRIGGER dodaj_prispevek_trigger BEFORE INSERT ON PRISPEVKI
FOR EACH ROW
DECLARE
st_prispevkov NUMBER;
BEGIN
SELECT COUNT(IDPRISPEVKA)
INTO st_prispevkov
FROM PRISPEVKI
UPDATE ODBOR
SET IDCLANA = !!! HERE I NEED A RADNOM INTEGER IN INTERVAL [1, count(IDCLANA)] !!!
....
I googled but didn't find what i was lookin' for :\
Can anybody help?
Thanks!
January 13, 2008 at 2:04 pm
Nevermind.. I solved the problem..
January 13, 2008 at 8:08 pm
If we had found a solution for you, everyone would benefit because we would post the answer. To be courteous, you should too...
--Jeff Moden
Change is inevitable... Change for the better is not.
January 13, 2008 at 11:28 pm
Sorry, i thought this was to "easy"..
Anyway here is the whole trigger:
CREATE OR REPLACE TRIGGER dodaj_prispevek_trigger AFTER INSERT ON PRISPEVKI
FOR EACH ROW
DECLARE
st_prispevka NUMBER;
st_odobritve NUMBER;
max_clan NUMBER;
st_clana NUMBER;
BEGIN
-- dobimo id vstavljenega prispevka
st_prispevka := :new.IDPRISPEVKA;
-- izracunamo nov id odobritve
SELECT MAX(IDODOBRITEV)
INTO st_odobritve
FROM ODOBRITVE;
st_odobritve := st_odobritve + 1;
SELECT MAX(IDCLANA)
INTO max_clan
FROM ODBORI;
-- nakljucno izberemo clana odbora
SELECT dbms_random.value(1, max_clan) num
INTO st_clana
FROM DUAL;
-- vstavimo odobritev
INSERT INTO ODOBRITVE (IDODOBRITEV, PRIS_IDPRISPEVKA,
ODB_IDCLANA) VALUES (st_odobritve, st_prispevka, st_clana);
END;
/
Bold is what i was lookin for 😉
January 14, 2008 at 5:49 am
Heh... thanks... good to know.
And, my bad... didn't look at the first post... this is Oracle code...
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply