Extracting particular pattern

Hello Gurus,
Need your help again. I have a field of variable length which has values with multiple '|' delimiters and followed by a 14 digit number. I need to code for a query or function that will escape the first two '|' pipes and after the second pipe get the last 8 digits of the 14 digit number.
For ex - the field x_id =
test|example|00050044175462|00050044177545|00050044177542
abc|xyz|00123244139190
The o/p will be -
test|example|44175462|44177545|44177542
abc|xyz|44139190
Please advice. I appreciate any help. Thank you in advance

Hi,
Oracle 9 was released in 2001, and superseded in 2003. Always mention your version, especially if it's 9 years old.
Things like this are very difficult to do in pure SQL without regular expressions. I suggest you write a PL/SQL function.
If you really must do it in pure SQL:
WITH     got_pipe_cnt     AS
     SELECT     x_id
     ,     LENGTH (x_id) - LENGTH (REPLACE (x_id, '|'))     AS pipe_cnt     -- Assumes x_id is not all pipes
     FROM     table_x
,     cntr     AS
     SELECT     LEVEL     AS n
     FROM     (  SELECT  MAX (pipe_cnt)     AS max_pipe_cnt
             FROM        got_pipe_cnt
     CONNECT BY     LEVEL <= 1 + max_pipe_cnt
,     got_pos          AS
     SELECT     pc.x_id
     ,     pc.pipe_cnt
     ,     c.n
     ,     INSTR ( '|' || pc.x_id
                , '|'
                , 1
                , c.n
                )          AS start_pos
     ,     INSTR ( pc.x_id || '|'
                , '|'
                , 1
                , c.n
                )          AS end_pos
     FROM    got_pipe_cnt     pc
     JOIN     cntr          c     ON     c.n     <= 1 + pc.pipe_cnt
,     split_data     AS
     SELECT     x_id
     ,     pipe_cnt
     ,     n
     ,     SUBSTR ( x_id
                 , start_pos
                 , end_pos - start_pos
                 )               AS txt
     FROM    got_pos
SELECT       SUBSTR ( SYS_CONNECT_BY_PATH ( CASE
                              WHEN  LEVEL > 2
                              AND   TRANSLATE ( txt
                                              , '123456789'
                                        , '000000000'
                                        ) = '00000000000000'
                              THEN  SUBSTR (txt, 7)
                              ELSE  txt
                          END
                                , '|'
             , 2
           )     AS new_id
FROM       split_data
WHERE       LEVEL     > pipe_cnt
START WITH     n     = 1
CONNECT BY     n     = PRIOR n + 1
     AND     x_id     = PRIOR x_id          -- Assumes x_id is unique
;I don't have an Oracle 9 database available, so even if you had posted some useable sample data, I couldn't test it.

Similar Messages

  • How to search for a particular pattern in a string

    Hi,

    Hi ,
    How to search for a particular pattern in a string?
    I heard about java.util.regex; and used it in my jsp program.
    Program I used:
    <% page import="java.util.regex"%>
    <% boolean b=Pattern.matches("hello world","hello");
    out.println(b);%>
    I run this program using netbeans and am getting the following error message.
    "Cannot find the symbol : class regex"
    "Cannot find the symbol : variable Pattern "
    How to correct the error?

  • Editing particular pattern in an input text in ADF

    Hi,
    I have a requirement in ADF like the user should be able to editable only a particular pattern.
    Example:
    Name: Chandramohan
    Hobbies: My hobbies are {}, {}, {}
    In the above hobbies filed( say textarea or input text), the user should be able to replace only the {} with some text, not other text like 'My hobbies are'.
    Kindly suggest some ideas.
    Edited by: 875628 on Jul 27, 2011 11:29 PM
    Edited by: 875628 on Jul 27, 2011 11:30 PM

    Hi,
    Have you tried this with javascript?
    Here is a basic solution (which takes care only for the first {} - you can enhance it to fulfill your requirement).
                    <af:inputText label="Label 1" id="it1" value="My hobbies are {}, {}, {}" clientComponent="true" >
                    <af:clientListener type="keyPress" method="validateValue" />
                    </af:inputText>
                    <af:resource type="javascript">
                    function validateValue(evt){
                        var inputTxt=document.getElementById('it1::content');
                        var startPos = inputTxt.value.indexOf("{");
                        var endPos = inputTxt.value.indexOf("}");
                        var cursorPos = inputTxt.selectionStart;
                        if (cursorPos &lt; startPos || cursorPos > endPos) {
                        alert("Cannot Edit");
                        evt.cancel();
                    </af:resource>-Arun

  • Can I extract particular bits of information from an iTunes backup?

    Is there a way to extract particular information about stuff like contacts, notes or reminders from a backup in iTunes?

    Not by design, try this Google search and explore the options before making a purchase.
    tt2

  • Extract and Pattern Maker filters in Photoshop CS4?

    What happened to the Extract and Pattern Maker filters in Photoshop CS4? Are they gone or placed somewhere else?

    Hi guys,
    I might be an old fart! But I love extract... Are there any other way to make transparent pixels on the edges on the object you want cut out?
    Personally I cry at night for the semi-loss of Extract! This means that Adobe wont improve it any more and with time the filter might be all gone!?!
    cheers
    Peter

  • How to Extract particular field from a string ( Mapping)

    how to exteract the particular field from the given string:
    ProcessEmp this element has a below string subfields.
    <ProcessEmp>&lt;?xml version="1.0" encoding="utf-8" standalone="no"?&gt;
    &lt;Employee PersonnelNumber="11111" FirstName="String" MiddleName="String" LastName="String" Department="String" Group="" SapUserID="10flname" EmailAddress="[email protected]" DefaultPassword="*" Status="Success" /&gt;</ProcessEmp>
    how to extract only PersonalNumber, department, EmailAddress from above ProcessEmp into 3 diff fields.
    Thanks
    dhanush.

    Hi,
    You are receiving XML message within a field. To access a particular field from that XML message, you could create a User Defined Function, as suggested by many already.
    You could write UDF using some of the String operation functions. This could include following:
    1. If you need to access field Employee PersonnelNumber, you could get last index of that within string using function lastIndexOf(String str). Pass string "Employee PersonnelNumber="" for this function.
    2. This function would return an index of rightmost occurance of this string.
    3. after this you could get the index of next occurance of ", as the value of field is within quotes. You could use function indexOf(int ch, int fromIndex) for getting the same. You would pass Character as " and index as the one received by previous function.
    4. Now you have index for starting and ending point of value string for desired field.
    5. After this you could use substring(int beginIndex, int endIndex) function by passing first and second index values to retrieve the needed string, which contains value of field.
    Hope this would be helful.
    Thanks,
    Bhavish
    Reward points if comments found helpful:-)

  • A programme that will extract particular records from a file

    Let's assume that there is a text file containing arround 50 records in the following format:
    ABCDEFGH:AB:12345:-09876:567:876
    The file to be read by the programme consist of a sequence of records each of which is split into fields using separator characters just like as we have in the Unix. The command line arguments should be given to execute the programme
    The most important part of the programme is that the condition for extracting a particular record from that file will be that specified fields shall contain a particular string of characters.
    The command line arguments to be given are:
    -tx This flag specifies the field separator character "x"
    -<num> This flag introduces a match requirement for field "num". Fields are numbered starting at 1. This flag may be followed by further flags and then by the string to look for.
    -f Fold case. I.e. string matching is not case sensitive.
    -t Transposition match. A match is recorded even if the strings differ provided the difference consists of just 2 characters transposed so that, for example: "compiler and complier" will be recorded as a match.
    -d A differ match. A match is recorded even if the two strings differ by one letter. For example: "gest and rest" will be recorded as a match.
    The file to be processed will be specified in the final command line argument.
    If match requirements are specified for more than one field the implication is that all fields specified must separately satisfy their individual match requirements. If any fields referred to in the match requirements are missing from a particular record then the record will not satisfy the overall match requirements.

    And your question is??

  • How to extract particular print layout design in B1?

    Hi,
    I had design some of the marketing documents using print layout design.  How do I extract the particulars marketing documents?
    Currently I'm copy the whole table and replace it.
    Please advice.
    Thank you.
    Regards,
    Foong Yee

    Hi Foong Yee,
    SAP Note 600813 might help a bit (copying LD templates) The direct link:
    https://websmp101.sap-ag.de/~sapidb/012006153200000183292003E.ITF
    ---- Replace *SOURCE* with the source database name.
    ---- Replace *DEST* with the destination database name.
    insert into [*DEST*].[dbo].[RDOC]
    select [*SOURCE*].[dbo].[RDOC].*
    from
    [*SOURCE*].[dbo].[RDOC],[*DEST*].[dbo].[cinf],[*SOURCE*].[dbo].[cinf]
    where [*DEST*].[dbo].[cinf].[lawsset]=[*SOURCE*].[dbo].[cinf].[lawsset]and [*DEST*].[dbo].[cinf].[version]=[*SOURCE*].[dbo].[cinf].[version] and [*SOURCE*].[dbo].[RDOC].[Doccode]NOT IN (SELECT Doccode from [*DEST*].[dbo].[RDOC])
    insert into [*DEST*].[dbo].[RITM]
    select [*SOURCE*].[dbo].[RITM].*
    from [*SOURCE*].[dbo].[RITM],[*DEST*].[dbo].[cinf],[*SOURCE*].[dbo].[cinf] where [*SOURCE*].[dbo].[RITM].[Doccode] NOT IN (select Doccode from [*DEST*].[dbo].[RITM])AND [*SOURCE*].[dbo].[RITM].[Doccode]IN (SELECT Doccode from [*DEST*].[dbo].[RDOC])
    Hope it helps!
    Rowdy

  • Mail Adaptor : How to extract particular Mail from the mail server?

    Hi @,
    I have a requirement where I need to extract all the new mails with a aprticular Subject line to the XI and then forward it to the receiveing system.My problem is that the actual payload is situated in the Mail attachment which I will use in my scenarion but the filtering has to happen based upon the mail subject.
    I am not able to deal as the filtering and usage of payload are diffrent,need help in this regard
    Regards

    Hi
    As far as i know Mail adapter wouldnt be able to do anything of this sort.It will read all mails which it has never read before.You should use the mail Server for this.
    Thanks

  • How do I search for lines with a particular pattern and delete them when a match occurs

    How do I search for lines with a particular patter and delete them when a match occurs? For example delete lines containing SUB_NAME = "?" where ? is any string. 

    How do I search for lines with a particular patter and delete them when a match occurs? For example delete lines containing SUB_NAME = "?" where ? is any string. 
    Lines in what? And what language are you using to develop with?
    Are the lines in a text file? A RichTextBox? A TextBox? Some other control? A List(Of String)?
    Is there some expectation by you that by providing what you wrote in your question post that the knowledge in your mind about what you are thinking about will mysteriously emanate to anybody reading your post so all of the sudden your knowledge will
    become their knowledge and they will be able to provide you with an answer as they will suddenly understand what you are trying to do? Because that's probably impossible. Most people try providing enough information in a question so anybody, even stupid people
    like me, can understand what they want. Maybe you should try that. As well as selecting an appropriate forum for your question in the future. Usually a question like this is related to programming in a particular language therefore a language forum may be
    a good choice. Or not.
    La vida loca

  • How to define and track a particular pattern in a series of images?

    i'm working on a robot project which require the robot chase an object. i plan on acquire images from IMAQ vision and control the motion of robot by LabVIEW.

    One example that you might look at to get you started is located here.
    To use pattern matching, you will need something on your target that will not change size, this may not be practical for a robot that will be chasing something. You can also look at thresholding followed by blob analysis to determine which item in your field of view is the target. This method works if your object will not be the same color as the background. This is faster than pattern matching, and is more size independant.

  • Just picked up my Macbook Pro (Oct 24th) to find that it keeps freezing on me - only way out is to crash it via the power button. No particular pattern to it.  It can happen on opening, or clicking on Safari - or when it's backing up on the TC.  Ideas?

    Picked up my new Macbook Pro Retina display on October 24th (2013).  It runs Mavericks.  Keeps freezing on me - with no pattern to it.  Sometimes when it's backing up, sometimes when it opens, sometimes when I click on Safari.  Only way out of the probelm is a crash shut down using the power button. Nothing else works.  Anyone found a fix to this yet?
    JRH

    Safe Mode deletes some system caches that may help.
    Startup your Mac in Safe Mode
    A Safe Mode boot takes longer than a normal boot so be patient.
    Once you are in Safe Mode, click Restart from the Apple () menu.

  • How do I create an emboss in a particular pattern I want?

    I want to emboss this image so that it looks like the small circles (coloured) are embossed on the big circle (red) and the 'G' is embossed over that to a bigger level....

    Is this a fully layered document?  If yes, it a simple matter of double clicking the relevant layer, and on Bevel & Emboss.
    If not layered, well, it would be MUCH easier and quicker to create it again as a layered document.

  • Keeps crashing, twice today and yesterday, once the day before. No particular pattern I can discern, just normal usage, usually 3-5 tabs open.

    Crashes usually just looking at a web page, not downloading anything, sometimes not even touching computer. So frustrating....

    Two of the four reports seem to be related to known issues, while two were not. One of the two with data shows numerous "closed" bugs so possibly Firefox 22 addresses those issues. The other one sounds as though it could be related to graphics drivers and/or Flash.
    '''Graphics Drivers'''
    Could you try disabling graphics hardware acceleration? Since this feature was added to Firefox, it has gradually improved, but there still are a few glitches and driver updates may cause new incompatibilities.
    You usually need to restart Firefox in order for this to take effect, so save all work first (e.g., mail you are composing, online documents you're editing, etc.).
    orange Firefox button (or Tools menu) > Options > Advanced
    On the "General" mini-tab, uncheck the box for "Use hardware acceleration when available"
    If you restart Firefox, is the issue resolved (or at least improved)?
    '''Flash'''
    The Flash player also has its own acceleration setting that you can disable. See this support article from Adobe: http://helpx.adobe.com/flash-player/kb/video-playback-issues.html#main_Solve_video_playback_issues
    Let us know about any new issues with Firefox 22.

  • UDF for reading a particular line and storing the value in a variable

    Hi Experts,
    I am reading entire file content in single feild in source data type.I want to write a UDF to seach for a particular pattern(say :25: and store the value after it i.e  34535764778 detination for further use).
    EX: My  sample file and its  has feilds like
    point assured
    Thanks

    Hi since u are using a single field only then u dont need to use any advanced function
    Wel because if u see the formation of the queue u wil find the the whole data is under one context.. and there are not more context changes
    Convert the string to an array and progressively u can check for the four checks if the a<i>=:
    then a[i+]=2 then a[i]=5 and a[i+] =: and then substring the next 7-8 chrac.. hope u understand
    If this also doesnt work wel then u will have to use the Pattern class in Java
    By the way remember that the substring value cant be retained for the next instance of mapping
    Hope u have that in mind...
    Rgds
    Aditya

Maybe you are looking for