<s>
A	O
user-defined	B-Language
function	I-Language
(	O
UDF	O
)	O
is	O
a	O
function	O
provided	O
by	O
the	O
user	O
of	O
a	O
program	O
or	O
environment	O
,	O
in	O
a	O
context	O
where	O
the	O
usual	O
assumption	O
is	O
that	O
functions	O
are	O
built	O
into	O
the	O
program	O
or	O
environment	O
.	O
</s>
<s>
In	O
some	O
old	O
implementations	O
of	O
the	O
BASIC	O
programming	O
language	O
,	O
user-defined	B-Language
functions	I-Language
are	O
defined	O
using	O
the	O
"	O
DEFFN	O
"	O
syntax	O
.	O
</s>
<s>
More	O
modern	O
dialects	O
of	O
BASIC	O
are	O
influenced	O
by	O
the	O
structured	B-Language
programming	I-Language
paradigm	O
,	O
where	O
most	O
or	O
all	O
of	O
the	O
code	O
is	O
written	O
as	O
user-defined	B-Language
functions	I-Language
or	O
procedures	O
,	O
and	O
the	O
concept	O
becomes	O
practically	O
redundant	O
.	O
</s>
<s>
In	O
the	O
COBOL	B-Application
programming	I-Application
language	I-Application
,	O
a	O
user-defined	B-Language
function	I-Language
is	O
an	O
entity	O
that	O
is	O
defined	O
by	O
the	O
user	O
by	O
specifying	O
a	O
FUNCTION-ID	O
paragraph	O
.	O
</s>
<s>
A	O
user-defined	B-Language
function	I-Language
must	O
return	O
a	O
value	O
by	O
specifying	O
the	O
RETURNING	O
phrase	O
of	O
the	O
procedure	O
division	O
header	O
and	O
they	O
are	O
invoked	O
using	O
the	O
function-identifier	O
syntax	O
.	O
</s>
<s>
See	O
the	O
ISO/IEC	O
1989:2014	O
Programming	O
Language	O
COBOL	B-Application
standard	O
for	O
details	O
.	O
</s>
<s>
As	O
of	O
May	O
2022	O
,	O
the	O
IBM	O
Enterprise	O
COBOL	B-Application
for	O
z/OS	O
6.4	O
(	O
IBM	B-Language
COBOL	I-Language
)	O
compiler	O
contains	O
support	O
for	O
user-defined	B-Language
functions	I-Language
.	O
</s>
<s>
In	O
relational	B-Application
database	I-Application
management	I-Application
systems	I-Application
,	O
a	O
user-defined	B-Language
function	I-Language
provides	O
a	O
mechanism	O
for	O
extending	O
the	O
functionality	O
of	O
the	O
database	B-Application
server	I-Application
by	O
adding	O
a	O
function	O
,	O
that	O
can	O
be	O
evaluated	O
in	O
standard	O
query	O
language	O
(	O
usually	O
SQL	B-Language
)	O
statements	O
.	O
</s>
<s>
The	O
SQL	B-Language
standard	O
distinguishes	O
between	O
scalar	O
and	O
table	O
functions	O
.	O
</s>
<s>
A	O
scalar	O
function	O
returns	O
only	O
a	O
single	O
value	O
(	O
or	O
NULL	B-Language
)	O
,	O
whereas	O
a	O
table	O
function	O
returns	O
a	O
(	O
relational	O
)	O
table	O
comprising	O
zero	O
or	O
more	O
rows	O
,	O
each	O
row	O
with	O
one	O
or	O
more	O
columns	O
.	O
</s>
<s>
User-defined	B-Language
functions	I-Language
in	O
SQL	B-Language
are	O
declared	O
using	O
the	O
CREATE	O
FUNCTION	O
statement	O
.	O
</s>
<s>
Once	O
created	O
,	O
a	O
user-defined	B-Language
function	I-Language
may	O
be	O
used	O
in	O
expressions	O
in	O
SQL	B-Language
statements	O
.	O
</s>
<s>
This	O
also	O
includes	O
SELECT	B-Language
statements	I-Language
,	O
where	O
the	O
function	O
can	O
be	O
used	O
against	O
data	O
stored	O
in	O
tables	O
in	O
the	O
database	O
.	O
</s>
<s>
It	O
invokes	O
the	O
CtoF	O
user-defined	B-Language
function	I-Language
as	O
declared	O
above	O
in	O
order	O
to	O
convert	O
the	O
value	O
in	O
the	O
column	O
to	O
a	O
value	O
in	O
Fahrenheit	O
.	O
</s>
<s>
Each	O
user-defined	B-Language
function	I-Language
carries	O
certain	O
properties	O
or	O
characteristics	O
.	O
</s>
<s>
The	O
SQL	B-Language
standard	O
defines	O
the	O
following	O
properties	O
:	O
</s>
<s>
Language	O
-	O
defines	O
the	O
programming	O
language	O
in	O
which	O
the	O
user-defined	B-Language
function	I-Language
is	O
implemented	O
;	O
examples	O
include	O
SQL	B-Language
,	O
C	O
,	O
C#	O
and	O
Java	O
.	O
</s>
<s>
Parameter	O
style	O
-	O
defines	O
the	O
conventions	O
that	O
are	O
used	O
to	O
pass	O
the	O
function	O
parameters	O
and	O
results	O
between	O
the	O
implementation	O
of	O
the	O
function	O
and	O
the	O
database	O
system	O
(	O
only	O
applicable	O
if	O
language	O
is	O
not	O
SQL	B-Language
)	O
.	O
</s>
<s>
Note	O
that	O
the	O
function	O
name	O
does	O
not	O
have	O
to	O
be	O
unique	O
,	O
considering	O
overloaded	B-Language
functions	I-Language
.	O
</s>
<s>
Some	O
SQL	B-Language
implementations	O
require	O
that	O
function	O
names	O
are	O
unique	O
within	O
a	O
database	O
,	O
and	O
overloaded	B-Language
functions	I-Language
are	O
not	O
allowed	O
.	O
</s>
<s>
The	O
determinism	O
characteristic	O
has	O
an	O
influence	O
on	O
the	O
query	B-Language
optimizer	I-Language
when	O
compiling	O
a	O
SQL	B-Language
statement	O
.	O
</s>
<s>
SQL-data	O
access	O
-	O
tells	O
the	O
database	O
management	O
system	O
whether	O
the	O
function	O
contains	O
no	O
SQL	B-Language
statements	O
(	O
NO	O
SQL	B-Language
)	O
,	O
contains	O
SQL	B-Language
statements	O
but	O
does	O
not	O
access	O
any	O
tables	O
or	O
views	O
(	O
CONTAINS	O
SQL	B-Language
)	O
,	O
reads	O
data	O
from	O
tables	O
or	O
views	O
(	O
READS	O
SQL	B-Language
DATA	O
)	O
,	O
or	O
actually	O
modifies	O
data	O
in	O
the	O
database	O
(	O
MODIFIES	O
SQL	B-Language
DATA	O
)	O
.	O
</s>
<s>
User-defined	B-Language
functions	I-Language
should	O
not	O
be	O
confused	O
with	O
stored	B-General_Concept
procedures	I-General_Concept
.	O
</s>
<s>
Stored	B-General_Concept
procedures	I-General_Concept
allow	O
the	O
user	O
to	O
group	O
a	O
set	O
of	O
SQL	B-Language
commands	O
.	O
</s>
<s>
A	O
procedure	O
can	O
accept	O
parameters	O
and	O
execute	O
its	O
SQL	B-Language
statements	O
depending	O
on	O
those	O
parameters	O
.	O
</s>
<s>
A	O
procedure	O
is	O
not	O
an	O
expression	O
and	O
,	O
thus	O
,	O
cannot	O
be	O
used	O
like	O
user-defined	B-Language
functions	I-Language
.	O
</s>
<s>
Some	O
database	O
management	O
systems	O
allow	O
the	O
creation	O
of	O
user	B-Language
defined	I-Language
functions	I-Language
in	O
languages	O
other	O
than	O
SQL	B-Language
.	O
</s>
<s>
Microsoft	B-Application
SQL	I-Application
Server	I-Application
,	O
for	O
example	O
,	O
allows	O
the	O
user	O
to	O
use	O
.NET	B-Language
languages	I-Language
including	O
C#	O
for	O
this	O
purpose	O
.	O
</s>
<s>
DB2	O
and	O
Oracle	O
support	O
user-defined	B-Language
functions	I-Language
written	O
in	O
C	O
or	O
Java	O
programming	O
languages	O
.	O
</s>
<s>
There	O
are	O
three	O
types	O
of	O
UDF	O
in	O
Microsoft	B-Application
SQL	I-Application
Server	I-Application
2000	O
:	O
scalar	O
functions	O
,	O
inline	O
table-valued	O
functions	O
,	O
and	O
multistatement	O
table-valued	O
functions	O
.	O
</s>
<s>
Inline	O
table-valued	O
functions	O
return	O
the	O
result	B-Application
set	I-Application
of	O
a	O
single	O
SELECT	O
statement	O
.	O
</s>
<s>
Multistatement	O
table-valued	O
functions	O
return	O
a	O
table	O
,	O
which	O
was	O
built	O
with	O
many	O
TRANSACT-SQL	O
statements	O
.	O
</s>
<s>
User-defined	B-Language
functions	I-Language
can	O
be	O
invoked	O
from	O
a	O
query	O
like	O
built‑in	O
functions	O
such	O
as	O
OBJECT_ID	O
,	O
LEN	O
,	O
DATEDIFF	O
,	O
or	O
can	O
be	O
executed	O
through	O
an	O
EXECUTE	O
statement	O
like	O
stored	B-General_Concept
procedures	I-General_Concept
.	O
</s>
<s>
On	O
Microsoft	B-Application
SQL	I-Application
Server	I-Application
2000	O
a	O
table-valued	O
function	O
which	O
"	O
wraps	O
"	O
a	O
View	B-Language
may	O
be	O
much	O
faster	O
than	O
the	O
View	B-Language
itself	O
.	O
</s>
<s>
The	O
following	O
MyFunction	O
is	O
an	O
example	O
of	O
a	O
"	O
function-wrapper	O
"	O
which	O
runs	O
faster	O
than	O
the	O
underlying	O
view	B-Language
MyView	O
:	O
</s>
<s>
On	O
Microsoft	B-Application
SQL	I-Application
Server	I-Application
2005	O
the	O
result	O
of	O
the	O
same	O
code	O
execution	O
is	O
the	O
opposite	O
:	O
view	B-Language
is	O
executed	O
faster	O
than	O
the	O
"	O
function-wrapper	O
"	O
.	O
</s>
<s>
User-defined	B-Language
functions	I-Language
are	O
subroutines	O
made	O
of	O
one	O
or	O
more	O
Transact-SQL	O
statements	O
that	O
can	O
be	O
used	O
to	O
encapsulate	O
code	O
for	O
reuse	O
.	O
</s>
<s>
Has	O
both	O
control-flow	O
and	O
DML	O
statements	O
in	O
its	O
body	O
similar	O
to	O
stored	B-General_Concept
procedures	I-General_Concept
.	O
</s>
<s>
Apache	B-General_Concept
Hive	I-General_Concept
defines	O
,	O
in	O
addition	O
to	O
the	O
regular	O
user-defined	B-Language
functions	I-Language
(	O
UDF	O
)	O
,	O
also	O
user-defined	O
aggregate	O
functions	O
(	O
UDAF	O
)	O
and	O
table-generating	O
functions	O
(	O
UDTF	O
)	O
.	O
</s>
