简体   繁体   中英

REPLACE procedure on oracle 12c

When selecting the employee name and salary of 1500 if there is 1 employee, insert into tMessage the employee's name and the salary amount. If there are 2 or more employees, insert multiple lines. If there are no employees then insert into tMessage without any staff.

create or REPLACE procedure temployees_i(
  v_aempname in tregions.aregid%type,
  v_aempsal number(3):=1500),
)
is 
BEGIN
  select lastname,salary from employees ;
EXCEPTION
  WHEN SALARY=v_aempsal THEN
    insert into tMessage values ('have qualified staff'|| lastname ||'of' salary);
  WHEN SALARY!=v_aempsal THEN
    insert into tMessage values ('There are no employees
  ');
END;

I think that's you want.

   CREATE OR REPLACE PROCEDURE temployees_i( v_aempsal number := 1500 )
   IS 
     TYPE emprec IS RECORD (empname VARCHAR2(50), salary NUMBER(9,2));
     TYPE emp_tab IS TABLE OF emprec;
     
     empv emp_tab;
     BEGIN

      SELECT lastname, salary bulk COLLECT INTO empv from employees WHERE 
      SALARY = v_aempsal ;
      
        IF empv.count != 0 then
             FORALL i in 1..empv.COUNT 
                insert into tMessage values ('have qualified staff '|| 
                empv(i).empname ||'of ' ||empv(i).salary);
        ELSE
             INSERT INTO tMessage VALUES ('There are no employee');
        END IF;
      COMMIT;

END;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM