Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Export query result to Oracle Server

User_FJUPFSep 2 2023

I have written PL/SQL code to store XML into cursor. Refer the below code

Requirement: As of line at line 83, I am inserting the result into another table (XML_GEN) as XMLTYPE datatype. Line: insert into xml_gen (fxdoc) values (i.FXML); But I don't want to that, I need this result to get stored as file on Oracle DB Server. (each row to be stored as a file .xml). File should be exported based on ID column, so that file name is unique (ID.xml) I have searched on google, but I am unable to do it.

Can someone provide suggestion or guidance, how I can achieve it.

I have attached the file TableDetail.xls (export of data) and PL/SQL Code I am using.

Below code and table are available at below link as well https://drive.google.com/drive/folders/1d7VPlY0ooR8jr3Xrvd1la1BiEIwFrEhv?usp=drive_link

Code:

CREATE OR REPLACE PROCEDURE EXPORT (Dir VARCHAR2, File_Name VARCHAR2) is
    CURSOR c_fdoc is SELECT  
        XMLElement("SDPSyncMessage", 
                    XMLElement("payload",
                    XMLElement("servicePoint",
                      XMLForest(loc_badge "mRID"),
                      XMLElement("type",'ServiceDeliveryPoint'),
                      XMLElement("serviceType",'Electric'),
                      XMLElement("className",'Electric'),
                      XMLElement("status",'Active'),
                      XMLElement("premise",
                      XMLForest(phx_loc "mRID")),
                      XMLElement("servicePointStatus",
                      XMLElement("powerStatus",'Y'),
                        CASE WHEN TO_DATE IS NOT NULL THEN XMLElement("loadStatus",'N')
                        ELSE XMLElement("loadStatus",'Y')END,
                      XMLElement("billingHoldStatus",'N'))),
                
                  XMLElement("device",
                      XMLForest(phx_badge "mRID", modeltype "model"),
                      XMLElement("className",'Electric'),
                      XMLElement("status",'Installed'),
                      XMLElement("type",'Meter'),
                      XMLElement("deviceFunctionType",'N'),
                      XMLElement("parameter",
                        XMLElement("name",'Configuration ID'),
                        XMLForest(CONFIGURATIONID "value", EFFECTIVE_DATE "startDate")),
                      XMLElement("parameter",
                        XMLElement("name",'Program ID'),
                        XMLForest(PROGRAMID "value", EFFECTIVE_DATE  "startDate"))),
                 
                  XMLElement("device",
                      XMLForest(phx_badge "mRID", modeltype "commTechnology"),
                      XMLElement("type",'CommModule'),
                      XMLElement("deviceFunctionType",'Y'),
                      XMLElement("className",'Electric'),
                      XMLElement("status",'Active')),
                
                  XMLElement("serviceLocation",
                      XMLForest(phx_loc "mRID"),
                      XMLElement("stateOrProvince",'Arizona'),
                      XMLElement("timeZone",'America/Phoenix'),
                      XMLElement("country",'United States'),
                      XMLElement("status",'Active')),
                 
                  XMLElement("servicePointDeviceAssociation",
                    XMLForest(INSTALL_DATE "startDate"),
                        CASE WHEN TO_DATE IS NOT NULL THEN XMLForest(TO_DATE "endDate") END,
                    XMLElement("servicePointId",
                        XMLForest(loc_badge "mRID")),
                    XMLElement("deviceId",
                        XMLForest(phx_badge "mRID")),
                        XMLElement("relType",'SDP-METER')),
                  
                  XMLElement("deviceFunctionAssociation",
                    XMLForest(INSTALL_DATE "startDate"),
                        CASE WHEN TO_DATE IS NOT NULL THEN XMLForest(TO_DATE "endDate")END,
                    XMLElement("deviceId",
                        XMLForest(phx_badge "mRID")),
                    XMLElement("comFunctionId",
                        XMLForest(phx_badge "mRID")),
                    XMLElement("relType",'COMMUNICATION-METER'))
              ))  AS "FXML" 
  FROM   X_EISERVER_ASSETS_COPY 
  WHERE FILE_CREATED IS NULL;
File UTL_FILE.FILE_TYPE;

BEGIN
  File := UTL_FILE.FOPEN(UPPER(Dir), File_Name,'w',32767);
  for i in c_fdoc
  loop
    if (i.FXML is not null) then
              UTL_FILE.PUT_LINE(File, i.FXML);
    end if;
  end loop;
  UTL_FILE.FCLOSE(File);
 
END EXPORT;

TableDetail.xlsx

This post has been answered by Barbara Boehmer on Sep 2 2023
Jump to Answer
Comments
Post Details
Added on Sep 2 2023
2 comments
102 views