Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Check if there is a department name with the same name

2832023Dec 28 2015 — edited Dec 30 2015

I would like to make a procedure that will help me add a new row in the Departments table. I have to insert department_id, department_name, location_id and manager_id. I made this successfully with that code:


create or replace PROCEDURE add_depar(
  p_name VARCHAR2
, p_mgr NUMBER, p_loc NUMBER) IS
BEGIN
 
INSERT INTO DEPARTMENTS (department_id,
  department_name
, manager_id, location_id)
 
VALUES (DEPARTMENTS_SEQ.NEXTVAL, p_name, p_mgr, p_loc);
  DBMS_OUTPUT
.PUT_LINE('Added Dept: '|| p_name);
EXCEPTION
WHEN OTHERS THEN
  DBMS_OUTPUT
.PUT_LINE('Err: adding dept: '|| p_name);
END;


Now I'd like to check the uniqueness of the department_name, And if the requirements are not done, I would like to make an exception for that. May I ask for your help! I have tried to do this many times, but still not resolved. Please help!

Thanks

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 27 2016
Added on Dec 28 2015
23 comments
4,343 views