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
isarray
make_array
position
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
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 Server & Internet
XML
XPATH & XQUERY

Functions Index

aset

set array element
aset (in arg any, in nth integer, in new_elem any);
Description

aset sets the nth element of a string, array or vector where nth is a zero-based index. If the first argument is a string, the nth character of string is replaced with the ASCII value given in the third argument elem.

Parameters
arg – A string, array or vector.
nth – Zero-based element index.
nelem – The new element. If arg is a string, its nth element will be replaced by the ASCII value given in new_elem.
Return Values

Aset returns nelem. It modifies its first argument.

Errors
SQLState Error Code Error Text Description
22003 SR020 Bad array subscript %d in aset.

Examples
Using make_string and aref

Make a string, fill with character sequence from A to Z.

SQL> create procedure
alphabet_string ()
{
  declare _inx integer;
  declare _str varchar;
  _str := make_string (26);

  while (_inx < 26)
    {
      aset (_str, _inx, _inx + 65);
      _inx := _inx + 1;
    }

  return (_str);
}
;

Done. -- 6 msec.
SQL> select alphabet_string ();
callret
VARCHAR NOT NULL
_______________________________________________________________________________

ABCDEFGHIJKLMNOPQRSTUVWXYZ

1 Rows. -- 4 msec.
Reverse a string using aset

Note that str is modified by aset.

SQL> create procedure
revstr (in str varchar)
{
    declare len, inx1, inx2, tmp integer;

    if (str is null) return (str);

    len := length (str);
    if (len < 2)
      return (str); -- No need for further processing

    inx1 := 0;       -- Index from the left.
    inx2 := len - 1; -- Index from the right.
    len  := len / 2; -- Upper limit for inx1.

    while (inx1 < len)
      {
        tmp := aref (str, inx1);
	aset (str, inx1, aref (str, inx2));
	aset (str, inx2, tmp);
	inx1 := inx1 + 1;
	inx2 := inx2 - 1;
      }
    return (str);
}
;

Done. -- 7 msec.
SQL> select revstr ('repaid'), revstr ('Alli, tapa pulu papatilla!');
callret   callret
VARCHAR   VARCHAR
_______________________________________________________________________________

diaper    !allitapap ulup apat ,illA

1 Rows. -- 11 msec.
See Also

aref(), vector(), make_string()