Π‘ΠΊΡΠΈΠΏΡ ΠΏΠΎ ΡΠΎΠ·Π΄Π°Π½ΠΈΡ Ρ ΡΠ°Π½ΠΈΠΌΡΡ ΠΏΡΠΎΡΠ΅Π΄ΡΡ
DECLARE VARIABLE discount INTEGER; WHERE c. id_client=:id_client; CREATE PROCEDURE view_address. CREATE PROCEDURE not_executed. DECLARE VARIABLE summa money; SET c. discount = :discount. Apartament_number transfer). GROUP BY o. id_client. INTO: id_client:summa. AND o. executed = '0'. UPDATE client c. Discount = '0'; FROM orders o. Set term ;!! Set term !!; Suspend; Suspend; Begin. Begin. Begin… Π§ΠΈΡΠ°ΡΡ Π΅ΡΡ >
Π‘ΠΊΡΠΈΠΏΡ ΠΏΠΎ ΡΠΎΠ·Π΄Π°Π½ΠΈΡ Ρ ΡΠ°Π½ΠΈΠΌΡΡ ΠΏΡΠΎΡΠ΅Π΄ΡΡ (ΡΠ΅ΡΠ΅ΡΠ°Ρ, ΠΊΡΡΡΠΎΠ²Π°Ρ, Π΄ΠΈΠΏΠ»ΠΎΠΌ, ΠΊΠΎΠ½ΡΡΠΎΠ»ΡΠ½Π°Ρ)
Π Π±Π°Π·Π΅ Π΄Π°Π½Π½ΡΡ Π½Π΅ΠΎΠ±Ρ ΠΎΠ΄ΠΈΠΌΠΎ ΡΠΎΠ·Π΄Π°ΡΡ ΡΠ»Π΅Π΄ΡΡΡΠΈΠ΅ Ρ ΡΠ°Π½ΠΈΠΌΡΠ΅ ΠΏΡΠΎΡΠ΅Π΄ΡΡΡ:
- 1. ΠΡΠ²Π΅ΡΡΠΈ Π²ΡΠ΅ Π½Π΅ΠΏΠΎΠ³Π°ΡΠ΅Π½Π½ΡΠ΅ Π·Π°ΠΊΠ°Π·Ρ Π²ΠΌΠ΅ΡΡΠ΅ Ρ ΡΠΎΠ²Π°ΡΠΎΠΌ, ΠΈΡ ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎΠΌ ΠΈ ΡΠΎΡΡΡΠ΄Π½ΠΈΠΊΠΎΠ² ΠΊΠΎΡΠΎΡΡΠ΅ ΠΈΡ Π²ΡΠΏΠΎΠ»Π½ΡΡΡ.
- 2. Π Π°ΡΡΠ΅Ρ ΠΈ Π·Π°Π½Π΅ΡΠ΅Π½ΠΈΠ΅ ΡΠΊΠΈΠ΄ΠΊΠΈ Π΄Π»Ρ ΠΊΠ»ΠΈΠ΅Π½ΡΠ° Π² Π·Π°Π²ΠΈΡΠΈΠΌΠΎΡΡΠΈ ΠΎΡ ΡΡΠΌΠΌΡ ΠΏΠΎΡΡΠ°ΡΠ΅Π½Π½ΠΎΠΉ ΠΈΠΌ Π½Π° ΡΠΎΠ²Π°ΡΡ.
- 3. ΠΡΠ²Π΅ΡΡΠΈ Π³ΠΎΡΠΎΠ΄, ΡΠ»ΠΈΡΡ, Π΄ΠΎΠΌ, ΠΊΠ²Π°ΡΡΠΈΡΡ, ΠΈ ΡΠ΅Π»ΠΎΠ²Π΅ΠΊΠ° ΠΊΠΎΡΠΎΡΡΠΉ ΠΏΡΠΎΠΆΠΈΠ²Π°Π΅Ρ ΠΏΠΎ Π΄Π°Π½Π½ΠΎΠΌΡ Π°Π΄ΡΠ΅ΡΡ.
/************************************************************/.
/*ΠΡΠ²Π΅ΡΡΠΈ Π²ΡΠ΅ Π½Π΅ΠΏΠΎΠ³Π°ΡΠ΅Π½Π½ΡΠ΅ Π·Π°ΠΊΠ°Π·Ρ Π²ΠΌΠ΅ΡΡΠ΅ Ρ ΡΠΎΠ²Π°ΡΠΎΠΌ, ΠΈΡ ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎΠΌ ΠΈ ΡΠΎΡΡΡΠ΄Π½ΠΈΠΊΠΎΠ² ΠΊΠΎΡΠΎΡΡΠ΅ ΠΈΡ Π²ΡΠΏΠΎΠ»Π½ΡΡΡ */.
/************************************************************/.
/*ΠΠ²ΠΎΠ΄ΠΈΠΌ ΠΏΠΎΠ»Π΅ «ΠΏΠΎΠ³Π°ΡΠ΅Π½ΠΎ» Π² ΡΠ°Π±Π»ΠΈΡΡ Π·Π°ΠΊΠ°Π·*/.
ALTER TABLE orders ADD executed INTEGER CHECK ((executed IN (0,1)) and (executed is not null));
/*Π²Π²ΠΎΠ΄ΠΈΠΌ Π΄Π»Ρ ΠΊΠ»ΠΈΠ΅Π½ΡΠ° ΠΏΠΎΠ»Π΅ ΡΠΊΠΈΠ΄ΠΊΠ°*/.
ALTER TABLE client ADD discount INTEGER DEFAULT 0 CHECK (discount IS NOT NULL);
SET TERM !!;
CREATE PROCEDURE not_executed.
RETURNS (id_order INTEGER, name VARCHAR (20), quantity INTEGER,.
manager VARCHAR (20), seller VARCHAR (20), forwarding_agent VARCHAR (20), driver VARCHAR (20)).
AS.
BEGIN.
FOR.
SELECT o. id_order, r. quantity, g.name,.
- (SELECT e. fio FROM employee e WHERE e. id_employee=o.manager) AS manager,
- (SELECT e. fio FROM employee e WHERE e. id_employee=o.seller) AS seller,
- (SELECT e. fio FROM employee e WHERE e. id_employee=d.forwarding_agent) AS forwarding_agent,
- (SELECT e. fio FROM employee e WHERE e. id_employee=d.driver) AS driver
FROM orders o, row_order r, goods g, row_delivery rd, delivery d.
WHERE r. id_order=o.id_order AND r. id_goods=g.id_goods AND rd. id_order=o.id_order AND d. id_delivery=rd.id_delivery.
AND o. executed = '0'.
INTO :id_order:quantity:name:manager:seller:forwarding_agent:driver.
DO.
SUSPEND;
END!
/************************************************************/.
/*Π Π°ΡΡΠ΅Ρ ΠΈ Π·Π°Π½Π΅ΡΠ΅Π½ΠΈΠ΅ ΡΠΊΠΈΠ΄ΠΊΠΈ Π΄Π»Ρ ΠΊΠ»ΠΈΠ΅Π½ΡΠ° Π² Π·Π°Π²ΠΈΡΠΈΠΌΠΎΡΡΠΈ ΠΎΡ ΡΡΠΌΠΌΡ ΠΏΠΎΡΡΠ°ΡΠ΅Π½Π½ΠΎΠΉ ΠΈΠΌ Π½Π° ΡΠΎΠ²Π°ΡΡ */.
/************************************************************/.
CREATE PROCEDURE calculate_discount.
AS.
DECLARE VARIABLE id_client INTEGER;
DECLARE VARIABLE summa money;
DECLARE VARIABLE discount INTEGER;
BEGIN.
FOR.
SELECT o. id_client, SUM (o.cost).
FROM orders o.
GROUP BY o. id_client.
INTO :id_client:summa.
DO.
BEGIN.
IF (:summa>'3000') THEN discount = '5'; ELSE.
IF ((:summa'3000')) THEN discount = '7'; ELSE.
IF (:summa>'10 000') THEN discount = '10'; ELSE.
discount = '0';
UPDATE client c.
SET c. discount = :discount.
WHERE c. id_client=:id_client;
END.
END!
/************************************************************/.
/*ΠΡΠ²Π΅ΡΡΠΈ Π³ΠΎΡΠΎΠ΄, ΡΠ»ΠΈΡΡ, Π΄ΠΎΠΌ, ΠΊΠ²Π°ΡΡΠΈΡΡ, ΠΈ ΡΠ΅Π»ΠΎΠ²Π΅ΠΊΠ° ΠΊΠΎΡΠΎΡΡΠΉ ΠΏΡΠΎΠΆΠΈΠ²Π°Π΅Ρ ΠΏΠΎ Π΄Π°Π½Π½ΠΎΠΌΡ Π°Π΄ΡΠ΅ΡΡ*/.
/************************************************************/.
CREATE PROCEDURE view_address.
returns (fio varchar (20), city_name varchar (20), street_name varchar (20), house_number transfer,.
apartament_number transfer).
AS.
BEGIN.
FOR.
SELECT c. fio, ci. city_name, s. street_name, a. house_number, a. apartament_number.
FROM client c, address a, city ci, street s.
WHERE c. id_address=a.id_address AND a. id_city=ci.id_city AND a. id_street=s.id_street.
INTO :fio:city_name:street_name:house_number:apartament_number.
DO.
suspend;
END!
SET TERM ;!!