Skip to Main Content

SQL & PL/SQL

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!

How to use XQuery Custom Function in Oracle SQL Queries

Orcl ApexJun 7 2018 — edited Aug 28 2018

Hi All,

I am trying to understand using Xquery custom functions in usage with oracle sql queries.

Kindly help me understanding these with some examples.

example of custom function from OTN:

select * from

    xmltable('declare function local:reverse($a)

              {

                if (string-length($a) != 0) then

                 concat(substring($a,string-length($a),1), local:reverse(substring($a,1,string-length($a)-1)))

                else ()

              }; (: eof

              declare function local:sum($a)

              {

                if (string-length($a) != 0) then

                  xs:integer(substring($a,1,1)) + xs:integer(local:sum(substring($a,2)))

                else (0)

              }; (: eof

              declare function local:prod($a)

              {

                if (string-length($a) != 0) then

                  xs:integer(substring($a,1,1)) * xs:integer(local:prod(substring($a,2)))

                else (1)

              }; (: eof

              for $i in 1 to 10000

               where $i - local:reverse(xs:string($i)) = local:sum(xs:string($i)) + local:prod(xs:string($i))

                     return $i' columns x integer path '.')

This post has been answered by mNem on Jun 8 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 25 2018
Added on Jun 7 2018
12 comments
647 views