Can dbms_lob.instr have end position?

I am extracting data from xml using dbms_lob utility and the pattern in XML is as below.
<Atag>
<Btag>
<Ctag>value</Ctag>
</Btag>
<Btag>
<Ctag>value</Ctag>
<Dtag>value</Dtag>
</Btag>
<Btag>
<Ctag>value</Ctag>
<Dtag>value</Dtag>
</Btag>
</Atag>
I want to extract all tag values inside <Btag> which will be nohting but Ctag and Dtag values. There can be any occurence of <Btag> in this xml. When I use like this,
val:=0;
<LOOP>
val1:=dbms_lob.instr(xml,'<Btag>',val);
val2:=dbms_lob.instr(xml,'</Btag>,val1);
val3:=case(val1) when 0 then 0 else dbms_lob.instr(xml,'<Ctag>,val1) end;
val4:=case(val3) when 0 then 0 else dbms_lob.instr(xml,'</Ctag>,val3) end;
val5:=case(val1) when 0 then 0 else dbms_lob.instr(xml,'<Dtag>,val1) end;
val6:=case(val5) when 0 then 0 else dbms_lob.instr(xml,'</Dtag>,val5) end;
In this case as <Dtag> doesnt exist inside the first occurence of <Btag>, so it gets the value from the next one which is not what I require. I want that to be set to null/zero so for which I want to search only between the first occurence of <Btag> and </Btag>.
I know it is confusing but can some one of you tell me how to go and find the values of <Ctag> and <Dtag> between each occurence of <Btag>. If they are not present I want the value to be set to zero/null.
Thanks in advance.

test@ora>
test@ora> @ver1
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
1 row selected.
test@ora>
test@ora>
test@ora> --
test@ora> with t as (
  2    select '<Atag>
  3  <Btag>
  4  <Ctag>Tootsie</Ctag>
  5  </Btag>
  6  <Btag>
  7  <Ctag>Psycho</Ctag>
  8  <Dtag>Casablanca</Dtag>
  9  </Btag>
10  <Btag>
11  <Ctag>Goodfellas</Ctag>
12  <Dtag>Chinatown</Dtag>
13  </Btag>
14  </Atag>' as x from dual)
15  --
16  select
17    x,
18    regexp_replace(modx,'(.*?)<Btag>(.*?)</Btag>.*$','\2',1,1) as txt1,
19    regexp_replace(modx,'(.*?)(<Btag>(.*?)</Btag>){1}<Btag>(.*?)</Btag>.*$','\4',1,1) as txt2,
20    regexp_replace(modx,'(.*?)(<Btag>(.*?)</Btag>){2}<Btag>(.*?)</Btag>.*$','\4',1,1) as txt3
21  from (
22    select regexp_replace(x,'(>).(<)','\1\2',1,0,'n') as modx, x from t
23  );
X                              TXT1                 TXT2                                        TXT3
<Atag>                         <Ctag>Tootsie</Ctag> <Ctag>Psycho</Ctag><Dtag>Casablanca</Dtag>  <Ctag>Goodfellas</Ctag><Dtag>Chinatown</Dtag>
<Btag>
<Ctag>Tootsie</Ctag>
</Btag>
<Btag>
<Ctag>Psycho</Ctag>
<Dtag>Casablanca</Dtag>
</Btag>
<Btag>
<Ctag>Goodfellas</Ctag>
<Dtag>Chinatown</Dtag>
</Btag>
</Atag>
1 row selected.
test@ora>
test@ora>
test@ora>@Keith - Regular expressions are from 10g upwards.
isotope

Similar Messages

  • Viewing event end positions

    In logic 6 when viewing smpte time ruler, you could see the exact end position of a region when you clicked on it... in 7, it shows the beginning position and the length of the region. How can I view the end position so that I can put two regions directly together when they aren't on a bar line?

    I think you are looking for the view as relative/absolute option, selectable from the event list. See also Shuffle L or No Overlap in the arrange

  • My itunes will not work at all. i have deleted and reinstalled in over ten times, i have ended the process, i have reinstalled quicktime i few times, i have deleted many folders. What else can i do? Please help:(

    My itunes will not work at all. i have deleted and reinstalled in over ten times, i have ended the process, i have reinstalled quicktime i few times, i have deleted many folders such as TEMP, itunes helper et What else can i do? Please help:(

    Now it sometimes keeps coming up and working but once i plug an ipod in it freezes my whole computer up and no i dont get any response from itunes at all

  • Will itunes 11 work with windows xp, I have ended up with this neqw version and it doesn't work , I can look at my library ,but not play and since synching my ipod it is now empty. Apple support is useless, they treat me like I'm on a Mac not a PC .

    will itunes 11 work with windows xp , I have ended up with this new version after accepting an update and now although I can view my library I can't play anything and since synching my ipod it is empty. Apple support can't seem to get it's head around the fact I'm on a PC keeps asking for an apple serial number, Help!!!

    Morning gedeye,
    Thanks for using Apple Support Communities.
    System Requirements
    Windows XP Service Pack 2 or later
    32-bit editions of Windows Vista or
    32-bit editions of Windows 7, and Windows 8
    For more information on this, take a look at this article:
    http://support.apple.com/kb/DL1614
    Best of luck,
    Mario

  • What can I do I got my iPad fixed at a different brand place but not apple and I have ended up a few weeks later with dust inside my screen is their anything apple can still do for me?

    What can I do I got my iPad fixed at a different brand place but not apple and I have ended up a few weeks later with dust inside my screen is their anything apple can still do for me?

    If another person or company serviced your iPad, your warranty has been voided.  Apple will do an out-of-warranty exchange.  Have you contacted the original service provider, and complained?

  • I have ended up with three accounts can they be merged to one

    I have ended up with three Apple accounts !!!!
    This is causing me nightmares , is it possible to have them merged into one ? And how?
    Many thanks

    At the present time Apple will not merge accounts (I have 3 myself).  The best thing to do is choose one for all your future purchasing.

  • Dbms_lob.instr searching backwards

    How can I use dbms_lob.instr to locate a string backward? such as "locate the position of the first 'xxx' before the current position (current pos == 88)?
    Thanks,
    Kevin

    SQL> set serveroutput on size 100000;
    SQL> DECLARE
      2    str   VARCHAR2(100) := 'aiiisalalkjsiiiksjjjslakjsljliiiljflakjfljsldiiiiiisfsljslkjdoooofdiiiiiisfsljslkjdoooof';
      3    pos   NUMBER;
      4    occur NUMBER := 1;
      5    subst VARCHAR2(3) := 'iii';
      6  BEGIN
      7    WHILE instr(str,
      8                subst,
      9                1,
    10                occur) > 0
    11    LOOP
    12      pos   := instr(str,
    13                     'iii',
    14                     1,
    15                     occur);
    16      occur := occur + 1;
    17    END LOOP;
    18    dbms_output.put_line('last occurrence of ' || subst ||
    19                         ' begins at position ' || pos);
    20  END;
    21  /
    last occurrence of iii begins at position 71
    PL/SQL procedure successfully completed
    Peter

  • Replace Filename text by start/end position?

    I could do this in php, but I know nothing of applescript. The main function I need is PHP's substr_replace, to rename files in a passed array, by start/end string positions, with passed text.
    Basically I'm looking for an applescript function to add to an Automator workflow, that will replace filenames with text, by character position. The applescript function would have 4 parameters, (files:Array, startPosition:int, endPosition:int, replaceWith:String). The first is an array of the files passed by Automator's "Get Selected Files" func, then the starting and ending positions for what is to be replaced, finally followed by the string to replace with.
    So something like,
    function renameFilenamesByPosition(files, startPos, endPos, replaceWith)
    for(i=0;i<count(files);i++)
    file = files;
    oldName = basename(file);
    newName = substr_replace(oldName, replaceWith, startPos, endPos);
    rename(oldFilename, newName);
    Any help in coming up with an applescript that I can do this, and be inserted into an Automator workflow, is MUCH APPRECIATED!! I often have files with number tags, that I'd like to have removed.

    I had a substring handler that converted fairly readily, but I was looking for something more general-purpose to put into an Automator action. Using an action is good for making the interface not quite so ugly, but there is a bit more to do to make sure it is robust enough to take whatever the other actions can throw at it. I finally decided on an action that trimmed an adjustable number of characters from the beginning or end, with an option to add a text variable - something that the existing rename doesn't do.
    As for my replacement handler, the main difference is that it uses the normal AppleScript index ranges, and the index items can also be text strings. There is also a bit more code to take care of stuff like negative or swapped indexes (yours definitely doesn't like that). It does work differently than the PHP function, which is probably not what you were looking for.
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px; height: 340px;
    color: #000000;
    background-color: #FFEE80;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    on run -- examples
    set TheText to "00012-myfile.jpeg"
    ReplaceTheText of TheText between 1 thru 6 by ""
    -- ReplaceTheText of TheText between "000" thru "-" by ""
    -- ReplaceTheText of TheText between 1 thru "-" by "xxxx"
    display dialog "\"" & the result & "\""
    end run
    to ReplaceTheText of SomeText between StartItem thru EndItem by ReplacingText
    replaces the text between the specified items with ReplacingText
    item searches are from left to right (beginning to end)
    if an item is not found, the replacement is from the beginning or end
    parameters - SomeText [text]: the text to modify
    StartItem [mixed]: the starting item or index (negative number is from the end)
    EndItem [mixed]: the ending item or index (negative number is from the end)
    ReplacingText [Text]: the replacement text
    returns [text]: the modified text, or the original text if error (index out of range, etc)
    set SomeText to SomeText as text
    set TextCount to (count SomeText)
    if class of StartItem is in {integer, real} then
    if StartItem is less than 0 then set StartItem to ((TextCount + 1) + StartItem) -- make positive index
    if (StartItem is greater than TextCount) or (StartItem is less than 1) then return SomeText -- out of range
    else
    set StartItem to offset of (StartItem as text) in SomeText
    if result is 0 then set StartItem to 1 -- the beginning
    end if
    if class of EndItem is in {integer, real} then
    if EndItem is less than 0 then set EndItem to ((TextCount + 1) + EndItem) -- make positive index
    if (EndItem is greater than TextCount) or (EndItem is less than 1) then return SomeText -- out of range
    else
    get (offset of (EndItem as text) in (text StartItem thru -1 of SomeText))
    if result is 0 then
    set EndItem to TextCount -- the end
    else
    set EndItem to StartItem + result + (count EndItem) - 2
    end if
    end if
    if StartItem is greater than EndItem then set {StartItem, EndItem} to {EndItem, StartItem} -- swap
    if StartItem is not 1 then
    set StartItem to text 1 thru (StartItem - 1) of SomeText
    else
    set StartItem to ""
    end if
    if EndItem is not TextCount then
    set EndItem to text (EndItem + 1) thru TextCount of SomeText
    else
    set EndItem to ""
    end if
    return StartItem & ReplacingText & EndItem
    end ReplaceTheText
    </pre>

  • Dbms_lob.instr question

    Hello,
    I have a field that holds CLOBs in the database. I have a textfield in which the user can enter a target string, then I hope to use dbms_lob.instr to search for the target string in CLOB. The code looks like: dbms_lob.instr(upper(I.COMMENTS),upper(nvl(:P26_SEARCH_NAME,I.COMMENTS))). If I replace the textfield value :P26_SEARCH_NAME with a string, the line works fine, but the current line returns the error
    ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: 6250, maximum: 4000) Can someone offer some help with a fix?

    Steven - Try v('P26_SEARCH_NAME') as a test to see if it makes any difference. If not, I can look at your test case if you put it on apex.oracle.com.
    Scott

  • DBMS_LOB.INSTR - Searching for a pattern

    Hi
    I have a program supporting several databases. F.ex SQL2000 and Oracle 8/9.
    The field in question, text, might contain a lot of characters. In Oracle, it's a CLOB,
    on SQL2000 it's a varchar. It is not possible for me to alter the database-structure in
    any ways at this moment. The database-schema is locked.
    My question is pretty simple, you have probably seen it before.
    In SQL2000 I can use this query:
    select count(*) from crm5.text where text like 'n%'.
    The result returned = 8.
    The same on Oracle will be somewhat like:
    select count(*) from crm5.text where dbms_lob.instr( text, 'n') > 0
    The result returned = 29.
    The databases has the same data.
    It seems to me that the dbms_lob.instr
    does a (case-sensitive) query like this:
    select count(*) from crm5.text where text like '%n%
    Is this the right assumption? How can I get the correct number
    of rows and do the search case-insensitive at the same time not
    killing the performance of the database? We use a pretty smart
    little thing on "normal" LIKE. But how can we do this with the
    CLOB?
    Regards,
    Ivar

    Found the solution.
    On Oracle 9, use LIKE as you want.
    On Oracle 8, use
    select count(*) from crm5.text
    where dbms_lob.instr( text, 'N') = 1
    or dbms_lob.instr( text, 'n') = 1.
    Ivar (same account, different mail-address).

  • Can a subform have multiple pages defined?

    Can a subform have multiple pages defined to it?
    I have a form and it is calling several subforms. These subforms have multiple pages defined.
    The end result is I'm getting these additional pages overlaying the first page.
    I've verifed my Same Page option, origins, etc.
    I've used subforms before with no problems, however, I have never had a subform with more than one page.

    Its possible, be sure that you have a proper set origin on the sub form call - that can sometimes throw other things off. You also need to be careful of set origins in the subforms since those are relative to the subform call - you should not be using anything with ABS positioning in the subform.
    Do everything as REL/MAX first then adjust your subform calls followed by the content within the subforms. Use the store origin if you need to get positioning in the main form to the subform calls instead of ABS if possible.

  • HT1212 I am unable to get our of a continuous cycle when trying to update or restore my iPad 2. Plug in to iTunes 12.0.1 (latest version). Click update, told can't update, have to restore. Restore fails with error 9. Any help appreciated.

    When I tried to update my iPad I got an error 9. Now, I am unable to access my iPad. It is in a continuous cycle when I try to update or restore the iPad 2. Plug in to iTunes 12.0.1 (latest version). Click update, told can't update, have to restore. Restore fails with error 9. Any help appreciated.
    Here's the cycle:
    I plug in my iPad when “cable to iTunes shows on iPad screen. It says "Your iPad can't be updated, you must restore it to factory settings." That bad enough news, but it gets worse.
    Click Restore
    Extracting software…
    Preparing iPad for restore
    Waiting for iPad…
    Verifying iPad restore with Apple…
    (empty bar under the Apple logo…does not show any activity)
    “The iPad “iPad” could not be restored. An unknown error occurred (9).”
    Notes: I just upgraded to OS X Yosemite 10.10.1 on my iMac (27-inch, Mid 2011) in the last week. It’s the first time I’m tried to backup/update my iPad since the iMac update.
    I swapped out the USB cable to a new cable and get the same results.
    I also unplugged all other USB devices from the iMac and security on my iPad and still get the same results.
    I find it strange that it shows no Serial number for my my iPad 2 when plugged in. It shows “Serial Number: n/a on the screen when it displays: “iPad Recovery Mode To update your iPad without erasing its contents, click Update. To restore your iPad to its factory settings, click Restore iPad.
    I prefer to update my iPad, but it displays “Your iPad can’t be updated, you must restore it to factory settings. If you previously backed up the iPad, click Restore Backup after the restore process completes.”
    It’s a continuous loop. I get the display on my iPad to plug in the iPad to iTunes, plug it in which ends after going through the above procedure saying an error occurred (9).
    So now I cannot use my iPad. When I turn it on I get the display showing me to plug it into iTunes with the cable. Since this is the only option I have I plug it in and the loop begins.
    Any advice would be appreciated.
    Thanks!

    Hello jaybearden,
    Thanks for the question. After reviewing your post, it sounds like you are not able to restore the iOS device since you get an error 9. I would recommend that you read this article, it may be able to help the issue.
    Resolve iOS update and restore errors - Apple Support
    Check your security software
    Related errors: 2, 4, 6, 9, 1000, 1611, 9006. Sometimes security software can prevent your device from communicating with either the Apple update server or with your device.
    Check your security software and settings to make sure that they aren't preventing a connection to the Apple servers.
    Thanks for using Apple Support Communities.
    Have a nice day,
    Mario

  • HT1918 How do I change country if I have a positive balance in my gift card?

    HI. I have an Apple account set up with a gift card when I was in the US. It has a low positive balance which I canot buy anyting with. I am now working in Asia and wish to change the country of my Apple account. However, it would not allow me to since I have a positive balance in my account. However, there is nothing I can buy with the balance amount left in my gift card. Can anyone help me resolve this bottleneck?
    Thanks,
    Ed

    You can try contacting iTunes support and ask if they can remove the balance from your account : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page

  • I have downloaded the tv shows Homeland and Dexter. They have ended up in different places. Dexter is where is "belongs" in my itunes library on my NAS drive. Homeland ended up on my hard drive in the itunes/music/tvshows directory. Anyone know why?

    Several months ago I bought and downloaded Homeland. Earlier this month I bought
    Dexter Season 7. They have ended up in different directories. My iTunes library is
    on a NAS drive and Dexter was stored there (where it belongs). For some reason,
    Homeland got saved to my Mac hard drive in the itunes/music/tvshows directory.
    This seems odd everything else I have downloaded, music, other tv shows, movies
    have been saved to the proper place. I haven't changed the path to my iTunes
    library in years.
    Now, iTunes has kept track of these two tv shows and I synced them both
    to my iPad. The only reason I know they are in different places
    is because my wife couldn't find them on the NAS drive.
    Mostly out of curiosity, I'd like to know why this happened and how to keep it from
    happening again.
    Oh, it's iTunes 11.0.3 running on a MacBook Pro with OS X 10.6.8.
    Thanks
    Bob

    I don't think it is easy to move part of a collection unless you don't care about the metadata such as date added, etc.  You can copy the files to the other drive, delete in iTunes the references to the copies still on your computer, then hold down the option key while dragging the files on the external to iTunes so it doesn't copy them back to your internal but just references them where they are.  You have to remember to do this each time.  Either that, or set preferences so iTunes does not automatically copy any file to your media folder when added but leaves them all where they land on your computer.  You can move them by hand around the computer, but not between drives.
    You could try Dougscript "Move Files To Folder" but I don't know if this enables iTunes to track items moved to a different drive.  iTunes doesn't really like using multiple drives.
    As for using Time Capsule, I have seen various takes on this.  I recall reading somebody saying it isn't a good idea to have a backup drive competing for dual purposes.  My take on it is, TC is a backup, period.  If you keep your movies on it and the TC drive dies, you lose your only copy of the movies.
    How often do you really watch these movies?  Yes, it is nice having them appear in iTunes, but unless you are watching them every day then it isn't a huge burden to have them on another drive.  Frankly, if I had iTunes movies I would probably make a whole different library for them and start from it with the external drive turned on when I was in a movie mood.

  • DBMS_LOB.instr (looking backwards for a string)

    I am trying to find the position of the first instance of a string ('><'), but staring at a position in the CLOB (not the start) and working backwards
    I thought this may work:
    num := DBMS_LOB.instr(L_CLOB, '><', 5000, -1);
    But unfortunately it returns nothing....
    Anyone able to help me?
    Thanks,

    I think you've got the parameters scrambled. Try this:
       num := DBMS_LOB.instr(L_CLOB, '><', -1, 1);Cheers, APC

Maybe you are looking for

  • Keeps reading out emails and sms

    Hi My phone noe reads out emails received ans SMS. It is only on the email application and not gmail I have reset application preferences Subsequently I have unticked email notifications in the email account setting and unticked notifications in the

  • Do you have any idea about EPC error? If yes,  Please come in.

    Hellow : please try to solve the EPC-INIT failed epc-95 error which arbitrarily raises any day, we can not say that it raises only during peak time.It comes arbitrarily any time any day. Initially it was use to come after every 5 to 10 days But now i

  • Data retrieval in I Photo 09

    Help! My daughter-in-law and I both have Mac Book Pro's, not the latest version, with OS 10.6.3 and I Photo 09. She has not backed up her laptop and it crashed, and won't boot up. I removed her internal hard drive and placed a spare I had and her Mac

  • How do i install adobe reader so I can read an e-mail

    how do I install adobe reader so I can read an e-mail with this attachment

  • OIM 9.1 Upgrade scripts

    Can anybody please let me know if OIM 9.1 upgrade scripts are available, if yes can you please point me to the same. Thanks