Oracle: Bulk collect with DBMS_SQL defined array
Вопрос
It doesn't compile. What's wrong?
TYPE recEniFlussiHub IS RECORD
(
FLVO_ID dbms_sql.varchar2_table,
flh_id_messaggio dbms_sql.varchar2_table,
flh_integrazione_id dbms_sql.varchar2_table
);
TYPE taof_RowCurEniFlussiHub IS TABLE OF recEniFlussiHub;
curEniFlussiHub taof_RowCurEniFlussiHub;
SELECT null FLVO_ID,
c.flh_id_messaggio,
c.flh_integrazione_id,
BULK COLLECT INTO curEniFlussiHub
FROM ENI_FLUSSI_HUB c
WHERE c.flh_fornitura = P_FLH_FORNITURA
Решение
If you're going to use nested tables in a record you need to reference their elements in the BULK COLLECT clause. Something like this:
SELECT null FLVO_ID,
c.flh_id_messaggio,
c.flh_integrazione_id
BULK COLLECT INTO curEniFlussiHub.FLVO_ID
, curEniFlussiHub.flh_id_messaggio
, curEniFlussiHub.flh_integrazione_id
FROM ENI_FLUSSI_HUB c
WHERE c.flh_fornitura = P_FLH_FORNITURA
Also you just need to define the variable as an instance of the record: you don't need to have an additional table type i.e.
declare
recEniFlussiHub IS RECORD
(
FLVO_ID dbms_sql.varchar2_table,
flh_id_messaggio dbms_sql.varchar2_table,
flh_integrazione_id dbms_sql.varchar2_table
);
curEniFlussiHub recEniFlussiHub;
Другие советы
You have declared your record type incorrectly (I am assuming your columns flh_id_messaggio
and flh_integrazione_id
are not themselves nested tables).
If you are creating an associative array to hold the values selected, each field doesn't have to be a collection in itself (and you had an extra comma in your select statement after c.flh_integrazione_id
):
(I have assumed your flvo_id
is a VARCHAR2
as you tried to declare it as a VARCHAR2_TABLE
, if it is a NUMBER
then declare it as such in your record declaration).
TYPE receniflussihub IS RECORD(
flvo_id VARCHAR2,
flh_id_messaggio eni_flussi_hub.flh_id_messaggio%TYPE,
flh_integrazione_id eni_flussi_hub.flh_integrazione_id%TYPE
);
TYPE taof_rowcureniflussihub IS TABLE OF receniflussihub;
cureniflussihub taof_rowcureniflussihub;
SELECT NULL flvo_id,
c.flh_id_messaggio,
c.flh_integrazione_id
BULK COLLECT INTO cureniflussihub
FROM eni_flussi_hub C
WHERE c.flh_fornitura = p_flh_fornitura;
See Here
hope it helps...
EDIT:
From your comment, if you NEED to select into a record of collections (rather than a collection of records) then you do not need to declare the table TYPE, just a record of your decalred record type and select into that (don't forget that in your code you still had the extra comma after c.flh_integrazione_id
in your select statement):
Try this:
TYPE receniflussihub IS RECORD(
flvo_id dbms_sql.varchar2_table,
flh_id_messaggio dbms_sql.varchar2_table,
flh_integrazione_id dbms_sql.varchar2_table
);
receniflussihub_rec receniflussihub;
SELECT NULL flvo_id,
c.flh_id_messaggio,
c.flh_integrazione_id
BULK COLLECT INTO receniflussihub_rec.flvo_id,
receniflussihub_rec.flh_id_messaggio,
receniflussihub_rec.flh_integrazione_id
FROM eni_flussi_hub C
WHERE c.flh_fornitura = p_flh_fornitura;