How to insert rows from an xml file in a table

IM Using Oracle 11g, is show below error when I run...



declare
charString varchar2 (80);
finalStr varchar2 (400): = null;
whole rowsp;
v_FileHandle UTL_FILE. TYPE_DE_FICHIER;
Start
-the name of the table specified in our DTD
xmlgen.setRowsetTag ('Zipcodes');
-the name of the data set as shown in our DTD
xmlgen.setRowTag ('mappings');
-to get the result on the screen
dbms_output. Enable (100000);
-Open the XML document in read-only mode
v_FileHandle: = utl_file.fopen (TMP_DIR1,'XML_NEW_CITIES.) XML', 'r');
loop
BEGIN
UTL_FILE.get_line (v_FileHandle, charString);
exception
When no_data_found then
UTL_FILE.fclose (v_FileHandle);
"exit";
END;
dbms_output.put_line (charstring);
If finalStr is not null then
finalStr: = finalStr | charString;
on the other
finalStr: = charString.
end if;
end loop;
-for the insertion of XML data in the table
rowsp: = xmlgen.insertXML('SYS.) Codes POSTAL, finalStr);
dbms_output.put_line ('INSERT FACT' |) To_char (rowsp));
xmlgen.resetOptions;
end;
/




XML_NEW_CITIES. XML is

<? XML version = "1.0"? >
< zip codes >
< Record mappings = "4" >
CA < STATE_ABBREVIATION > < / STATE_ABBREVIATION >
< ZIPCODE > 94301 < / code >
< CITY > Palo Alto < / CITY >
< / maps >
< Record mappings = "5" >
< STATE_ABBREVIATION > CO < / STATE_ABBREVIATION >
< ZIPCODE > 80323 < / code >
< ZIP_CODE_EXTN > 9277 < / ZIP_CODE_EXTN >
Boulder < CITY > < / CITY >
< / maps >
< / zip codes >




Error report:
ORA-06550: line 8, column 3:
PLS-00201: identifier ' XMLGEN. SETROWSETTAG' must be declared
ORA-06550: line 8, column 3:
PL/SQL: Statement ignored
ORA-06550: line 10, column 3:
PLS-00201: identifier ' XMLGEN. SETROWTAG' must be declared
ORA-06550: line 10, column 3:
PL/SQL: Statement ignored
ORA-06550: line 14, column 34:
PLS-00201: identifier 'TMP_DIR1' must be declared.
ORA-06550: line 14, column 3:
PL/SQL: Statement ignored
ORA-06550: line 31, column 12:
PLS-00201: identifier ' XMLGEN. INSERTXML' must be declared
ORA-06550: line 31, column 3:
PL/SQL: Statement ignored
ORA-06550: line 33, column 3:
PLS-00201: identifier ' XMLGEN. RESETOPTIONS' must be reported
ORA-06550: line 33, column 3:
PL/SQL: Statement ignored
06550 00000 - "line %s, column % s:\n%s".
* Cause: Usually a PL/SQL compilation error

Published by: 898235 on November 20, 2011 23:02

OK, so you tried the XMLTable example, or wait for someone write at the bottom for you? :)

You must first create an object of directory Oracle pointing to the physical location of the file (must be somewhere on the db server or at a location that the db server can access on the network).
Then, create the procedure, in this case a simple INSERT SELECT:

SQL> create directory tmp_dir as 'c:\temp';

Directory created

SQL> create table zipcodes (
  2   state_abbreviation  varchar2(2),
  3   zipcode             varchar2(5),
  4   zip_code_extn       varchar2(10),
  5   city                varchar2(80)
  6  );

Table created

SQL> CREATE OR REPLACE PROCEDURE insertZipcodes (
  2    p_directory IN VARCHAR2
  3  , p_filename  IN VARCHAR2
  4  )
  5  IS
  6  BEGIN
  7
  8    INSERT INTO zipcodes (state_abbreviation, zipcode, zip_code_extn, city)
  9    SELECT state_abbreviation
 10         , zipcode
 11         , zip_code_extn
 12         , city
 13    FROM XMLTable('/Zipcodes/mappings'
 14           passing xmltype(bfilename(p_directory, p_filename), nls_charset_id('AL32UTF8'))
 15           columns state_abbreviation varchar2(2)  path 'STATE_ABBREVIATION'
 16                 , zipcode            varchar2(5)  path 'ZIPCODE'
 17                 , zip_code_extn      varchar2(10) path 'ZIP_CODE_EXTN'
 18                 , city               varchar2(80) path 'CITY'
 19         )
 20    ;
 21
 22  END;
 23  /

Procedure created

SQL> exec insertZipcodes('TMP_DIR', 'xml_new_cities.xml');

PL/SQL procedure successfully completed

SQL> commit;

Commit complete

SQL> select * from zipcodes;

STATE_ABBREVIATION ZIPCODE ZIP_CODE_EXTN CITY
------------------ ------- ------------- ---------------
CA                 94301                 Palo Alto
CO                 80323   9277          Boulder
 

Tags: Database

Similar Questions

  • How to insert data in the XML file?

    Hi guys,.

    How to insert information into an XML file. I tell you, I have a CFM file with some questions to the user

    When users submit this form within the form information is send in an XML file.

    How can insert this information in the XML file?

    When I don't have a DB?

    Thank you

    Kind regards

    Fabiano Magno Pechibella

    You must

    1. Read in the XML file
    2. Analyze the document in an XML (just one big struct) object
    3. Insert your XML code of the object where you need
    4. rewrite the XML file with your data now included

    You can Google 'ColdFusion working with XML' and find hundreds of items to help you. Here's a beginning tutorial to help you get started:

    Intermediate ColdFusion Tutorials - working with XML

  • How to display records from the xml file

    Hi all
    I created a region his area of research in reality
    with 5 elements and array of result area

    I want to search records based on the 5 elements and want to view output table


    I have the table name as hr_api_transactions, which contains many columns



    and also, this table contains a column
    name TRANSACTION_DOCUMENT of type CLOB()
    that files xml columns for each record
    I want to extract data from this xml file and want to display.

    Instance of the view - put the name of VO with which you are extracting data

    Discover the attribute and the attribute of file View - could see attribute by which you found the content of the file

    File name substitution - is not mandatory, let him

    The MIME type of the file: do not place anything, need to better manage programmatically through. Put the code in the below processRequest() method

    OADataBoundValueViewObject contentBoundValue = new OADataBoundValueViewObject(downloadBean,
      "FileContentType"); // here "downloadBean" is bean of message Download item
    downloadBean.setAttributeValue(FILE_CONTENT_TYPE, contentBoundValue);
    

    -Anand

  • How to insert text from the text file saved using the line number of the indesign document to point specific cursor?

    I use indesign for books of the brand. I need always insert quotes from some holy books. so I need to insert text using the verse number

    If you are looking for a way to automate where to insert the text? I really don't understand what you're trying to do.

  • How to insert images from the external file in the block of text using AppleScript

    the value myFile to null

    say application 'Finder '.

    the value ArtFolder to choose a folder with guest "Select the folder of Art: - > >".

    the value Chap1 to (get 1 folder from the folder ArtFolder)

    the value myFile to (Download file 1 to file (chap1 as alias))

    end say

    say application "Adobe InDesign CS5.5.

    set myDoc for the active document

    say myDoc

    set figureNode to XML element 1 of XML element 2 of XML element 1 of myDoc

    the value myFrame to do text block with properties {the geometric limits: {-13, 13, 3, -3}}

    tell text frame myFrame place (file (myFile))

    markup myFrame with figureNode

      end say

    end say


    ==========================================

    Condition: I want to Insert a picture of external & case content currently in the text frame... document node

    I am using above code but belowe the line does not...

    : - tell text frame myFrame place (file (myFile))

    Can someone help me please...

    Thank you

    Problem solved by code below :===>>

    say application "Adobe InDesign CS5.5.

    set myDoc to the active document

    myDoc say

    set figureNode to 1 to 2 to 1 of myDoc XML element XML element XML element

    set ArtFrame on to do text block with properties {geometric limits: {-13, 13, 3, -3}}-{y, w, h, x}

    Select ArtFrame

    Place (myArtFile as alias) on ArtFrame

    say fit myFrame given frame to content

    end say

    end say

  • How to extract information from the ovf file from a file of eggs by programming?

    How to extract information from the ovf file from a file of eggs by programming?

    Hello

    Please provide details:

    -On what OS you are programming (Linux, Windows,...)?

    -What programming or scripting language do you use?

    An EGG file is just a tarball of hard, .ovf and .mf files. The .ovf file is always the first. For example, on a Unix like operating system, this should be easy.

    For Windows, there are several options available to manage programmatically the tarballs. See for example http://www.codeproject.com/Articles/470999/tarlib-Windows-TAR-Library.

    And the ovf itself file is in XML format. For handling XML files are libraries available for literally every OS and programming language.

    Google is your friend.

    Andreas

  • Extract data from an xml file takes almost an hour to 2.5 M data.

    Hello

    Any help would be much appreciated. Extract data from an xml file takes almost an hour to 2.5 M. data is there a solution to this.

    WITH t AS
    (SELECT XMLTYPE (response) pass FROM dual
    )
    SELECT
    b.entity_id,
    c.INSTANCE_ID,
    d.attribute_id,
    d.DATA_TYPE,
    d.ATTRIBUTE_VALUE,
    d.outcome_style
    T,.
    XMLTABLE (XMLNamespaces ("http://schemas.xmlsoap.org/soap/envelope/" AS "SOAP-ENV"
    'http://oracle.com/determinations/server/10.3/rulebase/assess/types' AS 'type')
    , ' SOAP - ENV:Envelope / SOAP - ENV:Body / typ: assess-response/typ: global instance / typ:entity'
    PASSAGE t.col
    Path of COLUMNS entity_id VARCHAR2 (256) "@id".
    path XMLTYPE res_tmp2 'typ:instance') b
    xmltable (XMLNamespaces ("http://schemas.xmlsoap.org/soap/envelope/" AS "SOAP-ENV"
    'http://oracle.com/determinations/server/10.3/rulebase/assess/types' AS 'type')
    , "typ:instance".
    PASSAGE b.res_tmp2
    Path of COLUMNS instance_id VARCHAR2 (256) "@id".
    path XMLTYPE res_tmp3 'typ:attribute') c
    xmltable (XMLNamespaces ("http://schemas.xmlsoap.org/soap/envelope/" AS "SOAP-ENV"
    'http://oracle.com/determinations/server/10.3/rulebase/assess/types' AS 'type')
    , "typ:attribute".
    PASSAGE c.res_tmp3
    Path of VARCHAR2 (256) COLUMNS attribute_id '@id '.
    , data_type VARCHAR2 (256) path '@type '.
    , attribute_value VARCHAR2 (256) path '.'
    path VARCHAR2 (256) outcome_style '@inferred') d;

    Thank you
    Mhand

    OK, in this case the best option is to store the answer in a binary table of XMLType (may be a temporary table if you want to) and run the query from there:

    CREATE TABLE tmp_xml OF XMLType
    XMLType STORE AS SECUREFILE BINARY XML -- default storage in your version
    ;
    
    INSERT INTO tmp_xml VALUES(XMLType(response));
    
    SELECT b.entity_id,
           c.instance_id,
           d.attribute_id,
           d.data_type,
           d.attribute_value,
           d.outcome_style
    FROM tmp_xml t,
         XMLTABLE(
           XMLNamespaces('http://schemas.xmlsoap.org/soap/envelope/' AS "SOAP-ENV"
                        , 'http://oracle.com/determinations/server/10.3/rulebase/assess/types' AS "typ")
         , 'SOAP-ENV:Envelope/SOAP-ENV:Body/typ:assess-response/typ:global-instance/typ:entity'
           PASSING t.object_value
           COLUMNS
    ...
    
  • How to extract pages from a large file?

    How to extract pages from a large file?

    Free Adobe Acrobat Reader cannot extract pages. This would require the purchase of the full version of Adobe Acrobat.

  • How to insert multiple images into a file

    How to insert multiple images into a file

    Hi Mary,

    See this tutorial on adding images in Photoshop Mix and the grantor together: http://tv.adobe.com/watch/learn-photoshop-cc/combine-two-photos/

    Hope that helps,

    Concerning

  • Impossible to analyze data from an xml file

    I try to get the strings from an xml file:

    I tried the following:

    var url: URLRequest = new URLRequest ("blog.xml");

    var xml;
    var rss:URLLoader = new URLLoader();
    RSS. Load (URL);
    rss.addEventListener (Event.COMPLETE, readRss);

    function readRss(e:Event):void {}
    XML = XML (rss.data);
    txt_field. Text = XML. Entry [1]. Author.Name;

    }

    but no result. TypeError: Error #1010:...

    I tried tracing xml and worked well.

    The xml structure seems to be too complex

    var blogList:XMLList = xml.children (); Returns a xml structure more simple but always unsuccessfully in the analysis of the parts of xml as a "title" or "author."

    Any suggestions would be greatly appreciated.

    Thank you

    var url: URLRequest = new URLRequest ("blog.xml");

    var xml;
    var rss:URLLoader = new URLLoader();
    RSS. Load (URL);
    rss.addEventListener (Event.COMPLETE, readRss);

    function readRss(e:Event):void {}
    XML = XML (rss.data);

    var ns:Namespace=xml.namespace();
    txt_field. Text = XML... NS::name [0];

    }

  • How to migrate data from a source to multiple targets (tables)?

    How to migrate data from a source to multiple targets (tables)? Describe the General steps, please or point me to a tutorial

    Yes, a table in a mapping element can be source and target at the same time (i.e. a target can be reused as a source for the rest of the map on the right side of the table).

    Don't forget to check the order of loading (in the property map), to ensure that the reused as source is loaded before the final table target table.

    I tested it and it works. However, the documentation is not said in the link I gave you above:

    "Each element of data store that has entries but no exits in the logical diagram is considered a target."

    Usually, I tend not to do. I am in favour of a Divide and Conquer approach and try to have my mapping as simple as possible. It is easier to debug and maintain.

  • How can I transfer content from an XML file in a MS SQL database of the stored procedure using LabWindows/CVI SQL Toolkit?

    Hello

    I have a problem to transfer content to an XML file in a MS SQL database through a stored procedure data/fixed. I am able to transfer the content of the file using method...

    HSTMT = DBPrepareSQL (hdbc, EXEC usp_InsertReport " ... ");

    resCode = DBExecutePreparedSQL (hstmt);

    resCode = DBClosePreparedSQL (hstmt);

    ... but in this case, I am not able to read the return value of the stored procedure.

    I tried to follow the example of the stored procedure in the help documentation (DBPrepareSQL), but I miss a xml data type?

    No idea how to solve my problem?

    Cake of KR

    DianaS salvation,

    Thanks for your comments. During this time I found another way which fullfill my needs:

    resCode = DBSetAttributeDefault (hdbc, ATTR_DB_COMMAND_TYPE, DB_COMMAND_TEXT);

    sprintf (sz_SqlStatement, "DECLARE @TESTID INT EXEC @TESTID = usp_InsertReport ' SELECT 'RetVal' %s = @TESTID", sz_Buffer ");
    HSTMT = DBActivateSQL (hdbc, sz_SqlStatement);

    While ((resCode = DBFetchNext (hstmt)) == DB_SUCCESS)

    {

    / * Enter values in the record. */

    resCode = DBGetColInt (hstmt, 1, & s32_TestId);
    }

    resCode = DBDeactivateSQL (hstmt);

    sz_Buffer is the content of the XML file.

    Cake of KR

  • How to insert image from mysql into the table using php and create the checkbox in the table?

    How can I insert image from mysql into the table using php and create the checkbox for each data as a vote? Here is my code...

    WELCOME

    connect_error) {die ("connection failed:".)} $conn-> connect_error); } $sql = "SELECT no, Calon, ID, of course, the Image OF THE candidates." $result = $conn-> Query; If ($resultat-> num_rows > 0) {echo ' '; export data of each line while ($row = $result-> fetch_assoc()) {"echo"}}
    NO Candidate INFO Vote
    " . $row ["no"]. "-" . $row ["Calon"]. "
    -" . $row ['ID']. "
    -" . $row ['class']. "
    "; } ECHO ' ' ;} else {echo '0 results' ;} $conn-> close();?} >

    hope someone can help me because I am a newbie in this program... need to finish this project... Thank you.

    If you have saved the file name in the database, it's pretty simple.

    echo '' . $row['description'] . '';
    

    Is the same for the box:

    echo '';
    

    If you have saved the image file in the database, it is much more complicated. I recommend you store only the file name in the database.

  • Insert xml files into the table

    Hi all

    How to create an application, which allows me to download an xml file and insert the file into a table, looking something like what makes the apex, with 'data-> data-> Data Load XML Workshop'.

    I tried to create it using this link https://forums.Oracle.com/message/9170494 # 9170494

    but when loading the file and send it (current executing the "sp") sends the error "ORA-22285: file for FILEOPEN operation or non-existent directory.

    I could slightly auxiliary

    concerning

    This idea is troubling for me.

    The XML file DOES NOT CHANGE.  This is the goal.  You have a DTD/XST that defines where in the XML hierarchy, a data element is and (so) how to access it.  With this information, you can hardcode things.

    Therefore, you should have no reason for that functionality 'map the data column in the table column"of the data loader since all mappings will be always the same.

    As a simple INSERT... The SELECT statement can (and should) be used.

    (use the FUSION if you update / insert data).

    I copy + paste some of my code in a procedure that I use.

    You will need to replace the parameter name (p_filename) with the value of appropriate link (name of item)

      declare
        l_XML XMLType;
      begin
        /* get file from APEX WWV_FLOW_FILES */
        begin
            select XMLType( blob_content, 1 ) -- 1 means that the file is USACII encoded. this may need to be changed.
              into l_XML
            from wwv_flow_files where name = p_filename; -- replace this with the appropriate ITEM NAME
        exception
          when no_data_found then
            raise_application_error( -20001, 'not in FLOW: ''' || p_filename || '''' );
        end;
    
        /* you'll need to figure this one out */
        INSERT INTO T (...)
        SELECT ..
        FROM  XMLTable( '/'
    pasing l_xml
                columns
                       PATH  -- repeat for each "column" you want to extract
            );
    
       delete from wwv_flow_files where name=p_filename;
      end;
    
  • How do you use the config.xml file to determine which version of an application, a user will download?

    I have two APKs for the same application and I implemented the config.XML of lower version number working for all screen sizes.  The config.XML for the higher version number is set up for only the scresns large and extra-large.  Here's the code from the config.xml file.

    Version 1

    < media screens android: anyDensity = "true" android: Center = 'true '.
    Android: smallScreens = "true".
    Android: normalScreens = 'true '.
    Android: largeScreens = "true".
    Android: xlargeScreens = "true" / >

    Version 2

    < media screens android: anyDensity = "true" android: Center = 'true '.
    Android: smallScreens = "false".
    Android: normalScreens = "false".
    Android: largeScreens = "true".
    Android: xlargeScreens = "true" / >

    When I try to download the app on Google game, only the top version is available, regardless of the size of the unit.  When I asked Google game why this was not behave as expected, they said that the file manifest for both applications is the same.  Here is the code, they shot in the manifest after having used PhoneGap Build.

    < media screens android: anyDensity = "true" android: smallScreens = "true" android: normalScreens = "true" android: largeScreens = "true" android: Center = "true" android: xlargeScreens = "true" / >

    Can someone explain why PhoneGap Build is not using the settings I set in the config.xml file?  And how to fix this?

    The tag is not a valid tag in the config.xml file. This is probably why you see the same tag in two, as the build service is ignorant.

    As to how solve you this problem. Currently, you can not, but the next version of android-cordova will include the ability to add a tag which you will be able to use like this:

Maybe you are looking for