Mavzu: sql da funksiyalar va triggerlar yaratish
Omonov Abbosxon 612-20 guruh talabasui.
21 – 26 – laboratoriya ishi
Mavzu: SQL da funksiyalar va triggerlar yaratish.
Ishdan maqsad: SQL da triggerlarr va funksiyalar yaratish bo`yicha ko`nikmaga ega bo`lish.
Masalaning qo`yilishi: Berilgan predmet soha ma`lumotlar bazasidagi barcha ob`yektlarni ustida funsiyalar va triggerlar yaratish asosida amallarini bajarish.
Uslubiy ko`rsatmalar:
Triggerlar - bu to'g'ridan-to'g'ri chaqirilmaydigan, ammo ma'lum bir voqea sodir bo'lganda bajariladigan (qatorni qo'shish, o'chirish, yangilash) saqlanadigan protsedura.
Funksiyalar (FUNCTION) - protseduraga o'xshash, bu biz qayta-qayta ishlatmoqchi bo'lgan ba'zi SQL kod. Funktsiya va protsedura o'rtasidagi farq shundan iboratki, funktsiya faqat bitta parametrni qaytaradi va funktsiya "Call" qilmasdan nomi bilan chaqiriladi
FUNCTIONS
Minus
mysql> create function minus(a int, b int)
-> returns int
-> deterministic
-> begin
-> declare result int;
-> set result = a - b;
-> return (result);
-> end//
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
mysql> select minus(100, 25);
+----------------+
| minus(100, 25) |
+----------------+
| 75 |
+----------------+
1 row in set (0.00 sec)
mysql>
Bo`lish
mysql> create function bolish(a float, b float)
-> returns float
-> deterministic
-> begin
-> declare result float;
-> set result = a / b;
-> return (result);
-> end//
Query OK, 0 rows affected (0.00 sec)
mysql> select bolish(10, 3)//
+------------------+
| bolish(10, 3) |
+------------------+
| 3.33333325386047 |
+------------------+
1 row in set (0.06 sec)
mysql>
Ildiz
mysql> create function ildiz(a float)
-> returns float
-> deterministic
-> begin
-> declare result float;
-> set result = sqrt(a);
-> return (result);
-> end//
Query OK, 0 rows affected (0.07 sec)
mysql> select ildiz(16)//
+-----------+
| ildiz(16) |
+-----------+
| 4 |
+-----------+
1 row in set (0.00 sec)
mysql>
Modul
mysql> create function modul(a int)
-> returns int
-> deterministic
-> begin
-> declare result int;
-> set result = abs(a);
-> return (result);
-> end//
Query OK, 0 rows affected (0.00 sec)
mysql> select modul(-1)//
+-----------+
| modul(-1) |
+-----------+
| 1 |
+-----------+
1 row in set (0.00 sec)
mysql>
Dostları ilə paylaş: |