我试图以表格式返回一个XML,但我仍然无法返回它,就好像它是select * from TABLE ( cast( gcg_tempdata_mft () as GCG_TableMFT ) );
或类似的东西一样,我不知道我的函数做错了什么,但在保存更改时,我收到了这个错误。我基于这个Function return sys_refcursor call from sql with specific columns
type GCG_RecordMFT is record(
INVENTORY_ORGANIZATION_NAME VARCHAR2(200 CHAR),
SCHEDULED_DATE VARCHAR2(80 CHAR),--timestamp,
WORK_ORDER VARCHAR2(80 CHAR),
OPERATIONS_CODE VARCHAR2(80 char),
OPERATION_NAME VARCHAR2(80 CHAR),
MATERIAL_NAME VARCHAR2(80 CHAR),
MATERIAL_DESCRIPTION VARCHAR2(150 CHAR),
PLANNED_USAGE_QUANTITY VARCHAR2(80 CHAR),--NUMBER(15,10),
PRIMARY_UOMNAME VARCHAR2(30 CHAR)
);
type GCG_TableMFT is table of GCG_RecordMFT;
功能代码:
function gcg_tempdata_mft (
p_user in varchar2,
p_password in varchar2,
p_InventoryOrganizationName in varchar2,
p_WorkOrder in varchar2,
p_ScheduledStartDate in varchar2,
p_ScheduledEndDate in varchar2
)
return GCG_TableMFT is
l_envelope CLOB;
l_response XMLTYPE;
l_report_clob clob;
l_report_blob blob;
l_xml xmltype;
l_ref_cur sys_refcursor;
l_rec GCG_TableMFT := GCG_TableMFT();
BEGIN
FOR i in (SELECT
INVENTORY_ORGANIZATION_NAME,
--cast(to_timestamp_tz(SCHEDULED_DATE,'YYYY-MM-DD"T"HH24:MI:SS.FFTZH:TZM') as timestamp) SCHEDULED_DATE,
SCHEDULED_DATE,
WORK_ORDER,
OPERATIONS_CODE,
OPERATION_NAME,
MATERIAL_NAME,
MATERIAL_DESCRIPTION,
PLANNED_USAGE_QUANTITY,
PRIMARY_UOMNAME
FROM (
select
XMLTYPE( l_report_blob,3) as xml
from dual
) xml_table,
xmltable(
'/DATA_DS/MFT'
passing xml_table.xml
columns
INVENTORY_ORGANIZATION_NAME VARCHAR2(200 CHAR) PATH '/MFT/INVENTORYORGANIZATIONNAME',
SCHEDULED_DATE VARCHAR2(80 CHAR) PATH '/MFT/SCHEDULEDDATE',
WORK_ORDER VARCHAR2(80 CHAR) PATH '/MFT/WORKORDER',
OPERATIONS_CODE VARCHAR2(80) PATH '/MFT/CODE',
OPERATION_NAME VARCHAR2(80 CHAR) PATH '/MFT/OPERATION',
MATERIAL_NAME VARCHAR2(80 CHAR) PATH '/MFT/MATERIALNAME',
MATERIAL_DESCRIPTION VARCHAR2(150 CHAR) PATH '/MFT/MATERIALDESCRIPTION',
PLANNED_USAGE_QUANTITY VARCHAR2(80 CHAR) PATH '/MFT/REQUIREDQUANTITY',
PRIMARY_UOMNAME VARCHAR2(30 CHAR) PATH '/MFT/PRIMARYUOMCODE'
))
loop
dbms_output.put_line(i.INVENTORY_ORGANIZATION_NAME);
l_rec.extend;
l_rec(i) := GCG_RecordMFT(
'SILENCIO',
'2022-07-25T12:35:00.000+00:00',
'M_ES40',
'AC_DU_EXP',
'OPERATION_NAME',
'fas',
'fafafs',
'sadadad',
'asdasdada'
-- i.INVENTORY_ORGANIZATION_NAME,
-- i.SCHEDULED_DATE,
-- i.WORK_ORDER,
-- i.OPERATIONS_CODE,
-- i.OPERATION_NAME,
-- i.MATERIAL_NAME,
-- i.MATERIAL_DESCRIPTION,
-- i.PLANNED_USAGE_QUANTITY,
-- i.PRIMARY_UOMNAME
);
END LOOP;
RETURN l_rec;
END gcg_tempdata_mft;
谢谢你们,问候你们。
1条答案
按热度按时间xtfmy6hx1#
RECORD
是仅限PL/SQL的数据类型。如果要返回在SQL语句中使用的集合,则需要使用OBJECT
(在SQL作用域中定义)数据类型,就像链接的问题所做的那样。然后,您可以通过将其设置为
PIPELINED
和其他一些次要更改来简化该函数:然后:
产出:
库存组织名称|Scheduled_Date|WORK_ORDER|OPERATIONS_CODE|OPERATION_NAME|MATERIAL_NAME|MATERIAL_DESCRIPTION|PLANUED_USAGE_QUANTITY|PRIMARY_UOMNAME
-|
Aaa|2022-07-25T12:35:00.000+00:00|M_ES40|AC_DU_EXP|OPERATION_NAME|fas|fafs|sadadad|asdasdada
fiddle