Skip to main content

Ejemplo Constrains Oracle


Incrementar los salarios de los empleados del departamento ‘IT’ en 1%, levantar una excepción en caso de que el salario 
actualizado exceda el salario máximo permitido para el puesto 


DECLARE
  name_department  departments.department_name%TYPE := 'IT';
incremento number := 1;
nvo_salario employees.SALARY%TYPE;
CURSOR CIncEmp(name_dept departments.department_name%TYPE) IS
    SELECT employee_id, first_name ||' '|| last_name as NombreEmp, salary, max_salary
FROM employees join jobs using(job_id)
JOIN departments using(department_id)
WHERE department_name = name_dept
    ORDER BY employee_id
    FOR UPDATE OF salary NOWAIT;

  BEGIN

  FOR RegEmp IN CIncEmp(name_department) LOOP
    DBMS_OUTPUT.PUT_LINE('ID. Empleado: ' || ' ' || RegEmp.employee_id);
DBMS_OUTPUT.PUT_LINE('Nombre Empleado: ' || ' ' || RegEmp.NombreEmp);
DBMS_OUTPUT.PUT_LINE('Salario Actual: ' || ' ' || RegEmp.salary);
DBMS_OUTPUT.PUT_LINE('% Incremento: ' || ' ' || Incremento/100);
Nvo_Salario:= RegEmp.salary * (1 + (incremento/100));
IF Nvo_Salario <= RegEmp.max_salary THEN
      UPDATE employees   SET salary = Nvo_Salario
      where current of CIncEmp;
DBMS_OUTPUT.PUT_LINE('Nuevo Salario ' || ' ' || Nvo_Salario);
    ELSE
      DBMS_OUTPUT.PUT_LINE('El aumento excede el limite preestablecido ' || RegEmp.salary ||' ' ||Nvo_Salario);
    END IF;
  END LOOP;
commit;
END;

Comments

Popular posts from this blog

Multimetro ( codigo ) vhdl

library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity Multimetro is port( clk: in std_logic; tst: inout std_logic_vector (3 downto 0); display: out std_logic_vector (7 downto 0):="00000000"; leds, anodos: out std_logic_vector (3 downto 0):="0000"); end Multimetro; architecture Behavioral of Multimetro is signal barrido: std_logic_vector (1 downto 0):="00"; signal anodo: std_logic_vector (3 downto 0):="0000"; signal contador: std_logic_vector (3 downto 0):="0000"; signal disp,disp1,disp2,disp3: std_logic_vector (7 downto 0):="00000010"; signal x,y,z,w: std_logic_vector (3 downto 0):="0000"; begin process(clk) begin if(clk'event and clk='1') then barrido<=barrido+'1'; if contador contador<=contador+'1'; elsif contador>tst then contador<="0000...

Cronometro (codigo) vhdl

library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity cronometro is     Port ( display : out  STD_LOGIC_VECTOR (7 downto 0);            clk, reset, enc : in  STD_LOGIC;            An  : out  STD_LOGIC_VECTOR (3 downto 0)); end cronometro; architecture Behavioral of cronometro is signal contador: std_logic_vector  (3 downto 0) :="0000"; signal segundos: std_logic_vector  (13 downto 0) :="00000000000000"; signal contador1: std_logic_vector  (3 downto 0) :="0000"; signal DecSeg: std_logic_vector  (9 downto 0) :="0000000000"; signal contador2: std_logic_vector  (3 downto 0) :="0000"; signal CentSeg: std_logic_vector  (7 downto 0) :="00000000"; signal Anodos: std_logic_vector (1 downto 0 ):="00"; begin Process (clk, reset, contador, segundos) begin if (clk'event and clk = '1') then ...