I have been trying to create a procedure in order to "EXECUTE INSERT INTO" a table. I gave up on this and continued trying to dynamically generate the required insert into code.
I have solved my issue by not creating the procedure and simply starting from the "DECLARE" bit; but still have not managed to make the pl/pgsql procedure to work.
The following procedure is not working:
CREATE PROCEDURE populate_xcc_allocatable() AS
$body$
DECLARE
TYPE tablearray IS VARRAY(17) OF VARCHAR2(30);
xa_tables tablearray := tablearray('allocation', 'container', 'location', 'sap_posting', 'status');
total integer;
BEGIN
total := xa_tables.count;
FOR i IN 1..total
LOOP
dbms_output.put_line('INSERT INTO allocatable VALUES (nextval(''allocatable_id_seq''), ''' || xa_tables(i) || ''');');
END LOOP;
END;
$body$
LANGUAGE plpgsql;
LINE 4: TYPE tablearray IS VARRAY(17) OF VARCHAR2(30);
CONTEXT: invalid type name "tablearray IS VARRAY(17) OF VARCHAR2(30)"
But this is working fine:
DECLARE
TYPE tablearray IS VARRAY(17) OF VARCHAR2(30);
xa_tables tablearray := tablearray('allocation', 'container', 'location', 'spirit_portion', 'activity', 'asset_ownership', 'container_location', 'sap_posting', 'status');
total integer;
BEGIN
total := xa_tables.count;
FOR i IN 1..total
LOOP
dbms_output.put_line('INSERT INTO xcc_allocatable VALUES (nextval(''xcc_allocatable_id_seq''), ''' || xa_tables(i) || ''');');
END LOOP;
END;