pg的存储过程的创建如下所示:
create or replace function "public"."update_sequence"("v" int4) returns void as $$ declare seq_record record; begin for seq_record in (select relname from pg_class where relkind='S') loop execute 'alter sequence ' || seq_record.relname || ' restart with ' || v || ';'; end loop; end; $$ language plpgsql volatile cost 100;
存储过程中 执行sql语句,要加execute
mybatis的mapper.xml文件中调用pg的存储过程如下:
<select id="xxx方法名"> select update_sequence(#{number}) </select>
注意:mybatis调用存储过程的入参类型要和pg中创建的存储过程的入参类型一致,不要会找不到对应的存储类型
mybatis 中执行pg的存储过程 用select ; 执行mysql的存储过程 用call