Ishdan maqsad: Ma’lumotlar bazasining infologik va mantiqiy modelini, er diagrammalarini yaratishni o‘rganish. Topshiriqlar


Download 1.49 Mb.
bet52/57
Sana27.01.2023
Hajmi1.49 Mb.
#1132339
1   ...   49   50   51   52   53   54   55   56   57
Bog'liq
2 5375303174699622638

CREATE [OR REPLACE] PACKAGE BODY
Paket_nomi {IS|AS} РL/SQL_da_paket_spetsifikatsiyasi
Yuqorida keltirilgan kod uchun paket tanasini yaratamiz. Faraz qilamiz, mulconst paket funksiyasi argumentni paket konstantasiga ko‘paytirishni bajarsin.
AUDITMUL protsedura esa mulconst funksiyasiga murojaatlar faktini fiksirlasin. Mulconst jadvalining yozuvlarini jadvaldagi qiymatlarni murojaat qilingandagi sanani yozib qo‘ysin. Paket tanasi yaratilgunga qadar TabAUD jadvalining mos ravishda atribut toifalari yaratilgan bo‘lishi kerak.
CREATE OR REPLACE PACKAGE BODY PACAA AS
PACAA_COUNT NUMBER := 0;
FUNCTION MULCONST(Argl NUMBER) RETURN NUMBER
IS BEGIN
AUDITMUL;
RETURN Argl*PACAA_CONST;
END;
PROCEDURE AUDITMUL IS
BEGIN
PACAA_COUNT := PACAA_COUNT + 1;
INSERT INTO TabAUD VALUES(PACAA_COUNT, SYSDATE); COMMIT;
END;
END;
Package body created.
Misol. Paket yaratishga yana bir misol.
create package pkgSalary As function fSalary(emp_id IN number) RETURN number; procedure pSalary(emp_id number, nSalary number); end pkgSalary;
Paketning asosiy qismini yaratish:
create package body pkgSalary AS function fSalary(emp_id IN number) RETURN number is nSalary number(10,2);
BEGIN
SELECT salary into nSalary from employees where employee_id = emp_id;
RETURN nSalary; end;
procedure pSalary(emp_id number, nSalary number) AS BEGIN
update hr.employees set salary = nSalary where employee_id =
emp_id; END;
end pkgSalary;
Paketdagi funksiyaga murojaat:
begin dbms_output.put_line(pkgSalary.fSalary(100)); end;
Paketdagi protseduraga murojaat:
begin pkgSalary.pSalary(100, 26000); end;

Download 1.49 Mb.

Do'stlaringiz bilan baham:
1   ...   49   50   51   52   53   54   55   56   57




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling