1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
-
- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
- project.
-
- Copyright (C) 1998-2018 OpenLink Software
-
- This project is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; only version 2 of the License, dated June 1991.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-
-->
<refentry id="fn_aset">
<refmeta>
<refentrytitle>aset</refentrytitle>
<refmiscinfo>array</refmiscinfo>
</refmeta>
<refnamediv>
<refname>aset</refname>
<refpurpose>set array element</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis id="fsyn_aset">
<funcprototype id="fprot_aset">
<funcdef><function>aset</function></funcdef>
<paramdef>in <parameter>arg</parameter> any</paramdef>
<paramdef>in <parameter>nth</parameter> integer</paramdef>
<paramdef>in <parameter>new_elem</parameter> any</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1 id="desc_aset"><title>Description</title>
<para>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.</para>
</refsect1>
<refsect1 id="params_aset"><title>Parameters</title>
<refsect2><title>arg</title>
<para>A string, array or vector.</para>
</refsect2>
<refsect2><title>nth</title>
<para>Zero-based element index.</para>
</refsect2>
<refsect2><title>nelem</title>
<para>The new element. If <parameter>arg</parameter> is a string,
its nth element will be replaced by the ASCII value given in
<parameter>new_elem</parameter>.</para>
</refsect2>
</refsect1>
<refsect1 id="ret_aset"><title>Return Values</title>
<para><function>Aset</function> returns
<parameter>nelem</parameter>. It modifies its first argument.</para>
</refsect1>
<refsect1 id="errors_aset"><title>Errors</title>
<table><title>Errors signalled by aset</title>
<tgroup cols="4">
<thead><row><entry>SQLState</entry><entry>Error Code</entry><entry>Error Text</entry><entry>Description</entry></row></thead>
<tbody>
<row>
<entry><errorcode>22003</errorcode></entry>
<entry><errorcode>SR020</errorcode></entry>
<entry><errorname>Bad array subscript %d in aset.</errorname></entry>
<entry></entry>
</row>
</tbody>
</tgroup>
</table>
</refsect1>
<refsect1 id="examples_aset"><title>Examples</title>
<example id="ex_aset_1">
<title>Using <function>make_string</function> and
<function>aref</function></title>
<para>Make a string, fill with character sequence from A to Z.</para>
<screen>
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.
</screen>
</example>
<example id="ex_aset_2"><title>Reverse a string using aset</title>
<para>Note that str is modified by aset.</para>
<screen>
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.
</screen>
</example>
</refsect1>
<refsect1 id="seealso_aset"><title>See Also</title>
<para><link linkend="fn_aref"><function>aref()</function></link>,
<link linkend="fn_vector"><function>vector()</function></link>,
<link linkend="fn_make_string"><function>make_string()</function></link>
</para>
</refsect1>
</refentry>
|