DB2 Stored Procedures versus Functions

Posted by: Martin Hubel in gravityisthelawDB2 Stored ProceduresDB2 LUWDB2 FunctionsDB2 Development on Print PDF

I provided a sample procedure written using SQL/PL earlier to check if a string contained only numbers. This is a common validation for input strings.

SQL UDFs cannot contain any commands that are outside the scope of the SQL reference. DB2 will take an SQL UDF and stick it directly into the calling SQL, so that when it's executed it's indistinguishable from the
rest of the SQL statement, as far as DB2 is concerned.

On the other hand, an SQL Procedure is a separate entity that contains it's own set of information specific to it's execution. As such, the SQL/PL language has directives that are NOT found in the SQL reference, as they are specific to the procedure processing. "DECLARE EXIT HANDLER" is one of them.

Also, stored procedures create a package. For the example MP1, the specific name is SQL080109124101300, as found in SYSCAT.PROCEDURES. The generated package name from Data Studio is P2410137. A bit of detective work was required to find how this name was created.

The package was created at 2008-01-09 12:41:01.377. So the package name was pulled from the middle of the timestamp, starting with the second digit of the hour to the hundredths of a second.

Comments (0)Add Comment

Write comment

busy