www.openlinksw.com
docs.openlinksw.com

Book Home

Contents
Preface

Virtuoso Functions Guide

Administration
Aggregate Functions
Array Manipulation
aref
aset
concat
concatenate
dvector
get_keyword
get_keyword_ucase
gvector_digit_sort
gvector_sort
isarray
make_array
position
rowvector_digit_sort
serialize
split_and_decode
tree_md5
vector
vector_concat
BPEL APIs
Backup
Compression
Cursor
Date & Time Manipulation
Debug
Dictionary Manipulation
Encoding & Decoding
File Manipulation
Free Text
Hashing / Cryptographic
LDAP
Locale
Mail
Miscellaneous
Number
Phrases
RDF data
Remote SQL Data Source
Replication
SOAP
SQL
String
Transaction
Type Mapping
UDDI
User Defined Types & The CLR
Virtuoso Java PL API
Virtuoso Server Extension Interface (VSEI)
Web & Internet
XML
XPATH & XQUERY

Functions Index

position

returns the index of an element within an array or string
position ( element any, array any, start_index integer (optional, default 1), step integer (optional, default 1));
Description

position returns the one-based index for the first occurrence of element within an array or string, beginning from offset start_index and iterating with step. If the second argument is a string, the first argument must be a string with a single character. If the second argument is an array of any, then depending of type of it's elements same type is expected as the first argument.

Parameters
element – any, depends of type of elements in second argument.
array – array, vector or string.
start_index – integer index beginning from 1; from where to start search.
step – integer the step between elements to be tested; default is 1 (every element)
Return Values

An integer index in array starting from 1; if not found returns zero.

Errors
SQLState Error Code Error Text Description
22003 SR061 position: expects a vector whose length is divisible by [step], not of length [actual len].
22023 SR000 position expects an array or vector, not an arg of type %d.

Examples
Simple examples
SQL> select position ('b', 'Abacus');
callret
VARCHAR
_______________________________________________________________________________

2

1 Rows. -- 3 msec.
SQL> select position (2, vector ('Primero', null, 2, 3.333));
callret
VARCHAR
_______________________________________________________________________________

3

1 Rows. -- 4 msec.

SQL> select position ('a', 'babaab', 1, 2);
                                ^--- matches 5-th as other 'a' are skipped as step is 2 chars
callret
INTEGER
_______________________________________________________________________________

5

1 Rows. -- 4 msec.
      
See Also

vector aset aref ascii