У меня есть таблица, в которой есть столбец varray, и varray создается из пользовательского типа. Я пытаюсь получить ссылки на строки varray, но я не могу это сделать. так что это в основном таблица (столбец, столбец, столбец, столбец varray некоторого типа [объект, объект, объект]), и я пытаюсь выбрать REF (объект).
Это домашняя работа, и у меня естьчтобы завершить это, используйте REF.
DB _ ****** - это мое имя пользователя и пароль, чтобы использовать типы, которые я создаю с моего сервера uni, мне нужно использовать свое имя пользователя.typename (я не знаюпочему)
Типы и таблицы:
------ORDER------
CREATE OR REPLACE TYPE in_plant_order AS OBJECT(
id NUMBER,
from_warehouse REF DB_******.WAREHOUSE,
to_warehouse REF DB_******.WAREHOUSE,
in_plant REF DB_******.PLANT,
createdAt DATE,
executedAt DATE,
--consturctor --could not figure out how to make custom constructor, it would be fantastic if you could explain me
MEMBER PROCEDURE execute(executionDate IN DATE),
MEMBER PROCEDURE set_from_warehouse(warehouse IN REF DB_******.WAREHOUSE),
MEMBER PROCEDURE set_to_warehouse(warehouse IN REF DB_******.WAREHOUSE),
MEMBER PROCEDURE set_in_plant(plant IN REF DB_******.PLANT)
);
--compiling everything does not work, but highliting them one by one and then compiling works for some reason
CREATE OR REPLACE TYPE BODY in_plant_order AS
MEMBER PROCEDURE execute(executionDate IN DATE) IS
BEGIN
self.executedAt := executionDate;
END execute;
MEMBER PROCEDURE set_from_warehouse(warehouse IN REF DB_******.WAREHOUSE) IS
BEGIN
self.from_warehouse := warehouse;
END set_from_warehouse;
MEMBER PROCEDURE set_to_warehouse(warehouse IN REF DB_******.WAREHOUSE) IS
BEGIN
self.from_warehouse := warehouse;
END set_to_warehouse;
MEMBER PROCEDURE set_in_plant(plant IN REF DB_******.PLANT) IS BEGIN
self.in_plant := plant;
END set_in_plant;
END;
CREATE TABLE orders OF in_plant_order(
id PRIMARY KEY,
from_warehouse NULL,
to_warehouse NULL,
in_plant NULL,
createdAt NOT NULL,
executedAt NULL
);
------PLANT-------
CREATE OR REPLACE TYPE warehouse_list AS VARRAY(3) of DB_******.warehouse;
CREATE OR REPLACE TYPE plant AS OBJECT (
id NUMBER,
location_id NUMBER,
size_ NUMBER(3, 2),
size_unit_id NUMBER,
warehouses WAREHOUSE_LIST
-- here i need a custom constructor to check if the warehouse has the correct location id
);
CREATE TABLE plants OF plant(
id PRIMARY KEY,
FOREIGN KEY (location_id) REFERENCES DB_******.possible_locations_enum(id),
location_id NOT NULL,
FOREIGN KEY (size_unit_id) REFERENCES DB_******.size_unit_enum(id),
size_unit_id NOT NULL
);
----WAREHOUSE-----
CREATE OR REPLACE TYPE warehouse AS OBJECT (
id NUMBER,
location_id NUMBER,
size_ FLOAT,
size_unit_id NUMBER,
shelves DB_******.shelf_list);
Процедура вставки в таблицу заказов (вот где у меня проблема):
create or replace PROCEDURE CREATE_ORDER
(
ORDER_ID IN NUMBER
, WH_FROM_ID IN NUMBER
, WH_TO_ID IN NUMBER
, PLANT_ID IN NUMBER
) AS
from_warehouse REF DB_********.warehouse;
to_warehouse REF DB_********.warehouse;
in_plant REF DB_********.plant;
in_plant_order DB_********.in_plant_order;
-- For this i am getting error PL/SQL: ORA-00904: "W"."WAREHOUSE": invalid --identifier ( it does not compile )
CURSOR c_warehouse_from IS
SELECT REF(w.warehouse)
FROM DB_********.plants plants, TABLE(plants.warehouses) w
WHERE w.id = wh_from_id
AND plants.id = plant_id;
-- This compiles but i get this error:
-- Connecting to the database FRTU.
-- ORA-22885: cannot get REF to a non-persistent object
-- ORA-06512: at "DB_******.CREATE_ORDER", line 14
-- ORA-06512: at "DB_******.CREATE_ORDER", line 33
-- ORA-06512: at line 12
-- Process exited.
-- Disconnecting from the database FRTU
CURSOR c_warehouse_to IS
SELECT REF(w)
FROM DB_********.plants plants, TABLE(plants.warehouses) w
WHERE w.id = wh_to_id
AND plants.id = plant_id;
CURSOR c_plant IS
SELECT REF(plants)
FROM DB_********.plants plants
WHERE plants.id = plant_id;
BEGIN
--create order
in_plant_order := DB_********.in_plant_order(order_id, NULL, NULL, NULL, SYSDATE, NULL);
--get warehouse_from ref
OPEN c_warehouse_from;
LOOP
FETCH c_warehouse_from INTO from_warehouse;
EXIT WHEN c_warehouse_from%NOTFOUND;
END LOOP;
CLOSE c_warehouse_from;
--get warehouse_to ref
OPEN c_warehouse_to;
LOOP
FETCH c_warehouse_to INTO to_warehouse;
EXIT WHEN c_warehouse_to%NOTFOUND;
END LOOP;
CLOSE c_warehouse_to;
--get plant reference
OPEN c_plant;
LOOP
FETCH c_plant INTO in_plant;
EXIT WHEN c_plant%NOTFOUND;
END LOOP;
CLOSE c_plant;
--set references in order
in_plant_order.set_from_warehouse(from_warehouse);
in_plant_order.set_to_warehouse(to_warehouse);
in_plant_order.set_in_plant(in_plant);
--insert to table
INSERT INTO DB_******.orders VALUES(in_plant_order);
END CREATE_ORDER;