在发布问题之前,我试图找到与我相似的东西,但没有成功。
这里我拥有一切,类型的创建,表的创建,值的插入,过程的创建,除了我尝试调用过程的部分之外,一切都有效。
CREATE OR REPLACE TYPE array_serial AS TABLE OF VARCHAR(20)
CREATE OR REPLACE TYPE ITEM_DATA AS OBJECT
(
ITEM_CODE VARCHAR2 (50),
serial array_serial,
notes VARCHAR2 (1000)
);
CREATE OR REPLACE TYPE obj_good_array AS VARRAY(500) OF ITEM_DATA;
CREATE TABLE item_data_table
(
item_id NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
item_data obj_good_array
);
插入数据
DECLARE
item_data_obj obj_good_array;
BEGIN
item_data_obj := obj_good_array();
item_data_obj.extend;
item_data_obj(1) := ITEM_DATA(
'ABC123',
array_serial('Serial1', 'Serial2', 'Serial3'),
'Sample notes for item ABC123'
);
INSERT INTO item_data_table (item_data) VALUES (item_data_obj);
COMMIT;
END;
/
DECLARE
item_data_obj obj_good_array;
BEGIN
item_data_obj := obj_good_array();
item_data_obj.extend;
item_data_obj(1) := ITEM_DATA(
'XYZ789',
array_serial('Serial4', 'Serial5', 'Serial6'),
'Sample notes for item XYZ789'
);
INSERT INTO item_data_table (item_data) VALUES (item_data_obj);
COMMIT;
END;
/
select * from item_data_table;
CREATE OR REPLACE PROCEDURE process_items (
p_item_list IN obj_good_array
) AS
BEGIN
FOR i IN 1..p_item_list.COUNT LOOP
DBMS_OUTPUT.PUT_LINE('Item Code: ' || p_item_list(i).ITEM_CODE);
DBMS_OUTPUT.PUT_LINE('Notes: ' || p_item_list(i).notes);
FOR j IN 1..p_item_list(i).serial.COUNT LOOP
DBMS_OUTPUT.PUT_LINE('Serial ' || j || ': ' || p_item_list(i).serial(j));
END LOOP;
END LOOP;
END process_items;
/
以这种方式调用该过程是行不通的。这是错误:
ORA-02315: 默认构造函数的参数数量不正确
代码:
set serveroutput on
DECLARE
item_data_variable obj_good_array; -- Declare the obj_good_array variable
BEGIN
SELECT CAST(MULTISET(
SELECT item_data
FROM item_data_table
) AS obj_good_array) INTO item_data_variable FROM dual;
process_items(item_data_variable);
END;
/
这应该是输出:
Item Code: ABC123
Notes: Sample notes for item ABC123
Serial 1: Serial1
Serial 2: Serial2
Serial 3: Serial3
Item Code: XYZ789
Notes: Sample notes for item XYZ789
Serial 1: Serial4
Serial 2: Serial5
Serial 3: Serial6
您能帮忙一下如何调用这个存储过程吗?
先感谢您
首先,您没有嵌套表,您有一个
VARRAY
.其次,您可以使用:
哪个输出:
小提琴