P. 1


|Views: 2|Likes:
Published by Baruch Doñez

More info:

Published by: Baruch Doñez on Oct 28, 2011
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as TXT, PDF, TXT or read online from Scribd
See more
See less





Rem Rem $Header: hr_code.sql 29-aug-2002.11:44:01 hyeh Exp $ Rem Rem hr_code.

sql Rem Rem Copyright (c) 2001, 2002, Oracle Corporation. All rights reserved. Rem Rem NAME Rem hr_code.sql - Create procedural objects for HR schema Rem Rem DESCRIPTION Rem Create a statement level trigger on EMPLOYEES Rem to allow DML during business hours. Rem Create a row level trigger on the EMPLOYEES table, Rem after UPDATES on the department_id or job_id columns. Rem Create a stored procedure to insert a row into the Rem JOB_HISTORY table. Have the above row level trigger Rem row level trigger call this stored procedure. Rem Rem NOTES Rem Rem CREATED by Nancy Greenberg - 06/01/00 Rem Rem MODIFIED (MM/DD/YY) Rem hyeh 08/29/02 - hyeh_mv_comschema_to_rdbms Rem ahunold 05/11/01 - disable Rem ahunold 03/03/01 - HR simplification, REGIONS table Rem ahunold 02/20/01 - Created Rem SET SET SET SET SET SET SET FEEDBACK 1 NUMWIDTH 10 LINESIZE 80 TRIMSPOOL ON TAB OFF PAGESIZE 100 ECHO OFF

REM ************************************************************************** REM procedure and statement trigger to allow dmls during business hours: CREATE OR REPLACE PROCEDURE secure_dml IS BEGIN IF TO_CHAR (SYSDATE, 'HH24:MI') NOT BETWEEN '08:00' AND '18:00' OR TO_CHAR (SYSDATE, 'DY') IN ('SAT', 'SUN') THEN RAISE_APPLICATION_ERROR (-20205, 'You may only make changes during normal office hours'); END IF; END secure_dml; / CREATE OR REPLACE TRIGGER secure_employees BEFORE INSERT OR UPDATE OR DELETE ON employees BEGIN secure_dml; END secure_employees; / ALTER TRIGGER secure_employees DISABLE;

p_end_date. job_id.job_id%type . p_start_date. sysdate. :old. department_id) VALUES(p_emp_id.REM REM REM REM ************************************************************************** procedure to add a row to the JOB_HISTORY table and row trigger to call the procedure when data is updated in the job_id or department_id columns in the EMPLOYEES table: CREATE OR REPLACE PROCEDURE add_job_history ( p_emp_id job_history. department_id ON employees FOR EACH ROW BEGIN add_job_history(:old. end_date. p_department_id). p_department_id job_history. END add_job_history. / COMMIT. .employee_id%type . p_job_id job_history. :old. p_job_id. :old.start_date%type . p_end_date job_history.department_id).end_date%type .employee_id. p_start_date job_history. start_date. / CREATE OR REPLACE TRIGGER update_job_history AFTER UPDATE OF job_id.job_id.hire_date. END.department_id%type ) IS BEGIN INSERT INTO job_history (employee_id.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->