Sign Up

Sign Up to our social questions and Answers to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In


Have an account? Sign In Now

Sign In

Login to our social questions & Answers to ask questions, answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Sorry, you do not have permission to add post.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Oraask Logo Oraask Logo
Sign InSign Up

Oraask

  • Write
    • Add A New Post
    • Ask A Question

Oraask Navigation

Search
Ask A Question

Mobile menu

Close
  • Categories
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Dev Tools
    • Online Compiler
    • Base64 Converter
  • Wiki
    • SQL Tutorials
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials
Home/ Questions/Q 82596

Oraask Latest Questions

Question
abhishekvv91
  • 0
  • 0
abhishekvv91Explorer
Asked: September 2, 20232023-09-02T04:57:16+03:00 2023-09-02T04:57:16+03:00In: PL/SQL

Export query result to Oracle Server

  • 0
  • 0

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

Create Table: Below holds the sample data for table

TableDetail

Code:

declare
  cursor c_fdoc is SELECT id, 
        XMLElement("SDPSyncMessage", 
                  XMLAttributes('http://www.emeter.com/energyip/syncinterface/v8' AS "xmlns"),
                  XMLElement("header",
                    XMLElement("verb",'SDPSync'),
                    XMLElement("noun",'SDPSync'),
                    XMLElement("revision",'1'),
                    XMLElement("dateTime",SYSTIMESTAMP),
                    XMLElement("source",'CIS'),
                    XMLForest(loc_badge "messageID"),
                    XMLElement("syncMode",'sync'),
                    XMLElement("optimizationLevel",'Optimistic') ),                  
                
                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   ASSETS_COPY 
  WHERE FILE_CREATED IS NULL;
begin
  for i in c_fdoc
  loop
    if (i.FXML is not null) then
            --NEED TO UPDATE BELOW LINE OF CODE TO GENERATE XML DIRECTLY TO ORACLE SERVER DIRECTORY
                insert into xml_gen (fxdoc) values (i.FXML);
                update ASSETS_COPY set FILE_CREATED = 'YES' where id = i.id;
                update ASSETS_COPY set FILE_DT = systimestamp where id = i.id;                
            ELSE
                update ASSETS_COPY set FILE_CREATED = 'NO' where id = i.id;
        end if;
  end loop;
end; 

 

 

 

export xmloraclepl/sqlproceduresql developer
0
  • 0 0 Answers
  • 15 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    Related Questions

    • What is the difference between Implicit and Explicit Cursor in Oracle
    • How many triggers can I create on a single table in Oracle Database
    • How many types of collections are there in Oracle
    • Can we extend Varray in Oracle PL/SQL
    • What is an array in PL/SQL

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    Sidebar

    Adv 250x250

    Explore

    • Categories
    • Questions
      • New Questions
      • Trending Questions
      • Must read Questions
      • Hot Questions
    • Dev Tools
      • Online Compiler
      • Base64 Converter
    • Wiki
      • SQL Tutorials
      • Java Tutorials
      • Python Tutorials
      • JavaScript Tutorials

    Footer

    Oraask

    About

    Oraask is a website for developers and software engineers who want to learn new skills, share their knowledge, and solve their coding problems. Oraask provides free content on various programming languages and topics, such as Oracle, Python, Java, etc. Oraask also allows users to ask questions and get answers from other members of the community.

    About Us

    • About Us
    • Contact Us

    Legal Stuff

    • Privacy Policy
    • Terms & Conditions

    Follow

    Oraask is licensed under CC BY-NC-SA 4.0Oraask CopyrightOraask CopyrightOraask CopyrightOraask Copyright

    © 2019 Oraask. All Rights Reserved
    With Love by Oraask.

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.