> For the complete documentation index, see [llms.txt](https://docs.layraweb.com.tr/merhaba/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.layraweb.com.tr/merhaba/sql-tarafi/konular/fonksiyon-konulari/user-defined-functions.md).

# User Defined Functions

SQL'de kullanıcı tanımlı işlevler (user-defined functions), belirli bir işlemi gerçekleştiren özel işlevlerdir. Bu işlevler, SQL sorgularının içinde kullanılabilen özelleştirilmiş kod parçalarıdır.

SQL'de iki tür kullanıcı tanımlı işlev bulunur: Skaler işlevler ve Tablo işlevleri.

Skaler işlevler, tek bir değer döndüren işlevlerdir. Örneğin, bir skaler işlev, iki sayıyı toplayıp sonucu döndürebilir.

Tablo işlevleri ise birden çok satırı döndürebilir. Örneğin, bir tablo işlevi, bir müşteri adı ve ülke adı verildiğinde, o ülkede bulunan tüm müşterilerin listesini döndürebilir.

İşlev tanımlama, CREATE FUNCTION anahtar kelimesiyle yapılır. Örneğin, aşağıdaki kod bir iki sayıyı toplayan bir işlev oluşturur:

```sql
CREATE FUNCTION sum_numbers (a INT, b INT)
RETURNS INT
BEGIN
  DECLARE c INT;
  SET c = a + b;
  RETURN c;
END;
```

Bu işlev, "sum\_numbers" adıyla ve iki tamsayı parametresi alan bir işlev olarak tanımlanır. "RETURNS" anahtar kelimesi, işlevin döndüreceği veri türünü belirtir. Bu durumda, işlev, tamsayı bir değer döndürür.

İşlev tanımlamadan sonra, işlev, bir SELECT sorgusu içinde kullanılabilir:

```sql
SELECT sum_numbers(10, 20);
```

Bu sorgu, "sum\_numbers" işlevini kullanarak 10 ve 20 sayılarını toplar ve sonucu döndürür.

Bu, basit bir örnek olmasına rağmen, kullanıcı tanımlı işlevler SQL sorgularının içinde birçok farklı işlem yapmak için kullanılabilir. İşlevler, özelleştirilmiş bir veri işleme mantığı sağlayarak, verilerinizi işlemenizi ve analiz etmenizi kolaylaştırır.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.layraweb.com.tr/merhaba/sql-tarafi/konular/fonksiyon-konulari/user-defined-functions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
