Файл: Ctpyкtypиpobaнныe элemeнtы пpoцeдypнoгo яsыкa пpoгpammиpobaния c яsыкom.docx

ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 11.01.2024

Просмотров: 132

Скачиваний: 1

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

HAИMEHOBAHHЫE PL/SQL БЛOKИ



Cosдaниe фyнкции:





Пpnмep 15:

Paspa6otatь фyнкцию, bычиcляющyю плoщaдь кpyгa

create or replace function lokrug(radius real) return real is

l real; begin

l:=3.14*radius*2; return(l);

end;

/
create or replace function lokrug1(radius real) return real is

begin return(3.14*radius*2);

end;

CREATE OR REPLACE FUNCTION round_square(radius REAL) RETURN REAL IS result REAL;

BEGIN

result := 3.14*radius**2; return(result);

END round_square;

/
DECLARE

radius REAL := &radius; BEGIN

DBMS_OUTPUT.enable; DBMS_OUTPUT.PUT_LINE(round_square(radius));

END;



Coздaнne пpoцeдypы






Пpnмep 16:

Paspa6otatь пpoцeдypy, bычиcляющyю плoщaдь кpyгa и длинy oкpyжнoctи

Prompt øopMиpyeM oтueт пo вceM oбъeктaM coзд. зa пpoMemyтoк вpeMeни

create or replace procedure prot_user is

db date:=&db; de date:=&de;

a char(20); b char(20); c date; e date;

begin

select substr(object_name,1,20) name, substr(object_type,1,20)

type_obj,

created, last_ddl_time into a,b,c,e

from user_objects

where last_ddl_time>=db and

last_ddl_time<=de; end;/



CREATE OR REPLACE PROCEDURE Sqr_len(radius REAL) IS

BEGIN DBMS_OUTPUT.ENABLE; DBMS_OUTPUT.PUT_LINE('

Плo4aдaкpysa- ' ||

TO_CHAR(3.14*radius**2)

);

DBMS_OUTPUT.PUT_LINE(

'Длuнaoкpyжнocmu- ' ||

TO_CHAR(2*3.14*radius)

);

END;

/
DECLARE

radius REAL := &radius;

BEGIN

Sqr_len(radius);

END;








Bыsob фyнкций и пpoцeдyp пaкeta:
Coздaнne пaкeta


  1. Cosдaet cпeцификaцию для xpaниmoгo пaкeta:




  1. Cosдaet teлo xpaниmoгo пaкeta:






Пpnмep 17:

Paspa6otatь пaкet гeometpичecкий кaлькyляtop, кotopый пo bbeдeннomy sнaчeнию paдиyca bычиcляet плoщaдь кpyгa и длинy oкpyжнoctи (иcпoльsyя фyнкции и пpoцeдypы)


CREATE OR REPLACE PACKAGE calc IS

FUNCTION square (radius IN REAL) RETURN REAL;

PROCEDURE length (radius IN REAL, len OUT VARCHAR);

END calc;

/
CREATE OR REPLACE PACKAGE BODY calc IS

FUNCTION square (radius in REAL) RETURN REAL IS

BEGIN

RETURN(3.14*radius**2);

END;
PROCEDURE length (radius in REAL, len OUT VARCHAR) IS

BEGIN

len:=2*3.14*radius;

DBMS_OUTPUT.ENABLE; DBMS_OUTPUT.PUT_LINE(len);

END;

END calc;

/
DECLARE

sqr REAL;

len REAL;

rad REAL:=&rad;

BEGIN

sqr := calc.square(rad);

calc.length(rad,len);

DBMS_OUTPUT.PUT_LINE('Плoщaдь paвнa = ' || TO_CHAR(sqr));

DBMS_OUTPUT.PUT_LINE('Длnнa paвнa = ' || TO_CHAR(len));

END;

Coздaнne tpnггepa






Пpnмep 18:

Paspa6otatь tpиггepы для bcex ta6лиц baшeй cxemы, o6ecпeчиbaющиx abtomatичecкyю bctabкy yникaльнoгo sнaчeния пoля ID.

CREATE SEQUENCE test1_seq START WITH 1;
CREATE TABLE test1 ( id NUMBER,

data VARCHAR2(255)

);

CREATE OR REPLACE TRIGGER test1_trig BEFORE INSERT ON test1

FOR EACH ROW BEGIN

SELECT test1_seq.NEXTVAL INTO :new.id

FROM DUAL; END;

/
select * from dba_errors where name = 'TEST1_TRIG'







На следующей странице
Coздaнne кoнctpeйtob




Пpnмep 19:

Paspa6otatь кoнctpeйtы для bcex cbяseй ta6лиц baшeй инфoлoгичecкoй moдeли (cm cem 1), o6ecпeчиbaющиx ccылoчнyю цeлoctнoctь дaнныx.

ALTER TABLE abonents ADD CONSTRAINT

C_abonents_ab_kateg FOREIGN KEY (ab_kateg)

REFERENCES

list_kategs(lk_id);
ALTER TABLE telefons ADD CONSTRAINT

C_telefons_tel_ab_num FOREIGN KEY (tel_ab_num)

REFERENCES

abonents(ab_num);









Пpnмep 20:

Пpobepиtь кoppeкtнyю pa6oty cosдaнныx кoнctpeйtob

INSERT INTO Device (device_id

INSERT INTO Plan (plan_id) VA INSERT INTO Device (device_id



, device_plan_id) VALUES (1, 1);

LUES (1);

, device_plan_id) VALUES (1, 1);



Koнtpoльныe boпpocы





    1. Пpинципы paspa6otки нeнaиmeнobaнныx PL/SQL 6лoкob

    2. Пpинципы paspa6otки и иcпoльsobaния нaиmeнobaнныx PL/SQL 6лoкob.

CREATE TABLE Device (

device_plan_id INTEGER NULL,

device_id INTEGER NOT NULL, device_employ_id INTEGER NULL, device_rev VARCHAR2(16) NULL,

device_status VARCHAR2(32) NULL

);
CREATE TABLE Employees (

employ_name VARCHAR2(32) NULL,

employ_id INTEGER NOT NULL, employ_surname VARCHAR2(32) NULL, employ_status VARCHAR2(32) NULL,

employ_func VARCHAR2(64) NULL

);
CREATE TABLE Equipment (

eqip_name VARCHAR2(128) NULL,

eqip_id INTEGER NOT NULL,

eqip_func VARCHAR2(128) NULL,

eqip_status VARCHAR2(32) NULL

);
CREATE TABLE Parts (

part_name VARCHAR2(128) NULL,

part_id INTEGER NOT NULL,

part_spec VARCHAR2(64) NULL,

part_num_avail INTEGER
NULL

);
CREATE TABLE Plan (

plan_eqip_id INTEGER NULL,

plan_id INTEGER NOT NULL,

plan_part_id INTEGER NULL,

plan_status VARCHAR2(32) NULL

);
ALTER TABLE Device

ADD CONSTRAINT pk_dev_id PRIMARY KEY (device_id);
ALTER TABLE Employees

ADD CONSTRAINT pk_emp_id PRIMARY KEY (employ_id);
ALTER TABLE Equipment

ADD CONSTRAINT pk_eqip_id PRIMARY KEY (eqip_id);
ALTER TABLE Parts

ADD CONSTRAINT pk_part_id PRIMARY KEY (part_id);
ALTER TABLE Plan

ADD CONSTRAINT pk_plan_id PRIMARY KEY (plan_id);
ALTER TABLE Device

ADD CONSTRAINT c_device_employ_id FOREIGN KEY (device_employ_id)

REFERENCES Employees;
ALTER TABLE Device

ADD CONSTRAINT c_device_plan_id

FOREIGN KEY (device_plan_id) REFERENCES Plan;
ALTER TABLE Plan

ADD CONSTRAINT c_plan_eqip_id

FOREIGN KEY (plan_eqip_id) REFERENCES Equipment;
ALTER TABLE Plan

ADD CONSTRAINT c_plan_part_id

FOREIGN KEY (plan_part_id) REFERENCES Parts;