I'm facing an Oracle to PostgreSQL migration: I managed to convert tables and views however I'm a bit stuck with Stored Procedures.
I've started with this one, which looks like this in Oracle:
CREATE OR REPLACE procedure
update_role_func_def(function_id varchar2)
as
cursor role_list_cursor is
select r.id from amm_role r
for update of r.id
;
begin
for role_record in role_list_cursor
loop
insert into AMM_ROLE_FUNC_DEF (RID, FID, GRANT_FUNCT) values (role_record.id, function_id, 'N');
end loop;
commit;
end update_role_func_def;
looking at the docs I managed to create this equivalent:
CREATE FUNCTION
update_role_func_def(function_id varchar)
returns void
as
$$
DECLARE
cursor role_list_cursor is
select r.id from amm_role r for update of r.id ;
begin
for role_record in role_list_cursor
loop
insert into AMM_ROLE_FUNC_DEF (RID, FID, GRANT_FUNCT) values (role_record.id, function_id, 'N');
end loop;
commit;
end ;
$$
However entering this procedure in the PgAdmin results in a "Syntax Error, unexpected CREATE, expecting ';'
I feel a bit lost: is there any Postgres developer that can give me a clue if the procedure is syntactically correct ?
commitinside a function in Postgres. And you don't need the cursor at all (neither in Oracle nor in Postgres), this can be done with a singleINSERT ... SELECT statement. And why do you usefor updateif you are not updatingamm_roleat all?sqlonly (nodeclare,begin,end) as suggested by @a_horse unless there is more in the function that needs plpgsql. Declare the used languagelanguage sqlorlanguage plpgsql