0% found this document useful (0 votes)
23 views1 page

SQL Practica 9

The document creates a table, trigger, inserts sample data, and shows an error being raised by the trigger when a salary exceeds a limit. The trigger is created to raise an error if the salary is updated to more than 10000. Sample data is inserted successfully and unsuccessfully due to the trigger.

Uploaded by

Daniel Juarez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views1 page

SQL Practica 9

The document creates a table, trigger, inserts sample data, and shows an error being raised by the trigger when a salary exceeds a limit. The trigger is created to raise an error if the salary is updated to more than 10000. Sample data is inserted successfully and unsuccessfully due to the trigger.

Uploaded by

Daniel Juarez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

SQL> connect

Enter user-name: hr
Connected.
SQL> create table empleados
2 as
3 select employee_id numemp,
4 first_name nombre,
5 last_name apellido,
6 salary salario,
7 hire_date f_contra,
8 job_id puesto
9 from employees where 1=2;

Table created.

SQL> create or replace trigger emp_biu


2 before insert or update
3 of salario
4 on empleados
5
6 for each row
7 declare
8 m_error varchar2(1000);
9 begin
10 if :new.salario > 10000 then
11 m_error := :old.nombre||' no puede ganar esta cantidad';
12 raise_application_error(-2099,m_error);
13 end if;
14 end;
15 /

Trigger created.

SQL> insert into empleados values(1,'Jesus','Lopez',10000,sysdate,'MGR_ASST');

1 row created.

SQL> insert into empleados values(2,'Jesus','Gracia',12000,sysdate,'MGR_DIR');


insert into empleados values(2,'Jesus','Gracia',12000,sysdate,'MGR_DIR')
*
ERROR at line 1:
ORA-21000: error number argument to raise_application_error of -2099 is out of
range
ORA-06512: at "HR.EMP_BIU", line 6
ORA-04088: error during execution of trigger 'HR.EMP_BIU'

SQL> select * from empleados;

NUMEMP NOMBRE APELLIDO SALARIO F_CONTRA


---------- -------------------- ------------------------- ---------- --------
PUESTO
----------
1 Jesus Lopez 10000 24/05/21
MGR_ASST

SQL> spool off

You might also like