Re: SQL Functions & Queries

From: Lennart Jonsson <>
Date: 23 Oct 2002 12:44:59 -0700
Message-ID: <> (K.Y. Fung) wrote in message news:<>...
> Hi everybody,
> I got some questions about SQL Function.
> 1. If there is a way to write queries & statements in a
> Function, does it also mean there is another way to
> write the queries & statement (such as, writing the
> query by query & statement by statement method)?

First there are several types of functions (since DB2 is the only db I know, I'll use things from there).

  1. functions written in sql.
  2. functions written in external languages such as C or java.

The functions written in sql can of course be written as a sequence of queries (eventhough I seem to remember that there are some procedural constructs, such as IF which might be difficult to transform).

SQL is really good at certain things, and less good at other things. Assume for example that you would like to send someone a mail when some special thing happens in the database. A function written in Java might be the answer.

> 2. If my assumption is correct, then why we need
> Funtions?

For functions of type 2 above the answer is already given (I hope :). For functions of type 1 above, the same arguments as why you need functions in any other language holds, encapsulation, abstraction, maintenance.

> 3. Are both ways performing a Single Action without
> interaction with any User Process?

I'm not sure I understand here. Could you elaborate?

/Lennart Received on Wed Oct 23 2002 - 21:44:59 CEST

Original text of this message