0% found this document useful (0 votes)
216 views4 pages

Taller 1 - PLSQL-katheryn Rojas

This document provides instructions for 3 PL/SQL exercises: 1) Create a PL/SQL block to insert a new department row into the DEPT table by prompting for the name and location. 2) Create a PL/SQL block to update the location of an existing department by prompting for the number and new location. 3) Create a PL/SQL block to delete the department added in exercise 2 by prompting for the department number.

Uploaded by

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

Taller 1 - PLSQL-katheryn Rojas

This document provides instructions for 3 PL/SQL exercises: 1) Create a PL/SQL block to insert a new department row into the DEPT table by prompting for the name and location. 2) Create a PL/SQL block to update the location of an existing department by prompting for the number and new location. 3) Create a PL/SQL block to delete the department added in exercise 2 by prompting for the department number.

Uploaded by

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

Taller 1 – PL/SQL

1. Insert a new row into the DEPT table interactively, using


PL/SQL. Prompt the name of departament and city (location).
1. EDIT PROCESO
2. VARIABLE g_max_deptno NUMBER
DECLARE
v_max_deptno NUMBER;
BEGIN
SELECT MAX(deptno)
INTO v_max_deptno
FROM dept;
:g_max_deptno:= v_max_deptno;
END;
/
PRINT g_max_deptno
/
DECLARE
v_max_deptno NUMBER;
BEGIN
SELECT MAX (deptno)
INTO v_max_deptno
FROM dept;
dbms_output.put_line (TO_CHAR (v_max_deptno));
END;
/

SET VERIFY OFF


ACCEPT p_dept_name PROMPT 'Please enter the
department name: '
DECLARE
v_max_deptno dept.deptno%TYPE;
BEGIN
SELECT MAX(deptno) + 10
INTO v_max_deptno
FROM dept;
INSERT INTO dept (deptno, dname, loc)
VALUES (v_max_deptno, '&p_dept_name' ,
NULL);
COMMIT;
END;
/
SET ECHO ON
SET VERIFY ON
3. @PROCESO

2. Create a PL/SQL that update the location for a existing


departament. Prompt the departament number and
departament location.
SET VERIFY OFF
ACCEPT p_dept_name PROMPT 'iNGRESE EL NOMBRE DEL
DEPARTAMENTO: '
DECLARE
v_max_deptno dept.deptno%TYPE;
BEGIN
SELECT MAX(deptno) + 10
INTO v_max_deptno
FROM dept;
INSERT INTO dept (deptno, dname, loc)
VALUES (v_max_deptno, '&p_dept_name' , NULL);
COMMIT;
END;
/
SET ECHO ON
SET VERIFY ON

3. Create a PL/SQL that deletes the departament created in


exercise 2. Prompt the departament number.

SET VERIFY OFF


ACCEPT p_deptno PROMPT 'Por favor ingrese el número de
departamento: '
ACCEPT p_loc PROMPT 'ingrese la localidad del
departamento: '
BEGIN
UPDATE dept
SET loc = '&p_loc'
WHERE deptno = &p_deptno;
COMMIT;
END;
/
SET VERIFY ON

SET VERIFY OFF


VARIABLE g_result VARCHAR2 (40)
ACCEPT p_deptno PROMPT 'NUMERO DEL
DEPARTAMENTO: '
DECLARE
v_result NUMBER (2) ;
BEGIN
DELETE
FROM dept
WHERE deptno = &p_deptno;
v_result := SQL%ROWCOUNT;
:g_result := (TO_CHAR(v_result) [[ 'row(s) deleted.') ;
COMMIT;
END;
/
PRINT g_result
SET VERIFY ON
2. @proceso

ACCEPT p_deptno PROMPT 'Introduzca el número de


departamento: '
DECLARE
v_result NUMBER (2) ;

You might also like