begin
INSERT INTO DEPARTMENT
VALUES(&id,'&nombre',&location);
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_line(SQLERROR);
end;
respuesta:
revisar
-----
ej 2
BEGIN
UPDATE DEPARTMENT
SET name = 'Prueba1'
WHERE department_id = &id;
end;
el motor no genera error si ese comando no afecta gfilas, si el comando viola una
constrain, si, salta error
sino viola ninguna fila, NO salta
si pongo id = 88
no salta un error, no hace nada.
ejemplo 3
Antiguo:BEGIN
UPDATE DEPARTMENT
SET location_id = 701
WHERE department_id = &id;
end;
Nuevo:BEGIN
UPDATE DEPARTMENT
SET location_id = 701
WHERE department_id = 10;
end;
ver lo de sqlerrs ?
ej 5
tanto el update como el delete no nos avisa cuando afectan filas
¡hay alguna manera par amostrar si ese update o delete fue exitoso?,
si
con cursores
cursores es una estructura de memoria
BEGIN
delete from DEPARTMENT
WHERE department_id = &id;
if sql%notfound then
dbms_output.put_line('el id no existe');
else
dbms_output.put_line(sql%rowcount);
end if;
EXCEPTION
WHEN others then
dbms_output.put_line('Sqlerrs');
end;
ejemplo C4001
BEGIN
UPDATE EMPLOYEE
set SALARY = SALARY * 1.10
WHERE DEPARTMENT_ID = &iddep AND
job_id = (select job_id from JOB
where FUNCTION = '&fun');
if sql%notfound then
dbms_output.put_line('el id no existe');
else
dbms_output.put_line(sql%rowcount);
end if;
EXCEPTION
WHEN others then
dbms_output.put_line('Sqlerrs');
end;
-VER PORQUE NO FUNCIONA SUSI ESTA IGUAL AL DE LAPROFE... faltaba el '& no es %!!
puse % en vez de '&
------------
EJ 7
Antiguo:declare
f_id number;
BEGIN
select job_id into f_id
from job
where function = '&fun';
UPDATE EMPLOYEE
set SALARY = SALARY * 1.10
WHERE DEPARTMENT_ID = &iddep AND
job_id = f_id;
if sql%notfound then
dbms_output.put_line('el id no existe');
else
dbms_output.put_line(sql%rowcount);
end if;
EXCEPTION
WHEN others then
dbms_output.put_line('Sqlerrs');
end;
Nuevo:declare
f_id number;
BEGIN
select job_id into f_id
from job
where function = 'CLERK';
UPDATE EMPLOYEE
set SALARY = SALARY * 1.10
WHERE DEPARTMENT_ID = 20 AND
job_id = f_id;
if sql%notfound then
dbms_output.put_line('el id no existe');
else
dbms_output.put_line(sql%rowcount);
end if;
EXCEPTION
WHEN others then
dbms_output.put_line('Sqlerrs');
end;
2
---------------------
bloqure que permita insertar un cliente pero entren nada mas los datos exijen la
tabla,
los primordiales
hacer manejo de excepciones para ver si ese insert ingreso o no ingresoç
los atributos de cursores
no tiene sentido en caso de insert o de select.
si insert cancela, es por un error de constrain,, si pasa , sabemos que esta ok.
lo mismo con select.
ej8
en este caso la primary key no se crea sola.
BEGIN
INSERT INTO CUSTOMER
VALUES(&customer_id,null,null,null,null,null,null,null,&salespersonid,null,null);
dbms_output.put_line(sql%rowcount);
EXCEPTION
WHEN others then
dbms_output.put_line('Sqlerrs');
end;
otra forma
ej9
BEGIN
INSERT INTO CUSTOMER (customer_id, salesperson_id)
VALUES(&customer_id,&salespersonid);
dbms_output.put_line(sql%rowcount);
EXCEPTION
WHEN others then
dbms_output.put_line('Sqlerrs');
end;