Count consecutive repetitive element in a sequence using XQuery

If the sequence = [an a b c c c a d e e d e f g h h]

then her output = [1 2 1 1 2 3 1 1 2 1 2 3 1 1 1 2]

Have tried to use recursion, but no luck... Help, please... Thank you in anticipation

Note: Using the implementation of XQuery 1.0

One of my failing application looks like:

declare function local:test($sequence,$count){

for $counter in (1 to count($sequence))

let $maxIndex := count($sequence)

return

if (matches(subsequence($sequence,1,$maxIndex)[$counter],subsequence($sequence,1,$maxIndex)[$counter + +1])) then let $count := $count + 1 return $count[last()]

else let $count := 1 return $count[last()]


};


It seems like $counter is a sequence where she returns a sequence in State matches and so fail this implementation

An interesting, easy to solve with the SQL analytic functions, but a little harder exercise using XQuery.

Here's one way:

declare function local: sequence-group ($seq as item() *) as item() *.

{

Let $start - of - Group: =.

FN: index - of)

for $i in 1-count ($seq)

Let $prev: = $seq [$i - 1]

return if ($prev! = $seq [$i] or not ($prev)) then 1 else 0

1

)

return

for $i in 1-count ($seq)

Return $i - $start Group [. $i] [last () the] + 1

};

Let $seq: = ('a', 'a', 'b', 'c', 'c', 'c', 'a', ', ', 'e', 'e', 'e', 'f', 'g', 'h', 'h')

return local: sequence - group ($seq)

The idea is to first find the starting index of each group, in this case:

$start-Group: = (1, 3, 4, 7, 8, 10, 13, 14, 15)

Then, for each element of the sequence, we have just to retrieve the associated with the starting index and remove them from the current position.

Tags: Oracle Development

Similar Questions

  • Perform a sequence using the new method of execution

    Hi ppl,

    I use the Engine.NewExecution method in LabVIEW to perform a sequence using sequential process model. I have been successful in this attempt.

    Now when I tried to pass arguments to the sequence with this method I could not do

    From the help file, I found to pass property to the sequenceArgsParam in the Engine.NewExecution. I used the Engine.NewPropertyObject to create a new property object. My problem started here. I was not able to define the parameters for the property object I created. When I created an object of type container property, newExecuion method returned an error indicating that the type is the string even if the setting for my sequence was a container. When I created a method of setValString string property object returned error saying unable to find settings where the look of string upward was parameters.x

    Please help me some body. I'm stuck with this upward.  can someone give me an example of program that passes parameters to the sequence when running via the NewExecution method.

    Hello

    It is not the Engine.NewPropertyObject method to pass parameters

    I used to sequence method before running the sequence

    try to replace the step Engine.NewExecution of this VI

    the values are in a cluster table: parameter is the name of the parameter in your sequence, the value is the value to pass

    A2

    Note 1: there is only the string in this VI, it is possible to change with integer...

    Note 2: If you have a container, the parameter name is "container". "" The name of the parameter.

  • count of the elements of another frequency table

    Hello

    I'm new to apex oracle so patient with me

    I'm counting the number of items in the other table using primary key (in this case the ID) for example:

    Inventory of the table:

    IDFRUITLOCATION

    1

    AppleWE
    2ORANGEUK
    3MANGOGermany
    1AppleUK
    1Apple

    UK

    Summary table

    ID
    FRUIT
    QUANTITY
    1Apple3
    2ORANGE1
    3MANGO1

    So basically I want to get quantity table in the summary table based on the inventory data, I thought to change the Source of the region by using apex_item.text, but it is not working properly. And I think that there are some restrictions in the source of the region on the query syntax as well since I can't use the count() function on the SELECT part, or using the loop, ideas?

    Simply create a second region of report based on a query, we gave you. Do not base a report on a table, you can create a report based on a query.


  • I have an older version of elements with I could use on my PC, I just bought a MacBook Pro and want to install it on MAC I can't find a place to download vs 13 Please help not wanting to upgrade to 14 again

    I have an older version of elements with I could use on my PC, I just bought a MacBook Pro and want to install it on MAC I can't find a place to download vs 13 Please help not wanting to upgrade to 14 again

    Available downloadable Setup files:

    Download and installation help links Adobe

    Help download and installation to Prodesigntools links can be found on the most linked pages.  They are essential; especially steps 1, 2 and 3.  If you click on a link that does not have these listed steps, open a second window by using the link to Lightroom 3 to see these "important Instructions".

  • Photoshop elements 14 can be used with 10.11 El Capitan OSX operating system?  Thank you

    Photoshop elements 14 can be used with 10.11 El Capitan OSX operating system?  Thank you

    Hi Francisco,.

    Photoshop elements 14 can be used with OS 10.11

    Please let us know if you have any questions.

    Kind regards

    Abhishek Seth.

  • I just bought a new Lenovo, computer office equipped Windows 10.  In September, I bought Photoshop elements 13 and have used on my old computer with Windows 7...  Can I download this version of photoshop on my new computer windows 10 and wil

    I just bought a new Lenovo, computer office equipped Windows 10.  In September, I bought Photoshop elements 13 and have used on my old computer with Windows 7...  Can I download this version of photoshop on my new computer windows 10, and it'll work?

    Download Photoshop Elements | 10, 12, 14, 11, 13

    Download, install, then enter your serial number.

  • Y at - it upgrade Photoshop Elements 5.0 for use with Windows 8?

    Y at - it an upgrade to Photoshop Elements 5.0 for use with Windows 8?

    Yes, photoshop elements 11 should be compatible with win 8 and there is a path of update here: http://www.adobe.com/products/photoshop-elements.html

    (compatibility info: http://www.microsoft.com/en-us/windows/compatibility/en-US/CompatCenter/ProductViewerWithD efaultFilters?) Architecture = X 64 & CurrentPage = 0 & TotalPages =-1 & ShowCriteria = 10 percent 20resultats % 20Per % 20Page & SortCriteria = relevance & IsSearchWithinFilterAvailable = False & FilterByCompatibility = a he'S & TextSearch 1 = Photoshop & AbsolutePage = & LastRequested = 13 & LastSearchTerm = Photoshop )

  • Sequence used for a wizard generated form

    Hello

    I have a page that includes a form wizard generated.
    In the process of section there is a process named MRU apply which performs the operation to update DML on the base table.

    The primary key column is getting updated through a sequence, but when I look at the details of the process apply MRU I can't understand what sequence is used.

    How can I go to find out the sequence used to this primary key column?


    Thank you
    Dippy

    Hello

    Then you've got after him would process created by the wizard who is looking for the next sequence number.

    BR, Jari

  • Nested reading XML using XQUERY in the PL/SQL procedure

    I'm using Oracle 11 G.
    I have a PL/SQL procedure, which is reading XML using xquery XMLTYPE column in a table. The XML contains data of the DEPARTMENT and its SECTIONS. DEPARTMENT has a to-many with SECTIONS or a DEPARTMENT can have one or more SECTIONS, and there may be cases where the DEPARTMENT will have all SECTIONS.

    The XML structure is such that
    <DATA>
    label to identify a DEPARTMENT and all its corresponding SECTIONS.

    XML
    <ROWSET> 
    <DATA>
     <DEPARTMENT>
      <DEPARTMENT_ID>DEP1</DEPARTMENT_ID>
      <DEPARTMENT_NAME>myDEPARTMENT1</DEPARTMENT_NAME>
     </DEPARTMENT>
     <SECTIONS>
      <SECTIONS_ID>6390135666643567</SECTIONS_ID>
      <SECTIONS_NAME>mySection1</SECTIONS_NAME>
      </SECTIONS>
       <SECTIONS>
      <SECTIONS_ID>6390135666643567</SECTIONS_ID>
      <SECTIONS_NAME>mySection2</SECTIONS_NAME>
      </SECTIONS>
     </DATA>
     <DATA>
     <DEPARTMENT>
      <DEPARTMENT_ID>DEP2</DEPARTMENT_ID>
      <DEPARTMENT_NAME>myDEPARTMENT2</DEPARTMENT_NAME>
     </DEPARTMENT>
     <SECTIONS>
      <SECTIONS_ID>63902</SECTIONS_ID>
      <SECTIONS_NAME>mySection1</SECTIONS_NAME>
      </SECTIONS>
     </DATA>
    </ROWSET>
    XQUERY
    select
     department_id,
      department_name,
      sections_id,
      sections_name
    from
      OFFLINE_XML xml_list,
      xmltable(
        '
          for $department in $param/ROWSET/DATA
            return $department
        '
        passing xml_list.xml_file as "param"
        columns
          "DEPARTMENT_ID"   varchar2(100) path '//DEPARTMENT/DEPARTMENT_ID',
          "DEPARTMENT_NAME" varchar2(4000) path '//DEPARTMENT/DEPARTMENT_NAME',
          "SECTIONS_ID"     varchar2(100) path '//SECTIONS/SECTIONS_ID',
          "SECTIONS_NAME"   varchar2(4000) path '//SECTIONS/SECTIONS_NAME'
      ) section_list
    where
      xml_list.Status = 5
    The performance of the query, you receive an error
    ORA-19279: XPTY0004 - XQuery dynamic type mismatch: expected singleton 
    sequence - got multi-item sequence
    It is natural because I have several sections, now how I'll handle this situation.

    It's the usual approach to manage several nested collections:

    SQL> select d.department_id
      2       , d.department_name
      3       , s.sections_id
      4       , s.sections_name
      5  from offline_xml t
      6     , xmltable(
      7         '/ROWSET/DATA'
      8         passing t.xml_file
      9         columns
     10           DEPARTMENT_ID   varchar2(20) path 'DEPARTMENT/DEPARTMENT_ID'
     11         , DEPARTMENT_NAME varchar2(30) path 'DEPARTMENT/DEPARTMENT_NAME'
     12         , SECTIONS        xmltype      path 'SECTIONS'
     13       ) d
     14     , xmltable(
     15         '/SECTIONS'
     16         passing d.sections
     17         columns
     18           SECTIONS_ID     varchar2(20) path 'SECTIONS_ID'
     19         , SECTIONS_NAME   varchar2(30) path 'SECTIONS_NAME'
     20      ) s
     21  ;
    
    DEPARTMENT_ID        DEPARTMENT_NAME                SECTIONS_ID          SECTIONS_NAME
    -------------------- ------------------------------ -------------------- ------------------------------
    DEP1                 myDEPARTMENT1                  6390135666643567     mySection1
    DEP1                 myDEPARTMENT1                  6390135666643567     mySection2
    DEP2                 myDEPARTMENT2                  63902                mySection1
     
    
  • Assign default names to fragment XML using XQuery

    Hello world!

    I need to add a default namespace declaration to a fragment of XML using XQuery. I wrote following statement to assign the fragment to $body:

    < SOAP - env:Body > {}
    {FN - bea: inlinedXML ($content / text ())}
    < / soap - env:Body >

    The problem is "$content / text ()" has no namespace declaration, so I need to assign a default namespace (xmlns = "" ") to it in order to apply some XQuery transformations to its content.

    I know it can be done easily with a XSLT, but I would like to use XQuery instead.

    Could someone tell me how can I perform this task?

    Thank you in advance,

    Daniel.

    Hello

    I suppose that you have two options here:

    (1) addition of namespace directly on the XML textual content in $content / text (), then call fn - bea: inlinedXML.
    Assuming that the implementation of XQuery in BEA supports the function fn: replace (according to the doc, he does-) or equivalent:

    fn-bea:inlinedXML( fn:replace($content/text(), '^<([^>]+)>', '<$1 xmlns="default_ns">') )
    

    For example, if $content / text () is

    TEST!
    

    The result will be:

    TEST!
    

    (2) the addition of namespace on the generated instance (that is, after the call to fn - bea: inlinedXML).

    It's a little more complex and it will take something like this:
    http://www.xqueryfunctions.com/XQ/functx_change-element-NS-deep.html

  • converting string to XML using Xquery transformation in OSB node

    How to convert the string to XML node elementusing built in function by using Xquery transformation in OSB?

    Discover this - http://www.javamonamour.org/2011/06/fn-beainlinedxml.html

    If in SOA (BPEL & mediator), you can use oraext:parseXML.

    You must analyze in depth where to implement your requirement as some good practices advise to implement logic more complex in SOA and let OSB only connect to endpoints of services.

    Hope this helps,

    A.

  • How can I recursively parse an xml using XQuery document?

    I have an open and I have to using XQuery in Response.xml can transform someone give me an idea how to analyze recursive Xml using XQuery documents. Any help will be appreciated. Thanks in advance

    Open

    " < = xmlns:ns0 ns0:GlobalRoutePlanServiceGOPResponse ' http://www.example.org/input ">

    < GlobalRoutePlanServiceResponse >

    < response >

    Buid_1 < Buid > < / Buid >

    SalesOrderId_1 < SalesOrderId > < / SalesOrderId >

    EODD_1 < EODD > < / EODD >

    LODD_1 < LODD > < / LODD >

    < legs >

    < leg >

    < level > 1 < / level >

    < Resources > ShipMode_1 < / resources >

    < FSBD > FSBD_1 < / FSBD >

    FABD_1 < FABD > < / FABD >

    < leg >

    < leg >

    < niv.2 > < / level >

    < Resources > ShipMode_2 < / resources >

    < FSBD > FSBD_1 < / FSBD >

    FABD_1 < FABD > < / FABD >

    < leg >

    < leg >

    < level > 3.1 < / level >

    < resources > ShipMode_3.1 & amp; < / resources >

    < FSBD > FSBD_1 < / FSBD >

    FABD_1 < FABD > < / FABD >

    < leg >

    < leg >

    < level > 4.1 < / level >

    < Resources > ShipMode_4.1 < / resources >

    < FSBD > FSBD_1 < / FSBD >

    FABD_1 < FABD > < / FABD >

    < leg > < / foot >

    < / foot >

    < / foot >

    < / foot >

    < leg >

    < level > 3.2 < / level >

    < Resources > ShipMode_3.2 < / resources >

    < FSBD > FSBD_1 < / FSBD >

    FABD_1 < FABD > < / FABD >

    < leg >

    < leg >

    < level > 4.2 < / level >

    < Resources > ShipMode_4.2 < / resources >

    < FSBD > FSBD_1 < / FSBD >

    FABD_1 < FABD > < / FABD >

    < leg > < / foot >

    < / foot >

    < / foot >

    < / foot >

    < / foot >

    < / foot >

    < / foot >

    < / foot >

    < / legs >

    < / answer >

    < / GlobalRoutePlanServiceResponse >

    < / ns0:GlobalRoutePlanServiceGOPResponse >

    Response.Xml

    " < = xmlns:ns0 ns0:InputParameters ' http://xmlns.Oracle.com/pcbpel/adapter/DB/SP/GOP_DB_FSL_Msg_Persist_SVC "> "

    < ns0:P_LEG >

    < ns0:P_LEG_ITEM >

    < ns0:LEGS_LEVEL > 1 < / ns0:LEGS_LEVEL >

    < ns0:SHIPMODE > ShipMode_1 < / ns0:SHIPMODE >

    < / ns0:P_LEG_ITEM >

    < ns0:P_LEG_ITEM >

    < ns0:LEGS_LEVEL > 2 < / ns0:LEGS_LEVEL >

    < ns0:SHIPMODE > ShipMode_2 < / ns0:SHIPMODE >

    < / ns0:P_LEG_ITEM >

    < ns0:P_LEG_ITEM >

    < ns0:LEGS_LEVEL > 3.1 < / ns0:LEGS_LEVEL >

    < ns0:SHIPMODE > ShipMode_3.1 < / ns0:SHIPMODE >

    < / ns0:P_LEG_ITEM >

    < ns0:P_LEG_ITEM >

    < ns0:LEGS_LEVEL > 4.1 < / ns0:LEGS_LEVEL >

    < ns0:SHIPMODE > ShipMode_4.1 < / ns0:SHIPMODE >

    < / ns0:P_LEG_ITEM >

    < ns0:P_LEG_ITEM >

    < ns0:LEGS_LEVEL > 3.2 < / ns0:LEGS_LEVEL >

    < ns0:SHIPMODE > ShipMode_3.2 < / ns0:SHIPMODE >

    < / ns0:P_LEG_ITEM >

    < ns0:P_LEG_ITEM >

    < ns0:LEGS_LEVEL > 4.2 < / ns0:LEGS_LEVEL >

    < ns0:SHIPMODE > ShipMode_4.2 < / ns0:SHIPMODE >

    < / ns0:P_LEG_ITEM >

    < / ns0:P_LEG >

    < / ns0:InputParameters >

    You can use recursive expressions function XQuery to browse down the tree (even if it's more than a job for XSLT), but in this case, it is probably easier to use a descendant axis:

    declare namespace ns0 = "http://xmlns.oracle.com/pcbpel/adapter/db/sp/GOP_DB_FSL_Msg_Persist_SVC";

    declare namespace ns1 = "http://www.example.org/INPUT";

    {

    for $i in $request / ns1:GlobalRoutePlanServiceGOPResponse / GlobalRoutePlanServiceResponse/response/legs / / leg

    where exists($i/Level)

    return

    {$i} / level/text)

    {$i} / ShipMode/text)

    }

    Output:

    http://xmlns.Oracle.com/pcbpel/adapter/DB/SP/GOP_DB_FSL_Msg_Persist_SVC">

    1

    ShipMode_1

    2

    ShipMode_2

    3.1

    ShipMode_3.1 &

    4.1

    ShipMode_4.1

    3.2

    ShipMode_3.2

    4.2

    ShipMode_4.2

  • Using XQuery with PL/SQL, link the Variable

    I am only able to find an example of use of xquery with pl/sql.

    [http://www.comp.dit.ie/btierney/oracle11gdoc/appdev.111/b28369/xdb_xquery.htm#CBAEEJDE]

    Why is what they show only using bind variables? It's the only way it should be used, it provides a performance gain more simply by using the crossing clause and a passing beam a PL/SQL variable? I'm looking to implement a solution for my company using Xquery in PL/SQL. I am concerned that these procedures will be called during a flow of the user interface and performance it must be as soon as possible.

    A PL/SQL variable, column, or the output of another operation would be all be equivalent to a connection variable that PL/SQL compilation is concerned. Which would be bad practice would be to build in XQuery with the predicate hardcoded in the XQuery operation whenever the XQuery query has been run.

  • Delete empty rows in the CSV using Xquery/XSLT file.

    Hello
    I have a CSV output file, where in it has empty lines at the end of the file, I want to delete these empty lines, can pls help on this point, that the way to delete these empty lines using Xquery/XSLT.


    sample file:

    20110706, O, Q, GGG, POT, LMM
    20110708, AAA, OPP, P, MAST
    20110715, BBB, TTT, O, TIN


    empty lines




    Thank you...

    Published by: user12679330 on July 27, 2011 12:29 AM

    Published by: user12679330 on July 27, 2011 12:32 AM

    Published by: user12679330 on July 27, 2011 12:32 AM

    I assume you are using a Proxy Service with text messaging and transport of type file or FTP to read the file and the same configuration to write the file.
    Then, you can use a simple snippet of XQuery in OSB assign or replace to remove extra blank lines:

    The editor page here is replaceing the escape characters carriage return and linefeed real CR and LF, so I described as a sample, you can replace the values in the XQuery when you use OSB,

    if (fn:contains(xs:string($body), 'CRLF'))
       then
          fn:replace (xs:string($body), 'CRLFCRLF', '')
    else
          fn:replace(xs:string($body), 'LFLF', '')
    

    In XQuery, replace CR Ð (also remove the space between & #xD and ;))
    and LF with (also remove the space between & #xA and ;))

  • using xquery in osb

    I want to compare two values of xquery (proxy service - if then the condition)
    If the first value is less than the second value or not

    I use fn: compare

    First value is stored in the variable firstres
    second value is variable secondres store

    Can someone tell me how to compare using xquery

    Use this option if you know that the values will be always digital. This should solve the problem with the comparison of the values of the number of different figures.
    XS:Decimal(Data($a))<>

Maybe you are looking for

  • Satellite A30, Win XP Pro SP3 - modem does not work

    Another problem with this laptop Satellite A30The built-in modem does not work. * Explanation: *.The driver is correct and downloaded from the Toshiba support site.The modem is identified as "Toshiba software modem amr" and is installed on com3 port.

  • How can I access my library songs with someone's computer?

    I sold my computer and don't think much about music on my phone. Well, I had to replace my phone, and I noticed that more than 500 songs, that I had on my music had disappeared.  So I used the computer of my father who has installed iTune.  I thought

  • Best survey practice: tiering with different types of storage drives

    Hello We recently received a new SAN Equallogic, and I am deciding the implementation. Our first unit (currently only one member in a swimming pool) is a PS4100 with 24x600GB 10K SAS. The new unit is a PS4210 with 12x4TB 7.2 K NL SAS. Should I leave

  • How to associate with Microsoft?

    Original title: How to become a partner Dear Sir/Madam, We are the website jobinqatar.org to the Qatar. jobinqatar.org is one of the best site for career opportunities and of the implementation to the Qatar. Can we get Microsoft partnership. If we ca

  • author not changed in case the other copy original as comment user base

    We have created a document and added comments in Adobe Acrobat Standard DC and submitted to client, which added some additional comments by copying the original comments made by us.In doing so the author is not changed to the person who copied the co