Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Oracle i trigeri

[es] :: Oracle :: Oracle i trigeri

Strane: 1 2

[ Pregleda: 7577 | Odgovora: 32 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

djoka_l
Beograd

Član broj: 56075
Poruke: 3453

Jabber: djoka_l


+1462 Profil

icon Re: Oracle i trigeri16.05.2009. u 11:19 - pre 182 meseci
Comii, bolje obriši taj kod, neće raditi...
 
Odgovor na temu

Serbiankum
Srbija

Član broj: 54947
Poruke: 240
*.adsl-a-1.sezampro.yu.

Sajt: www.drvoumomdvoristu.com


Profil

icon Re: Oracle i trigeri16.05.2009. u 14:13 - pre 182 meseci
Sa ovim kodom postoji greska DISTRIBUTER"."SIFRADISTRIBUTERA": invalid identifier
Code:

CREATE OR REPLACE TRIGGER "triger1" 
AFTER INSERT or update OF sifradistributera ON otprzagorivo
FOR EACH ROW
BEGIN

IF INSERTING THEN

UPDATE OTPRZAGORIVO c set
c.nazivdistributera=DISTRIBUTER.nazivdistributera
where DISTRIBUTER.sifradistributera = :new.sifradistributera;
 END IF;
END;



Sa drugim kodom postoji greska Encountered the symbol "end-of-file" when expecting one of the following: begin case declare end exception exit for goto if loop mod null pragma raise return select update while with


Code:

CREATE OR REPLACE TRIGGER "triger2" 
AFTER INSERT or update OF sifradistributera ON otprzagorivo
FOR EACH ROW
BEGIN
  
begin
   select nazivdistributera
   into :new.nazivdistributera
   from distributer d
   where d.sifradistributera = :new.sifradistributera;
end;


[Ovu poruku je menjao Serbiankum dana 16.05.2009. u 15:40 GMT+1]
 
Odgovor na temu

djoka_l
Beograd

Član broj: 56075
Poruke: 3453

Jabber: djoka_l


+1462 Profil

icon Re: Oracle i trigeri16.05.2009. u 21:36 - pre 182 meseci
Izvini, a šta će ti dva BEGIN. Ja sam tebi dao kompletan kod koji treba da zameni ceo tvoj begin .. end block, a ti si ostavio višak begina.
 
Odgovor na temu

Serbiankum
Srbija

Član broj: 54947
Poruke: 240
*.adsl-a-1.sezampro.yu.

Sajt: www.drvoumomdvoristu.com


Profil

icon Re: Oracle i trigeri16.05.2009. u 23:28 - pre 181 meseci
Triger radi jedino ako napisem before, ako je after onda ne radi i javlja gresku ORA-04084: cannot change NEW values for this trigger type.

Jer zamisao je bila da cim se unese sifra distributera da se odmah upise naziv distributera u polje "naziv distriutera". To sada togadja ali tek kada napravim novu stavku odnosno kada je stavka commit.

Da li nekako triger moze da bude AFTER INSERT or update umesto BEFORE?
 
Odgovor na temu

jaksic24

Član broj: 42831
Poruke: 1
195.252.78.*



Profil

icon Re: Oracle i trigeri17.05.2009. u 04:21 - pre 181 meseci
Probaj ovako:

create or replace TRIGGER OTPRZAGORIVO_AFT_U_ROW
After update of nazivdistributera on DISTRIBUTER
For each row
begin
UPDATE OTPRZAGORIVO c set
c.nazivdistributera = :new.nazivdistributera
where c.sifradistributera = :old.sifradistributera;
end;


 
Odgovor na temu

Serbiankum
Srbija

Član broj: 54947
Poruke: 240
*.adsl-a-1.sezampro.yu.

Sajt: www.drvoumomdvoristu.com


Profil

icon Re: Oracle i trigeri17.05.2009. u 10:10 - pre 181 meseci
zasto triger jedino radi sa before insert or update a ne radi kad se napise after insert or update. Jer cilj je bio da tek kada se upise sifradistributera odmah pojavi i naziv distributera, a ne da se naziv pojavi kada predjem u novi red ili novu stavku. Mislim odgovara i ovako ali me zanima da li taj naziv moze da se pojavi odmah posle upisivanja sifre distributera.

Pitanje vazano za ovaj deo koda:

begin
select nazivdistributera
into :new.nazivdistributera
from distributer d
where d.sifradistributera = :new.sifradistributera;
end;


1. select nazivdistributera, da li se misli na nazivdistributera u tabeli otprzagorivo?
2. into :new.nazivdistributera, sta ovo tacno znaci? Da li ovo znaci da ubacuje novu vrednost distributera u tabelu otprzagorivo?



[Ovu poruku je menjao Serbiankum dana 17.05.2009. u 11:20 GMT+1]

[Ovu poruku je menjao Serbiankum dana 17.05.2009. u 11:22 GMT+1]
 
Odgovor na temu

djoka_l
Beograd

Član broj: 56075
Poruke: 3453

Jabber: djoka_l


+1462 Profil

icon Re: Oracle i trigeri17.05.2009. u 10:36 - pre 181 meseci
Prvo, tačno je da triger treba da bude before, nisam obratio pažnju na deklaraciju treigera.

Drugo, triger radi tačno ono što treba da radi, ali to nije ono što si ti zamislio da on radi. Pretpostavljam da ti želiš da se naziv distributera pojavi na ekranu u aplikaciji. To onda ne može trigerom u bazi, mora se napisati u aplikaciji, s tim da ja pojma nemam šta koristiš da napraviš aplikaciju, APEX, FORMS ili nešto drugo.

I, zaboga, batali Oracle ako ne znaš da napišeš najobičniji SELECT. Kakvo je to pitanje? Zar ne znaš za šta ti služi FROM deo SELECT naredbe.
Da li razumeš za šta služi kod:

select nazivdistributera
from distributer d
 
Odgovor na temu

Serbiankum
Srbija

Član broj: 54947
Poruke: 240
*.adsl-a-1.sezampro.yu.

Sajt: www.drvoumomdvoristu.com


Profil

icon Re: Oracle i trigeri17.05.2009. u 10:52 - pre 181 meseci
Zasto triger treba da bude before?Ja sam mislio da moze after da cim se upise sifradistributera (a to je posle odnosno after) da se u polje nazivdistributera odmah upise naziv. Ako to ne moze u bazi onda ok.Ponavljam triger otprilike radi to sto sam i hteo jer na kraju ipak ispisuje naziv distributera kada se unese sifra distributera. Znam da to moze u aplikaciji ali sam mislio da mozda moze i u bazi. Inace koristim toad za testiranje.

Drugo, znam da koristim select i from naredbe, nego me je zbunio redosled. Jer prvo je isao select pa into pa from.
 
Odgovor na temu

djoka_l
Beograd

Član broj: 56075
Poruke: 3453

Jabber: djoka_l


+1462 Profil

icon Re: Oracle i trigeri17.05.2009. u 11:17 - pre 181 meseci
Assigning Values to a Variable With the PL/SQL SELECT INTO Statement

Another way to assign values to a variable is by selecting (or fetching) database values into it. With the PL/SQL SELECT INTO statement, you can retrieve data from one row in a table. In Example 4-13, 10 percent of the salary of an employee is selected into the bonus variable. Now, you can use the bonus variable in another computation, or insert its value into a database table.

In the example, the DBMS_OUTPUT.PUT_LINE procedure is used to display output from the PL/SQL program. For more information, see "Inputting and Outputting Data with PL/SQL".

Example 4-13 Assigning Values to Variables Using PL/SQL SELECT INTO

DECLARE -- declare and assign values
bonus_rate CONSTANT NUMBER(2,3) := 0.05;
bonus NUMBER(8,2);
emp_id NUMBER(6) := 120; -- assign a test value for employee ID
BEGIN
-- retreive a salary from the employees table, then calculate the bonus and
-- assign the value to the bonus variable
SELECT salary * bonus_rate INTO bonus FROM employees
WHERE employee_id = emp_id;
-- display the employee_id, bonus amount, and bonus rate
DBMS_OUTPUT.PUT_LINE ( 'Employee: ' || TO_CHAR(emp_id)
|| ' Bonus: ' || TO_CHAR(bonus) || ' Bonus Rate: ' || TO_CHAR(bonus_rate));
END;
/

Pročitaj dokument koji sam ti stavio u linku: http://www.oracle.com/pls/xe102/homepage
najbolje da kreneš od "2 Day Developer Guide"
 
Odgovor na temu

Serbiankum
Srbija

Član broj: 54947
Poruke: 240
*.adsl-3.sezampro.yu.

Sajt: www.drvoumomdvoristu.com


Profil

icon Re: Oracle i trigeri20.05.2009. u 17:35 - pre 181 meseci
jos jedno pitanje za trigere. U tabeli stavke otpremnice za gorivo postoje polja naruceno i istoceno goriva. Zamisao je da ako je naruceno 5t goriva a ako se u polje istoceno upise vrednost koja je veca od istoceno (u ovom slucaju 5) da se pokrene triger koji ce ispisati u polje istoceno vrednost naruceno.

Probao sam da resim ovaj problem sa if then ali opet se pojavljuje problem mutating.

Code:

CREATE OR REPLACE TRIGGER "istoceno" 
before insert or update of istoceno on stavkeotprzagorivo
For each row

begin 

if :new.istoceno > :old.naruceno then
insert into stavkeotprzagorivo (istoceno) values (:old.naruceno);
  
end if;
end;



Da li moze da se resi problem sa if then ?
 
Odgovor na temu

djoka_l
Beograd

Član broj: 56075
Poruke: 3453

Jabber: djoka_l


+1462 Profil

icon Re: Oracle i trigeri20.05.2009. u 18:27 - pre 181 meseci
Još uvek ne razumeš trigere...

:old NE MOŽEŠ da koristiš u ON INSERT trigeru - nije definisano, ne postoji

Kako možeš u triger ON INSERT OR UPDATE nad tabelom stavkeotprzagorivo da radiš insert/update u tu istu tabelu!!! Poznat ti je pojam beskonačne petlje?

Šta ovo znači:
insert into stavkeotprzagorivo (istoceno) values (:old.naruceno);
PROMENIO BI SVE SLOGOVE U TABELI AKO TI SE U JEDNOM SLOGU POJAVI NELOGIČNOST!!! (pod uslovom da ovo može da se izvrši)

izmena: moja greška, mislio sam da je update, vali sve jedno ne valja, pukao bi insert...

Evo koda, nemam Oracle na ovom računaru sa kojeg pišem da bih isprobao...
Code:

CREATE OR REPLACE TRIGGER "istoceno" 
before insert or update of istoceno on stavkeotprzagorivo
For each row

begin 

if :new.istoceno > :new.naruceno then
   :new.istoceno := :new.naruceno;
  
end if;
end;

 
Odgovor na temu

djoka_l
Beograd

Član broj: 56075
Poruke: 3453

Jabber: djoka_l


+1462 Profil

icon Re: Oracle i trigeri20.05.2009. u 18:40 - pre 181 meseci
Accessing Column Values in Row Triggers

Within a trigger body of a row trigger, the PL/SQL code and SQL statements have access to the old and new column values of the current row affected by the triggering statement. Two correlation names exist for every column of the table being modified. There is one for the old column value and one for the new column value. These columns in the table are identified by :OLD.colum_name and :NEW.column_name. The use of :NEW and :OLD is shown in Example 6-1 and Example 6-2.

Depending on the type of triggering statement, certain correlation names might not have any meaning:

*

A trigger fired by an INSERT statement has meaningful access to new column values only. Because the row is being created by the INSERT operation, the old values are null.
*

A trigger fired by an UPDATE statement has access to both old and new column values for both BEFORE and AFTER row triggers.
*

A trigger fired by a DELETE statement has meaningful access to old (:OLD) column values only. Because the row no longer exists after the row is deleted, the new (:NEW) values are NULL and cannot be modified.

Old and new values are available in both BEFORE and AFTER row triggers. A new column value can be assigned in a BEFORE row trigger, but not in an AFTER row trigger (because the triggering statement takes effect before an AFTER row trigger is fired). If a BEFORE row trigger changes the value of NEW.column, then an AFTER row trigger fired by the same statement sees the change assigned by the BEFORE row trigger.

Correlation names can also be used in the Boolean expression of a WHEN clause. A colon (:) must precede the OLD and NEW qualifiers when they are used in a trigger body, but a colon is not allowed when using the qualifiers in the WHEN clause.


Do not create recursive triggers. For example, creating an AFTER UPDATE statement trigger on the employees table that will then issue an UPDATE statement on the same employees table, will cause the trigger to fire recursively until it has run out of memory.


 
Odgovor na temu

Serbiankum
Srbija

Član broj: 54947
Poruke: 240
*.adsl-3.sezampro.yu.

Sajt: www.drvoumomdvoristu.com


Profil

icon Re: Oracle i trigeri23.05.2009. u 23:17 - pre 181 meseci
Da li u After trigeru ne moze da se koristi :new vrednost ?

Pokusao sam da od poslednjeg trigera napravim proceduru. Kod sam kompajlirao bez greske ali on ne radi. Gde bi bila greska?
Da li je jedini nacin testiranja procedure: BEGIN ime_procedure(vrednost); END; ili moze procedura nekako i drugacije da se testira bez pisanja koda?


Code:

CREATE OR REPLACE procedure naruceno

(istoceno out varchar2, naruceno in varchar2)

as
begin 

if istoceno > naruceno then
   istoceno := naruceno;
  
end if;
end;

 
Odgovor na temu

[es] :: Oracle :: Oracle i trigeri

Strane: 1 2

[ Pregleda: 7577 | Odgovora: 32 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.