'Insert data from table A into table B with different column names, using a stored procedure
Tried to use a cursor to cut and input data from table A into table B, but keep returning a syntax error. This is for a school project, much appreciated.
CREATE OR REPLACE PROCEDURE public.sp_activedata_sap_pp1()
LANGUAGE plpgsql
AS $procedure$
DECLARE TARGET_CURSOR record;
begin
SET search_path TO "public";
FOR TARGET_CURSOR IN
SELECT
*
FROM
"public".t_activedata_sap_pp1
LOOP
declare
month_get int2 := replace(TARGET_CURSOR.cpudt, SUBSTR(TARGET_CURSOR.cupdt, 5, 2));
date_get varchar := replace(cpudt, TARGET_CURSOR.cpudt, SUBSTR(TARGET_CURSOR.cpudt, 1,6));
tcode_get varchar := "40";
begin
insert into "public".t_activedata_sap_pp1("year", "month", plant, "date", tcode, "number", "content", department, typemove, costcenter, costcenter_2, value, workplace, workplace_code)
values(TARGET_CURSOR.mjahr, TARGET_CURSOR.month_get, TARGET_CURSOR.werks, TARGET_CURSOR.date_get, TARGET_CURSOR.tcode_get, TARGET_CURSOR.matnr, TARGET_CURSOR.mat_text, '', TARGET_CURSOR.bwart, '', '', TARGET_CURSOR.menge2, '', '')
end;
END LOOP;
END;
$procedure$
;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
