Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

SQL Stored Procedure vs. User-Defined Function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SQL Stored Procedure vs. User-Defined Function

    A stored procedure is a program.... You CALL MYPROCEDURE And it runs a set of statements, IFs, Dos, Selects, Fetches etc.... A function is a snipet of code that is used within an SQL statement Just liek the built in functions. For example you might say SELECT UPPER(CUSNAM) FROM CUSTMAST to display customer names in upper case. UPPER() is a function. You can write your own to do things like convert dates from your legacy format to a real date data type SELECT CVTDATE(LEGDAT) FROM MYORDMST Where CVTDATE() is a user defined function created by you to do whatever task you want it to do. Hope that helped!

  • #2
    SQL Stored Procedure vs. User-Defined Function

    Thanks!

    Comment


    • #3
      SQL Stored Procedure vs. User-Defined Function

      kforsythe wrote: > A function is a snipet of code that is used within an SQL statement > Just liek the built in functions. For example you might say I think to be more accurate: A function is used to return one and only one value when referenced. It can be much more than just a snipet of code, it can be as complex as you need it to be. I agree with the rest of the note. Bill

      Comment


      • #4
        SQL Stored Procedure vs. User-Defined Function

        A function can be defined as a procedure with return value. Stored procedures and user defined function must be explicitly called. Stored procedures are called by using the SQL statement CALL. User defined functions can be used like any SQL scalar function. Stored procedures can have input and output parameters, while user defined functions only can have input parameters. Output parameters must be returned as return values. With user defined table functions (UDTF) it is possible to return a set of values. If you create a stored procedure, a program object is created. Programs are always called dynamically. If you create a user defined function, a service program is created. The user defined function is a procedure in this service program and is statically called. You will find more information about stored procedures and user defined functions in the following redbooks: Modernizing eServer iSeries Application Data Access - A roadmap cornerstone http://www.redbooks.ibm.com/abstract...6393.html?Open and Stored Procedures, Triggers and User Defined Functions on DB2 UDB for iSeries http://publib-b.boulder.ibm.com/abst...6503.html?Open Birgitta

        Comment


        • #5
          SQL Stored Procedure vs. User-Defined Function

          Hi. I am trying to learn more about both stored procedures and user-defined functions. However, I keep getting confused. They seem very similar. Can someone explain for me what is the difference between the two? (Is there a difference, really?) And why I would use one over the other? Much thanks. DB

          Comment

          Working...
          X