Untitled

mail@pastecode.io avatar
unknown
plain_text
16 days ago
1.5 kB
10
Indexable
Never
09/02/2024
=============================================================================
Function:
there are two types of function:
1.inbuilt function
2.user define function.

syntax:-

create function Function_name(parameter datatype)
return retuen_datatype
begin
#decleration
#statements execution
end;

ex:
use second;
delimiter &&
 create function getempdetails(id int )
returns varchar(20)
READS SQL DATA
begin
     declare emp_name varchar(20);
     select name into emp_name from employee where emp_id =id;
return emp_name;
end &&
_______________________________________________________________________________________________________________________________________________________-
call function:
select * from employee;
select  distinct getempdetails(2)  from employee;


______________________________________________________________________________________________________________________________________________-

difference between storeprocedure and function:
1. store procedure : 1. store  procedure support input and output parameter
                     2store procedure cannot return any value
                     3.in store procedur all database operation perform.
                     4.store procedure call  function.


Function :1. function suport only input parameters
          2. function must return value.
          3. in function only select is allowed
          4.function can not call store procedure.

Leave a Comment