Selecting the first 4000 characters from a tag in an xml file

Oracle Enterprise Edition 11.1.0.7 64 bit (Jan 2012 CPU applied)
Windows 2003 64 bit
We have an XML file with the following sample format.
<?xml version="1.0"?>
<HR>
<EMP>
<FNAME>JOHN</FNAME>
<LNAME>DOE</LNAME>
<COMMENT>Comment with less than 4000 characters</COMMENT>
</EMP>
<EMP>
<FNAME>JANE</FNAME>
<LNAME>DOE</LNAME>
<COMMENT>Comment with more than 4000 characters</COMMENT>
</EMP>
</HR>
The query below
(full disclosure: which I took from odie_63's response in Creating External Table using Xml Dataset - how to include null values? and added the CURSOR_SHARING_EXACT hint on the top)
works when the contents of the <Comment> tag are smaller than 4000 characters. If it is more than 4000 I get
ORA-01706: user function result value was too large
SELECT /*+ CURSOR_SHARING_EXACT */
FROM XMLTable(
'/HR/EMP'
passing xmltype( bfilename('DATA_PUMP_DIR','emp.xml'), nls_charset_id('CHAR_CS') )
columns
first_name varchar2(30) path 'FNAME',
last_name varchar2(30) path 'LNAME',
comments varchar2(4000) path 'COMMENT'
I found another query where someone was doing a substring (I think to get only the first 4000 characters from the tag) here.
http://www.ibm.com/developerworks/forums/thread.jspa?messageID=14638197 (See OP's post)
TERMINATION_DATE VARCHAR(32) path 'TerminateDate/substring(text(), 1, 32)',
So I updated my query to be
SELECT /*+ CURSOR_SHARING_EXACT */
FROM XMLTable(
'/HR/EMP'
passing xmltype( bfilename('DATA_PUMP_DIR','emp.xml'), nls_charset_id('CHAR_CS') )
columns
first_name varchar2(30) path 'FNAME',
last_name varchar2(30) path 'LNAME',
comments varchar2(4000) path 'COMMENT/substring(text(),1,4000)'
The query runs without an error when the <comment> tag has 4000 or less characters but still errors out with it is more than 4000.
I found an alternative method to do the SUBSTRING here in Herald ten Dam's reponse in Re: A view over XML that is not 1:1
code varchar2(30) path 'substring(code,1,3)',
so I tried this:
SELECT /*+ CURSOR_SHARING_EXACT */
FROM XMLTable(
'/HR/EMP'
passing xmltype( bfilename('DATA_PUMP_DIR','emp.xml'), nls_charset_id('CHAR_CS') )
columns
first_name varchar2(30) path 'FNAME',
last_name varchar2(30) path 'LNAME',
comments varchar2(4000) path 'substring(COMMENT,1,4000)'
but that doesn't work either.
How can I extract the first 4000 characters of the <COMMENT> tag so that the query doesn't fail.
We are not using any other XMLDB features at this time. This is the first we've started looking into using Oracle built in XML features, so we might not have setup something that other's might know to specifically setup to start using the XML features in Oracle 11.1
Thanks in advance,
Wally

walls99 wrote:
This is regardless of the COMMENTS tag being 4000 characters or more and the same with the ideas from Odie.
WallyNo idea if it is an issue with your version. I don't have your version to test but following works for me. Does this simple test work?
SQL> select * from v$version ;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL> set define off
SQL> select dbms_xmlgen.convert(xmlserialize(content xmltype('<brand>Ben &amp; Jerry</brand>') as clob), 1) from dual ;
DBMS_XMLGEN.CONVERT(XMLSERIALIZE(CONTENTXMLTYPE('<BRAND>BEN&AMP;JERRY</BRAND>')A
<brand>Ben & Jerry</brand>

Similar Messages

  • How to get the first 3 characters from the previous month?

    Hi,
    I need to get in a View Column only the first 3 characters of the previous month of data from the bellow query.
    SELECT ID, Department, Capital_Project_Number, 
    Capital_Site_Number, 
    Funding_Source, Milestone, 
    Account, Year, Month, Data
    FROM  Table
    Where Month = DATENAME(Month, DATEADD(Month, - 1, GETDATE())) and (Year = YEAR(GETDATE()));
    Go

     Left(DATENAME(Month, DATEADD(Month, - 1, GETDATE())),3)
    --Or
     convert( varchar(3), DATEADD(Month, - 1, GETDATE()),100)

  • Printing the First 14 Characters of Every Line in a Text File

    My text file looks like the following:
    1111097116274, H0101C58F8110C005, 1, 16:48:03
    1111097116274, H0100058F8110C006, 2, 16:48:10
    1111097116274, H00F0458F8110C006, 3, 16:48:12I want my java program to print the first 14 characters of every line. Here's what I have:
    import java.awt.*;
    import javax.swing.JOptionPane;
    import java.io.*;
    public class Read {
         public static void main( String args[] ) {
        try {
            BufferedReader in = new BufferedReader(new FileReader("aFile.txt"));
            String line;;
            /*String tagid;*/
            while ((line = in.readLine()) != null) {
                 char[] tagid = line.toCharArray();
                 line.getChars(0, 14, tagid, 0); 
                 System.out.println(tagid);
            in.close();
        } catch (IOException e) {
             JOptionPane.showMessageDialog( null, "Error" );
             System.exit(0);
         Instead of printing the first 14 characters of every line to output, it prints the whole text file.
    Any ideas of what's wrong?
    Thanks.

    Well, that's the thing with a highly tuned, precision engine like your mind, JosAH. Adding a little alchohol to the fuel mix provides a performance boost, but as the alcohol/fuel ration increases, the performance improvement peaks and then degrades, until the performance is actually reduced. Now, I understand that in the case of the magic Grolsch, this performance curve is shifted farther to the right (graphed with Grolsch count as the independent variable, and performance improvement as the dependent variable), but it still occurs.
    I recommend nitrous oxide. You may need to get your piston heads hardened, though.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Select only first 10 chars from the field in a table while writlng a selec

    hi experts,
    In a table  one field contains a value of above 10 characters (ex 10 or 15 or 20 characters).But i want to select
    only first 10 characters from this field while writing a select statement.
    This logic should be included in select statement.
    please gime immediate solution.
    My question is understood.

    Hi,
    Try this one
    data : begin of itab occurs 0,
            maktx(10) type c,
    end of itab.
    " though the length of MAKTX is 40 you only get 10 chars
    select maktx from makt into table itab up to 10 rows.
    if sy-subrc is initial.
    endif.
    " Suppose the field name of table you want to select is MAKTX then declare
    " Your internal table in the above manner, it will automatically fit into it and will get 10 Chars only
    " Instead of burding the select query / DB interface use the above.
    Cheerz
    Ram

  • How can I obtain the first 10 charcter from field and the last 4 characters

    Hi
       I need to obtaind the first 10 characters from field AWKEY from BSEG table, and the last 4 characters, how can I obtain certains position from field??
        Example:
      AWKEY field from BSEG can be for example :
    51000573112002
       This mean that you can obtain separately:
    5100057311 - BELNR (field)
    2002- GJAHR (field)
        As you can see, the first 10 positions are BELNR and the last 4 positions are GJAHR.
         But sometimes you find in old rows:
    5100057312US502001
         This mean that you can get from this field:
    10 positions for BELNR : 5100057312
    4 positions for BUKRS or WERKS : US50  - in this case, I don´t know if its is BURKS or WERKS...for this reason only I want to take only the first 10 positions and the last 4 position to compare.
    4 posiition for GJAHR: 2001
       I rewards all the answers.
       Thank you.
    Alicia

    Hi, thank you for yours answers
    Let me try to explain more what I need to do:
    I have a Internal Table that I create with EKBE table:
      SELECT  MANDT EBELN EBELP GJAHR BELNR BEWTP BUDAT
              MENGE WRBTR WAERS WERKS SHKZG DMBTR
              ZEKKN VGABE BUZEI
        INTO CORRESPONDING FIELDS OF TABLE LIST_EKBE
        FROM EKBE
          WHERE EBELN IN R_EBELN
            AND BEWTP IN ('E','Q','R').
    The result is all the rows that have this conditions..then with this internal table I need to looking for each BELNR in BKPF table, but sometimes you can find the row compare EKBE-BELNR with BKPF-BELNR...but in many cases, you don´t find the row in this way, you need to add EKBE-BELNR and EKBE-GJAHR and looking for in BKPF with field AWKEY..
    For this reason I CONCATENATE in this way:
    LOOP AT LIST_EKBE.
        V_BELNR = LIST_EKBE-BELNR.
        V_GJAHR = LIST_EKBE-GJAHR.
        CONCATENATE V_BELNR V_GJAHR  INTO V_AWKEY.
        SELECT SINGLE MANDT BUKRS BELNR GJAHR AWKEY
        INTO (BKPF-MANDT, BKPF-BUKRS, BKPF-BELNR,
             BKPF-GJAHR, BKPF-AWKEY)
        FROM BKPF
        WHERE AWKEY = V_AWKEY.
    ENDLOOP.
      But I saw that sometimes you don´t find the record in BKPF because the AWKEY is formed with BELNRBUKRSGJAHR....or may be with BELNRWERKSGJAHR ...I don´t know if is BUKRS or WERKS the second field...for this reason I try only read in the select..if its posible the first 10 postions and the last 4 positions...but Im not sure if its possible..
      The reason for that I looking for the BELNR field in BKPF field for AWKEY its because sometimes de BELNR in BKPF its different..example:
    In EKBE you have:
    BELNR: 5105618260
    GJAHR: 2006
    If you looking for in BKPF you don´t find sometimes exactly the field BELNR : 5105618260.. then you need try looking for the AWKEY field then you need to add BELNR+GJAHR..example:
    BKPF:
    BELNR: 5105611111
    GJAHR: 2006
    AWKEY: 51056182602006
    But in other cases... I found that in AWKEY exist for example:
    BELNR: 5105611111
    GJAHR: 2006
    AWKEY: 5105618260US502006
    In the last case I supouse that I can divide in:
    AWKEY: 5105618260-US50-2006 ... but I don´t know what its the field that have the information US50..may be is BUKRS or may be its WERKS
    May be some people know what its exactly this field and can help me..
    With the solution that some of yours give me..I don´t know the how I can make the select? and if its posible make in this way
    Thank you a lot

  • Selecting the first file from a group of opened files in Photoshop

    Hi, I've been digitizing microfiche with 200 or so pages photographed onto one image file, laid out in a grid pattern. I've been using actions in Photoshop to cut out one page, create a new file in Photoshop from that page, then return to the first, master file and do it again with the next page in the series. So when it is complete I have each individual page as an individual image file which I then save with a batch process. I've been doing this for a while and have managed to make it work but I always run into the problem, when creating this action again, of getting Photoshop to select that first master file each time instead of selecting just the previous file. I know I can get it to select the previous file, or the previous file -1, -2, -3, etc. I've somehow been able to get this to work in the past by creating an action that selects a large enough group back, like previous file -19 or something, and through some bug or sheer luck it has worked and will always select that first file. But it doesn't always work and it always takes some frustration to luck into it when it does. Now I can't seem to get it to work at all. Is there a straightforward way I can simply tell it to select the first file everytime? If not, does anyone know how or why the method I used previously sometimes works and sometimes doesn't, and how I can make it work again? I'm using PS CS5 in Windows 7. Thanks!

    Just put this code on a file and put that 'namedfile.jsx' inside the scripts folder on photoshop.
    Open or re-open photoshop to load the script and create an action linked to a shortcut selected by you and save this script going to File>Scripts>namedfile.jsx
    It is just to press the shortcut key and the active image go back to the image opened before.
    When it is the first one it runs the script the same but it remains there.
    Here is the script:
    // Go back to the previous opened image
    #target photoshop
    // Go back to the previous opened image (not the previous viewed) . If it is the first, it remain there.
    if(documents.length>0) {
        var thisIndexImage = getActiveDocumentIndex();
        var theDocs = app.documents;
        if ( thisIndexImage != 0 ) {
            var flatAnterior = theDocs[thisIndexImage - 1];
            } else {
            var flatAnterior = theDocs[0];
        app.activeDocument = flatAnterior;
    } else {
        alert ("You must have opened images to run this script.")
    // Get the active document number - the number of opening order
    function getActiveDocumentIndex(){
         var ref = new ActionReference();
         ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
         return desc = executeActionGet(ref).getInteger(stringIDToTypeID('itemIndex'))-1;
    If you want to go directly to the first of all the images (in opening order) it is simpler:
    Just create this script:
    var first = app.documents[0];
    app.activeDocument = flatAnterior;

  • How to delete first few characters from all the elements of an array of strings

    hi
    I have a 2-dimensional array of strings length 104. I have to delete first 6 characters from all the elements of array and then change the strings to int. how to do it?? plz help

    Attached you can find the screenshot showing how to do so.
    Bye!
    Licia
    Attachments:
    array.jpg ‏14 KB

  • TS3274 When viewing pick lists from different web sites my iPad2 selects the first choice on the list and loads it without allowing me to pick my option; is there a way to change this default?

    When viewing pick lists from different web sites my iPad 2 (safari) selects the first choice on the list and loads it without allowing me to pick my option; is there a way to change this default?

    With your playhead over the clip in the timeline and that V track's 'track selector' as the only one active...hit the 'f' key.
    This will load the original clip into the viewer at the matching point of the frame in the timeline.
    K

  • How can I pull info into a report using just the first two characters of that field?

    I am trying to pull a total cost based upon locations in a particular area(s). Can I get the formula to just do this based on the first two characters of that field?
    Here is what I have so far:
    if {PACKED.LOCATIONS.NEXT OPERATION} = ["xx"] THEN {Job.Total_Price}
    Packed locations is a table I'm pulling from and the column I want just the first two digits is the the Next operation. Once this meets the "xx" (whatever location) then give me the total price from the Job table.
    This works for one or two orders, but then blows up when I do 10 or so.

    Hi Steve, assuming that Next Operation is a string field...
    Create a new formula and place it in the field where you see the {Job.Total_Price} field (Detail or Group depending on your report) with the formula:
    whileprintingrecords;
    global numbervar TotalValue;
    if len({? Replace me}) <= len({PACKED.LOCATIONS.NEXT OPERATION}) then(
    if left(ucase({PACKED.LOCATIONS.NEXT OPERATION}),len({? Replace me})) = ucase({? Replace me}) then
    TotalValue := TotalValue + {Job.Total_Price}
    TotalValue;
    You can go ahead and suppress that field.
    Create a new formula to place where you want to view the summary using the formula:
    whileprintingrecords;
    global numbervar TotalValue;
    This method allows for a higher degree of flexibility and you can search for the first x characters of that field instead of only the first 2 characters

  • Remove first 30 characters from get-content

    hello
    i have a one liner which reads a file and filter it based on my criteria. the output is very lengthy. i need to remove the first 35 characters of that in order to have a clear result with no unwanted information
    Get-Content D:\netlogon.bak | Select-String -Pattern "CHI-*"
    after I filter based on pattern, i want to remove the first 35 charaters. how can i do this?
    thank you

    Get-ContentD:\netlogon.bak
    | Select-String
    -Pattern
    "CHI-*" | %{$_.SubString(35,$_.Length-35)}
    \_(ツ)_/

  • How to select the first record?

    Hi,
    Could anyone tell me how to select the first record of every
    group?
    ex, I want to find out every customer their first purcaseDate.
    CustomerID PurcaseDate Region
    A00000001 2001/01/01 AA
    A00000001 2001/02/02 AA
    A00000002 2001/03/01 AC
    A00000002 2001/05/07 AC
    A00000003 2001/03/05 DD
    result:
    A00000001 2001/01/01 AA
    A00000002 2001/03/01 AC
    A00000003 2001/03/05 DD
    Thanks

    Vincent,
    You could do it as Carl suggested, with a couple of
    corrections.  You would need to include the CustomNo column in
    the order by clause of your cursor.  You would also need to add
    a where clause to your update statement, otherwise everywhere
    Region in the table would be updated with the same value of the
    last CustomNo in the cursor, regardless of the CustomNo in the
    table.  See corrected code below:
    DECLARE
      CURSOR     cust
      IS
      SELECT     DISTINCT CustomNo, Region, Purchase_Date
      FROM       my_table
      ORDER BY   CustomNo, Purchase_Date, Region;
      c_customer VARCHAR2 (9) := '...';
      c_region   VARCHAR2 (2) := '..';
      cntr       NUMBER := 0;
    BEGIN
      FOR x IN cust
      LOOP
        IF x.CustomNo != c_customer
        THEN
          c_customer := x.CustomNo;
          c_region := x.Region;
        ELSE
          UPDATE my_table
          SET    Region = c_region
          WHERE  CustomNo = c_customer;
          cntr := cntr + 1;
          IF cntr = 25
          THEN
            COMMIT;
            cntr := 0;
          END IF;
        END IF;
      END LOOP;
      COMMIT;
    EXCEPTION
      WHEN OTHERS THEN 
        NULL;
    END;
    Another option is that you could just use one update statement,
    like this:
    UPDATE my_table a
    SET    Region =
           (SELECT DISTINCT Region
            FROM   my_table b
            WHERE  (CustomNo, Purchase_Date) IN
                   (SELECT   CustomNo, MIN (Purchase_Date)
                    FROM     my_table
                    GROUP BY CustomNo)
            AND    a.CustomNo = b.CustomNo)
    Barbara

  • Thunderbird is removing the first 5 characters of the username, causing an error.

    I seem to be having some issues trying to set up the email for a website I recently started on GoDaddy through Thunderbird.
    I am using Thunderbird 24.4.0 on Windows 8
    Server Settings:
    email address: [email protected]
    pop3: pop.secureserver.net / 995 / SSL / normal password
    smtp: smtpout.secureserver.net / 465 / SSL / normal password
    username: [email protected]
    I have repeatedly verified the username and password are correct as are the server settings. I have tried changing the security settings, ports and password transmission to all available choices to no avail.
    After entering the settings and clicking "Done" I get the following message: "Configuration could not be verified -- is the username or password wrong?" They aren't.
    Clicking "Advanced Config" takes me out of the creation window into the server settings option window. The email shows up in the sidebar now as an available email and the server setting options window shows all the info as I entered it and it is all correct.
    Here is where I spotted something that may be the issue but I have no idea why it's happening or how to fix it: When I click "Get Mail", I get an error message: "Sending of password did not succeed. Mail server pop.secureserver.net responded: [email protected] not found in the auth database"
    However, the username is wrong: it is missing the first 5 characters. For example, if I use "[email protected]" the error message says "[email protected] not found in the auth database". If I use "[email protected]", the error message says "@xxx.com not found in the auth database". (These were all different attempts with different emails: I wasn't just randomly changing the username.)
    Any clues on how to fix this so I can get the email working?
    Thanks in advance.

    Have you tried with email scanning disabled in your anti virus? Your using SSL and anti virus companies are using hacking techniques to hack into the encrypted data stream to scan for a virus. For years they warn us Hackers break in and corrupt your data. Well now the A/V vendors are doing it.

  • HT201269 I'm trying to set up my new iPhone using iCloud - I entered my apple ID and password and selected the backup to restore from but the next page asks me to enter a password for a DIFFERENT apple ID

    I'm trying to set up my new iPhone using iCloud - I entered my apple ID and password and selected the backup to restore from but the next page asks me to enter a password for a DIFFERENT apple ID

    What different Apple ID? Yours? Your friends? Your dogs... ? I think we are going to need more information. You're probably best setting up the phone as a new phone and restoring from iCloud later on.

  • Selecting The First Row Of h:dataTable after getting new DataModel f

    Hi Friends
    If any one knows how to select first row of a dataTable on change of a DataModel it is representing please give the reply

    I haven't understood the answer of UlrichCech
    I am not using IRDA for my development purpose.
    and abt your reply ..
    I have already tried tht way but the problem is that
    whenever I selects different row page gets postback and selects
    the first row again and there is no way to trap posback event in JSF
    like ASP.NET
    I think my answer is some where related to DataModelListener..

  • Windows Explorer - How to select the first item once we open the explorer?

    Hi,
    In Windows Explorer - How to select the first item once we open the explorer using keyboard shortcut. I typically use downward arrow, it goes to the 2nd item in the list, then I again have to use upward arrow to go up.
    Is there a shortcut to select the first item in the list using keyboard? This is not specific to Windows 7, it has been the behavior even in previous Windows OS versions.
    Thanks,
    Mallik

    Opening a Microsoft Ticket is probably your best option. Unfortunately the change will not happen immediately and it will require multiple users to send in a ticket. I hope this ends up being resolved though.
    Good luck Mallik
    Also, don't forget to mark the post as answered so that it does not show up as unanswered to help others who search the forums.
    Agreed, MS wont change it easily. :)
    Arnav Sharma | http://arnavsharma.net/ Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading
    the thread.

Maybe you are looking for

  • How to connect the macbook with thunderbolt display 27" to TV with RGB port?

    Hi, I have the following equipments in hands: 1. Macbook PRO 15 inch with 1 thunderbolt port, OS is Mavericks 10.9.2 2. Apple Thunderbolt display 27" identical to this : http://www.apple.com/displays/ 3. A Samsung TV with RGB port, & HDMI port. I wan

  • Error while running tcode wwy1 in r/3

    Hello, I am beginner for Internet Transaction Server (ITS). while running tcode wwy1 in SAP R/3, ther is an ABAP runtime error as below. An exception occurred. This exception is dealt with in more detail below         . The exception, which is assign

  • IWork '08 & iLife '08 on iBook G3

    Well, the title says it, but I didn't do anything, bought it from the store, installer worked even though its "unsupported".

  • LotusXSL and WLS 5.1...

    Is there anyone using the IBMs LotusXSL 1.0.1 package (Xalan.jar and           Xeres.jar) with WLS 5.1 SP3?           Because I can't make it work...           Here's what I want to do my JSP:           - Take XML stream           - Take XSL stream (

  • Will not allow deauthorization

    My PC will not allow transfer of purchases from my iphone and says I have 5 devices already authorized. But my account does not show 5 devices authorized and I cannot deauthorize any/all of my devices (PC, laptop, ipod and iphone). Help!