Click here to Skip to main content
15,899,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello.

I need to create a stored procedure that allows to change the name of a teacher
based on their code.

This procedure should return a value of 1 on sucess and the value 0 otherwise.

I did this:

create or replace procedure ChangeName(codeT in number, name in varchar2)
as
begin
update teacher set teachername = name where codeteacher = codeT;
end;


And it works fine..but i need also to :"
SQL
return a value of 1 on sucess  and the value 0 otherwise.
"

Someone can help me to do this part?
Thank you very much for attention!
Posted

1 solution

What about this:
SQL
create or replace procedure ChangeName
( codeT IN number
, name IN varchar2
, success OUT number
)
as
begin
update teacher set teachername = name where codeteacher = codeT;
if sql%rowcount = 1 then
    success := 1;
else
    success := 0;
end if;
end;
 
Share this answer
 
Comments
mibetty 10-Jun-13 16:30pm    
thank you very much.
probably is that..but i wanted to test.
usually to test i execute the procedures in sqlPlus (because i dont know execute in oracle) like this: execute procedurename (parameter1, parameter2).
But now im doing this execute changename(1,'John',sucess) and i got a error saying that sucess must be declared..do you know how i can execute the procedure with right parameters?
Zoltán Zörgő 11-Jun-13 3:42am    
Since there is an out parameter, you need a variable to store the result.
Check this: http://psoug.org/definition/OUT.htm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900