Results 1 to 8 of 8

Thread: how differentiate between function and procedure?

  1. #1
    Junior Member
    Join Date
    Oct 2007
    Answers
    12

    how differentiate between function and procedure?

    In ORACLE where you are creating function, you can create Procedure and vice-versa?Can someone explain the practical sceneria where Procedure will work not Function or Vice-Versa?


  2. #2
    Expert Member
    Join Date
    Oct 2007
    Answers
    375

    Re: how differentiate between function and procedure?

    Use a function whenever you want to return a value.

    In some scenarios you wish to trap the return value when a function execution is completed and based on the return value proceed further.

    At these scenarios a procedure cannot be used as it only executes a pre-defined set of steps.


  3. #3
    Junior Member
    Join Date
    Oct 2007
    Answers
    12

    Re: how differentiate between function and procedure?

    But you can use RETURN keyword with procedure,so there is no difference at all in the functioning....


  4. #4
    Junior Member
    Join Date
    Nov 2006
    Answers
    9

    Re: how differentiate between function and procedure?

    1) Both are strored subprogrames
    2) functions can return a value back to the calling environment by its return statement
    3) procedures can not have any return statement ,but it can return more values via multiple OUT parameters to the calling programme
    4) function can be called from SQL statemetns
    5) procedure can not be called from the sql statments
    6) we can also use the OUT parameters in functions


  5. #5
    Junior Member
    Join Date
    Nov 2006
    Answers
    9

    Re: how differentiate between function and procedure?

    Quote Originally Posted by Sant_parkash View Post
    But you can use RETURN keyword with procedure,so there is no difference at all in the functioning....

    Yes ur right.but Acc to their syntax...we can not use any RETURN Statement in procedural declaration..I think it may be in the body section


  6. #6
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    Re: how differentiate between function and procedure?

    Quote Originally Posted by Sant_parkash View Post
    But you can use RETURN keyword with procedure,so there is no difference at all in the functioning....
    You can't use RETURN keyword to return any value out of the function. Function is mainly used in the case where it must return a value. Where as a procedure may or may not return a value or may return more than one value using the OUT parameter. Where you want to retun a value it is strongly recommended to use a function not a procedure even though you can use it with OUT parameters..


  7. #7
    Expert Member
    Join Date
    Apr 2007
    Answers
    500

    Re: how differentiate between function and procedure?

    Functions are normally used for computations where as procedures
    are normally used for executing business logic.

    Functions MUST return a value, procedures doesn't need to.

    You can have DML (insert,update, delete) statements in a function. But, you cannot call such a function in a SQL query.
    For example, if you have a function that is updating a table, you cannot call that function from a SQL query.
    - select myFunction(field) from sometable; will throw error.

    Function returns 1 value only. Procedure can return multiple values (max 1024).

    Stored Procedure: supports deferred name resolution. Example while writing a stored procedure that uses table named tabl1 and tabl2 etc..but actually not exists in database is allowed only in during creation but runtime throws error Function wont support deferred name resolution. Stored procedure returns always integer value by default zero. where as function return type could be
    scalar or table or table values(SQL Server).
    Stored procedure is precompiled execution plan where as functions are not.

    A procedure may modify an object where a function can only return a value.


  8. #8
    Junior Member
    Join Date
    Sep 2007
    Answers
    7

    Re: how differentiate between function and procedure?

    function return something whereas procedure dont return anything


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact