==== create table ====
CREATE TABLE kreis
(id NUMBER,
radius NUMBER,
flaeche NUMBER)
PCTFREE 10
INITRANS 1
MAXTRANS 255
TABLESPACE users
STORAGE (
INITIAL 65536
MINEXTENTS 1
MAXEXTENTS 2147483645
)
NOCACHE
MONITORING
/
==== fill id ====
CREATE OR REPLACE TRIGGER trg_next_id
BEFORE
INSERT
ON kreis
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
begin
select hr_seq.NEXTVAL into :new.id from dual;
end;
/
==== calc radius oder flaeche ====
CREATE OR REPLACE TRIGGER trg_calc_flaeche
BEFORE
INSERT OR UPDATE
ON kreis
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
begin
if :new.flaeche is null then
:new.flaeche := :new.radius**2 * 3.141;
elsif :new.radius is null then
:new.radius := (:new.flaeche / 3.141) ** (1/2);
end if;
dbms_output.put_line('Flaeche ' || :new.flaeche);
dbms_output.put_line('Radius ' || :new.radius);
end;
/