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.
Aset returns nelem. It modifies its first argument.
| SQLState | Error Code | Error Text | Description |
|---|---|---|---|
| 22003 | SR020 | Bad array subscript %d in aset. |
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.
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.