User Defined Function

User Defined Function

Eine Benutzerdefinierte Funktion (engl. User Defined Function, Abkürzung UDF) in einer Programmierumgebung bezeichnet eine Funktion, die der Anwender selbst erstellen und in seine Projekte einbinden kann. Sie erfüllt eine Aufgabe wie ein Makro, wird jedoch über einen Funktionsaufruf realisiert. UDFs sind in allgemeinen Programmiersprachen wie Visual Objects, Skriptsprachen wie PHP, spezieller Makrosoftware wie AutoIt und in Datenbanksprachen wie SQL und Firebird verfügbar.

Die Syntax einer UDF muss der Syntax der zugrundeliegenden Sprache entsprechen, wobei vordefinierte Standardfunktionen und andere UDFs in der Definition verwendet werden können. Als Funktion muss eine UDF genau einen Rückgabewert liefern.

Im Gegensatz zu einer Stored Procedure kann eine UDF nicht als Programm gestartet werden.

Beispiele

Einfache UDF in SQL

Der folgenden UDF werden zwei Datumswerte übergeben, die Funktion gibt das jüngere Datum zurück.

 CREATE FUNCTION [MaxDateValue] (@v1 datetime ,  @v2 datetime)  
 RETURNS datetime AS  
 BEGIN 
 IF (@v1 < @v2) 
    RETURN (@v2)
 RETURN(@v1)
 END

Nachdem diese UDF in der Datenbank gespeichert ist, kann sie innerhalb einer SQL-Abfrage verwendet werden:

 SELECT MaxDateValue(KaufDatum, Bestelldatum) FROM Auftrag
External Table Function („externe Tabellenfunktion“) in SQL

In dieser Variante wird genau eine (unbenannte) SQL-Tabelle als Rückgabewert geliefert. Sie kann innerhalb einer SQL-Anweisung überall dort stehen, wo auch eine SQL-Tabelle stehen kann. Auf SQL-Ebene wird ein Kontrolleintrag definiert, der auf ein externes Programm verweist. Das Datenbanksystem unterstützt in der Regel mehrere Programmiersprachen, in denen das Programm geschrieben werden kann.


Wikimedia Foundation.

Игры ⚽ Поможем решить контрольную работу

Schlagen Sie auch in anderen Wörterbüchern nach:

  • User-defined function — A User Defined Function, or UDF, is a function provided by the user of a program or environment, in a context where the usual assumption is that functions are built into the program or environment.BASIC languageIn some old implementations of the… …   Wikipedia

  • user-defined function — noun A program or subroutine written by an application programmer that returns the value of a mathematical function …   Wiktionary

  • Function point — A function point is a unit of measurement to express the amount of business functionality an information system provides to a user. Function points are the units of measure used by the IFPUG Functional Size Measurement Method. The IFPUG FSM… …   Wikipedia

  • Function key — A function key is a key on a computer or terminal keyboard which can be programmed so as to cause an operating system command interpreter or application program to perform certain actions. On some keyboards/computers, function keys may have… …   Wikipedia

  • User-generated content — UGC redirects here. For other uses, see UGC (disambiguation). User generated content (UGC) covers a range of media content available in a range of modern communications technologies. It entered mainstream usage during 2005 having arisen in web… …   Wikipedia

  • Main function (programming) — In some programming languages, the main function is where a program starts execution. It is generally the first user written function run when a program starts (some system specific software generally runs before the main function), though some… …   Wikipedia

  • Map (higher-order function) — In many programming languages, map is the name of a higher order function that applies a given function to each element of a list, returning a list of results. They are examples of both catamorphisms and anamorphisms. This is often called apply… …   Wikipedia

  • First-class function — In computer science, a programming language is said to support first class functions (or function literal) if it treats functions as first class objects. Specifically, this means that the language supports constructing new functions during the… …   Wikipedia

  • Strict function — A strict function in the denotational semantics of programming languages is a function f where . The entity , called bottom, denotes an expression which does not return a normal value, either because it loops endlessly or because it aborts due to …   Wikipedia

  • Help:User style — This Wikipedia help page is outdated. Please update this Wikipedia help page to reflect recent events or newly available information. Please see the talk page for more information. The user can customize fonts, colors, positions of links in the… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”