Технология Клиент-Сервер 1999'3 |
|||||||
|
Эта процедура на PL/SQL переносит значения из PHONE_LIST VARRAY в CUSTOMER_TAB во временную реляционную таблицу CT.
Листинг 4: Эта процедура на PL/SQL переносит значения из PHONE_LIST VARRAY в CUSTOMER_TAB во временную реляционную таблицу CT. create or replace procedure get_phone_list as type tt_t is table of varchar2(20) index by binary_integer; tt tt_t; pl phone_list_t; cursor c is select c.custno, c.phone_list from customer_tab c; /* Инициализируем таблицу */ procedure init_tab is begin for i in 1..10 loop tt(i) := null; end loop; end; /* Главная процедура */ begin for crec in c loop pl := crec.phone_list; init_tab; for i in 1..pl.count LOOP tt(i) := pl(i); end loop; update ct set -- Update the table p1 = tt(1), p2 = tt(2), p3 = tt(3), p4 = tt(4), p5 = tt(5), p6 = tt(6), p7 = tt(7), p8 = tt(8), p9 = tt(9), p10 = tt(10) where cno = crec.custno; end loop; commit; end; / show errors
Этот код воссоздает тип CUSTOMER-INFO-T и таблицу CUSTOMER-TAB с изменениями после уничтожения исходных типа и таблицы.
CREATE OR REPLACE TYPE CUSTOMER_INFO_T AS OBJECT ( custno NUMBER, custname VARCHAR2(200), address address_t, phone_list phone_list_t, sales_mgr varchar2(30), --------- Новая колонка MAP MEMBER FUNCTION cust_order RETURN INTEGER, PRAGMA RESTRICT_REFERENCES (cust_order, WNDS, WNPS, RNPS, RNDS) ) / CREATE OR REPLACE TYPE BODY CUSTOMER_INFO_T AS MAP MEMBER FUNCTION cust_order RETURN INTEGER IS BEGIN RETURN 99999 - custno ; END; END; / CREATE TABLE CUSTOMER_TAB OF CUSTOMER_INFO_T (custno PRIMARY KEY) /
Этот код заполняет вложенную таблицу PO_LINE_TAB, используя данные из временной таблицы PC.
declare lit line_item_list_t; li_rec line_item_t; stkrec stock_info_t; cursor c1 is select p.pono, line_item_list lil from purchase_tab p; begin for c1rec in c1 LOOP -- Insert records into the nested table -- insert into the( select x.line_item_list from purchase_tab x where x.pono = c1rec.pono) select y.lino, null, y.quantity, y.discount from pc y where y.pono = c1rec.pono; commit; end loop; for c1rec in c1 LOOP -- Update the stock Reference -- lit := c1rec.lil; for i in 1..lit.count LOOP li_rec := lit(i); dbms_output.put_line(li_rec.lineitemno); begin select ref(s) into li_rec.stockref from stock_tab s, pc where pc.lino = li_rec.lineitemno and s.stockno = pc.stockno and pc.pono = c1rec.pono; exception when no_data_found then dbms_output.put_line('NOT FOUND'); end; select deref(li_rec.stockref) into stkrec from dual; dbms_output.put_line('Stock is ' || stkrec.stockno); lit(i) := li_rec; end loop; update purchase_tab p set line_item_list = lit where p.pono = c1rec.pono; end loop; commit; end; /
Copyright © 1994-2016 ООО "К-Пресс"