Your code is purely procedural. I would rather do something like that in an application because relational database systems were not (originally) designed for that. But that's beside the point...
Assuming that you have a function like PUT_LINE, I would do this:
Code:
CREATE PROCEDURE ...
BEGIN
DECLARE v1_1 VARCHAR(12) DEFAULT 'a'
DECLARE v1_2 VARCHAR(12) DEFAULT 'b';
DECLARE res INT;
SET res = PUT_LINE('initial varray(1) and v1(1) ' || v1_1);
SET v1_1 = 'z';
SET res = PUT_LINE('initial varray(1) and v1(1) ' || v1_1);
END@
If the array is too big, a temp table can hold the elements:
Code:
CREATE PROCEDURE ...
BEGIN
DECLARE res INT;
-- storage for the array
DECLARE GLOBAL TEMPORARY TABLE session.t1 ( id INT, value VARCHAR(12) );
-- initialize array elements
INSERT INTO session.t1 VALUES (1, 'a'), (2, 'b');
SET res = put_line('initial varray(1) and v1(1) ' || ( SELECT value FROM session.t1 WHERE id = 1 ) );
-- change an array element
UPDATE session.t1 SET value = 'z' WHERE id = 1;
SET res = put_line('initial varray(1) and v1(1) ' || ( SELECT value FROM session.t1 WHERE id = 1 ) );
DROP TABLE session.t1;
END@
Granted, the syntax is a bit more verbose, but you have the same functionality. (In fact, you could use UDFs to reduce the syntax a bit more.)