set serveroutput on

select * from dept;

insert into dept values(60,'semmit','sehol');

delete from dept where deptno=60;



CREATE or replace TRIGGER  NESZE
AFTER  INSERT  OR  UPDATE  OR  DELETE  ON  dept
BEGIN
  DBMS_OUTPUT.PUT_LINE(CASE
                        WHEN  INSERTING  THEN 'Beszúrtunk'
                        WHEN  UPDATING  THEN 'Módosítottunk'
                        WHEN  DELETING  THEN 'Töröltünk'
                      END);
END;
/
CREATE  TRIGGER  minimálbér
AFTER UPDATE OF sal ON emp
REFERENCING OLD AS régi NEW AS új
FOR  EACH  ROW
WHEN (régi.sal>új.sal AND új.sal<500)
begin
  UPDATE emp SET sal= :régi.sal WHERE  empno= :régi.empno;
End;
/

set serveroutput on
DECLARE
  a INTEGER := 2**2*3**2;
  b INTEGER := (2**(2*3))**2;
  c INTEGER := 2**((2*3)**2);
-- d INTEGER := 2**2**3**2;
BEGIN
  DBMS_OUTPUT.PUT_LINE('a = ' || TO_CHAR(a));   -- 36
  DBMS_OUTPUT.PUT_LINE('b = ' || TO_CHAR(b));   -- 36
  DBMS_OUTPUT.PUT_LINE('c = ' || TO_CHAR(c));   -- 36
--  DBMS_OUTPUT.PUT_LINE('d = ' || TO_CHAR(d));   -- 36
END;
/
commit;
drop table tmp;


CREATE TABLE tmp (
szam NUMBER(20)
);
select * from tmp;
set serveroutput on

insert into tmp values(5);
select * from tmp;



CREATE OR REPLACE TRIGGER kiírás
BEFORE INSERT
ON tmp
BEGIN
DBMS_OUTPUT.PUT_LINE('Új sort fogunk beszúrni');
END;


/
insert into tmp values(5);
/
select * from xtmp;

delete xtmp where szam=5;
CREATE OR REPLACE TRIGGER kiírás2
AFTER INSERT
ON tmp
BEGIN
DBMS_OUTPUT.PUT_LINE('Új sort szúrtunk be');
END;
/
select * from tmp;
insert into tmp values(10);

insert into tmp select sal from emp;
/

CREATE OR REPLACE TRIGGER kiírás2
AFTER INSERT
ON tmp
for each row
BEGIN
DBMS_OUTPUT.PUT_LINE('Új sorokat szúrtunk be');
END;
/
select * from tmp;
insert into tmp values(10);

insert into tmp select sal from emp;


delete tmp ;
/
CREATE OR REPLACE TRIGGER xkiírás3
AFTER delete
ON tmp
BEGIN
DBMS_OUTPUT.PUT_LINE('töröltünk');
END;
/

delete tmp ;
/
insert into tmp select sal from emp;
select * from tmp;
/

CREATE OR REPLACE TRIGGER nem_csokken
AFTER UPDATE OF ber
ON munkatars
FOR EACH ROW
WHEN (OLD.ber > NEW.ber)
UPDATE munkatars SET ber = :OLD.ber
WHERE partner_id = :NEW.partner_id;
/

UPDATE munkatars SET ber = 1 WHERE partner_id = 1;
/
drop table tmp2;
CREATE TABLE tmp2 (
szam NUMBER(20)
);

CREATE  or replace TRIGGER  xNESZE
AFTER  INSERT  OR  UPDATE  OR  DELETE
ON  tmp2
BEGIN
  DBMS_OUTPUT.PUT_LINE(CASE
 		WHEN  INSERTING  THEN 'Beszúrtunk'
		WHEN  UPDATING  THEN 'Módosítottunk'
		WHEN  DELETING  THEN 'Töröltünk'
    END);
END;
/
set serveroutput on
insert into tmp2 values(1);
update tmp2 set szam=3;
delete tmp2;
/
drop trigger valami;
CREATE or replace TRIGGER  valami
AFTER  INSERT  OR  UPDATE  OR  DELETE  ON  dept
BEGIN
  DBMS_OUTPUT.PUT_LINE(CASE
 		WHEN  INSERTING  THEN 'Beszúrtunk'
		WHEN  UPDATING  THEN 'Módosítottunk'
		WHEN  DELETING  THEN 'Töröltünk'
    END);
END;


