Beruflich Dokumente
Kultur Dokumente
LOOP
IF credit_rating < 3 THEN ...
EXIT; -- exit loop immediately END IF;
END LOOP;
IF else
IF-THEN-ELSE
IF condition1 THEN
sequence_of_statements1
ELSE
sequence_of_statements3
END IF;
WHILE
WHILE condition LOOP sequence_of_statements
END LOOP;
average salary 4071.7525
EmployeeS
------------------------
Jason Martin makes $1234.56
Alison Mathews makes $6661.78
James Smith makes $6544.78
Celia Rice makes $2344.78
Robert Black makes $2334.78
Linda Green makes $4322.78
David Larry makes $7897.78
James Cat makes $1232.78
PL/SQL procedure successfully completed.
%rowtype
declare
2 l_dept employee%rowtype;
3 begin
4 l_dept.id := 100;
5 l_dept.first_name := 'Tech';
6 insert into employee (id, first_name )
7 values( l_dept.id, l_dept.first_name );
8 end;
9 /
PL/SQL procedure successfully completed.
VIEW
create view view_employee as
2 select id view_id, first_name view_first_name
3 from employee;
View created.
SQL>
SQL>
SQL> select * from view_employee;
VIEW VIEW_FIRST
---- ----------
01 Jason
02 Alison
03 James
04 Celia
05 Robert
06 Linda
07 David
08 James
8 rows selected.
SQL>
SQL>
SQL> drop view view_employee;
TRIGGER
select * from Employee
ID FNAME LNAME Start_DAT END_DATE SALARY
01 Jason Martin 25-JUL-96 25-JUL-06 1234.56
02 Alison Mathews 21-MAR-76 21-FEB-86 6661.78
03 James Smith 12-DEC-78 15-MAR-90 6544.78
04 Celia Rice 24-OCT-82 21-APR-99 2344.78
05 Robert Black 15-JAN-84 08-AUG-98 2334.78
06 Linda Green 30-JUL-87 04-JAN-96 4322.78
07 David Larry 31-DEC-90 12-FEB-98 7897.78
08 James Cat 17-SEP-96 15-APR-02 1232.78
SQL>
SQL>
SQL> create table employees_copy as select * from e
mployee;
SQL>
SQL> create table employees_log(
2 who varchar2(30),
3 when date );
SQL>
SQL> create trigger biud_employees_copy
2 before insert or update or delete
3 on employees_copy
4 begin
5 insert into employees_log( who, when )
6 values( user, sysdate );
7 end;
8 /
SQL>
SQL> update employees_copy set salary = salary * 1.
1;
SQL>
SQL> select * from employees_log;
WHO WHEN
------------------------------ ---------
JAVA2S 09-SEP-06
SQL>
SQL> delete from employees_copy;
SQL>
SQL> select * from employees_log;
WHO WHEN
------------------------------ ---------
JAVA2S 09-SEP-06
JAVA2S 09-SEP-06
SQL>
SQL> delete from employee;
8 rows deleted.
SQL>
SQL> select * from employee_audit;
ID SALARY DELETE_DA DELETED_BY
---- ---------- --------- ---------------
01 1234.56 09-SEP-06 JAVA2S
02 6661.78 09-SEP-06 JAVA2S
03 6544.78 09-SEP-06 JAVA2S
04 2344.78 09-SEP-06 JAVA2S
05 2334.78 09-SEP-06 JAVA2S
06 4322.78 09-SEP-06 JAVA2S
07 7897.78 09-SEP-06 JAVA2S
08 1232.78 09-SEP-06 JAVA2S
8 rows selected.
CREATE OR REPLACE TRIGGER employee_after_delete
2 AFTER DELETE
3 ON employee
4 FOR EACH ROW
5
6 DECLARE
7 v_username varchar2(10);
8
9 BEGIN
10
11 -- Find username of person performing the DELETE on the table
12 SELECT user INTO v_username
13 FROM dual;
14
15 -- Insert record into audit table
16 INSERT INTO employee_audit (id, salary, delete_date, deleted_
by)
17 VALUES ( :old.id, :old.salary, sysdate, v_username
);
18
19 END;
20 /
Trigger created.
SQL>
SQL> delete from employee;
8 rows deleted.
SQL>
SQL> select * from employee_audit;
ID SALARY DELETE_DA DELETED_BY
---- ---------- --------- ---------------
01 1234.56 09-SEP-06 JAVA2S
02 6661.78 09-SEP-06 JAVA2S
03 6544.78 09-SEP-06 JAVA2S
04 2344.78 09-SEP-06 JAVA2S
05 2334.78 09-SEP-06 JAVA2S
06 4322.78 09-SEP-06 JAVA2S
07 7897.78 09-SEP-06 JAVA2S
08 1232.78 09-SEP-06 JAVA2S
8 rows selected.