Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XQuery

KaushikBoseApr 28 2016 — edited Apr 29 2016

XQuery

Input: (1,2,3,4,5,6,7,14,15,16,17,24,25,26,27,28)

Output: (1,7,14,17,24,28)

I tried to remove consecutive numbers from the input sequence using the XQuery functions but failed doing so

xquery version "1.0" encoding "utf-8";

declare namespace ns1="http://www.somenamespace.org/types";

declare variable $request as xs:integer* external;

declare function local:func($reqSequence as xs:integer*) as xs:integer* {

let $nonRepeatSeq := for $count in (1 to count($reqSequence)) return

if ($reqSequence[$count+1] - $reqSequence) then remove($reqSequence,$count+1) else ()

return $nonRepeatSeq

};

local:func((1,2,3,4,5,6,7,14,15,16,17,24,25,26,27,28))

Please suggest how to do so in XQuery functional language.

Comments

odie_63

Something like this :

let $input := (1,2,3,4,5,6,7,14,15,16,17,24,25,26,27,28)

return

  for $i at $p in $input

  return if ( $input[$p - 1] != $i - 1

           or $input[$p + 1] != $i + 1

           or $p = 1

           or $p = count($input) ) then $i else ()

1 - 1
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 27 2016
Added on Apr 28 2016
1 comment
845 views