|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Execute procedure
hi guys,
i have some problem here, below is my procedure and some how it won't insert when ever i run it. i can't find any problems with the coding, so hopefully you guys would help me out. Code:
create or replace procedure insertinstructor(v_salary number, date_hired varchar2, v_insructid number, v_instrucname varchar2, v_commission number, v_mentorid number) is
v_mentor_id instructor.mentor_id%TYPE;
mentee_count pls_integer := 0;
mentor_salary instructor.salary%TYPE;
mentor_hired_date date;
begin
if (v_mentor_id is not null ) then
select count(*) into mentee_count from instructor where mentor_id = v_mentor_id;
if (mentee_count != 0 ) then
select salary, date_hired into mentor_salary, mentor_hired_date from instructor where instructor_id = v_mentor_id;
if mentor_salary <= 3500 AND MONTHS_BETWEEN(SYSDATE, to_date(mentor_hired_date,'dd-mon-yyyy') ) / 12 <= 21
THEN
RAISE_APPLICATION_ERROR (-20501, 'Inserting Record Failure,Only instructor that work more than 21 years or salary more than 3500 can act as mentor');
else
insert into INSTRUCTOR (salary, DATE_HIRED,INSTRUCTOR_ID,INSTRUCTOR_NAME, COMMISSION, MENTOR_ID)
values(v_salary,to_date(date_hired,'dd-mon-yyyy'),v_insructid, v_instrucname, v_commission, v_mentorid);
commit;
end if;
end if;
end if;
end;
/
i'm using this to execute the procedure Code:
exec insertinstructor (1000,'24-Jun-1999',991,'MEN',200,453); the procedure should raise an error message when i insert this value, but it just come out this message when i execute it. Code:
SQL> @execinsert PL/SQL procedure successfully completed. |
|
#2
|
|||
|
|||
|
in one of your selects from instructor you are matching v_mentor_id to mentor_id. In the next you are matching v_mentor_id to instructor_id.... Is that your problem?
|
|
#3
|
|||
|
|||
|
i dont get what u mean there,
and yes i'm matching v_mentor_id to mentor_id and v_mentor_id to instructor_id |
|
#4
|
|||
|
|||
|
sorry about that... I see what you are doing now... It looks like the real issue is that the variable v_mentor_id is never getting set, so the procedure fails on the first if statement. The variable that is getting set when you call the procedure is v_mentorid (note the missing "_"). So you either need to remove your current v_mentor_id declaration and change v_mentorid parameter to v_mentor_id, or update your v_mentor_id declaration to be v_mentor_id instructor.mentor_id%TYPE := v_mentorid;, so v_mentor_id will have a value when your code gets to the first if statement.
|
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > Execute procedure |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|