Warm tip: This article is reproduced from stackoverflow.com, please click
postgresql plpgsql mybatis spring-mybatis

how to inject pl/pgsql in myBatis 3 xml mapper

发布于 2020-03-27 15:42:08

I am using MyBatis 3.3.0 with Postgresql 12. I want to inject some pl/pgsql in my xml mapper

for example: to insert data with for loop

 <update id="generateNumbers" parameterType="tn.tt.nbms.dto.RangeDTO" statementType="CALLABLE">


<![CDATA[ 
   declare 
     ..... 
   begin 
      for number in ...... 
             insert into.....(....) values (...) 
      end loop; 
   end; ]]> 
</update>

with oracle and Pl/sql it works fine but I can't convert it to pl/pgsql How can I do it I know I can use stored procedure but my question is how to inject pl/pgsql in xml mapper files if it is possible?

Questioner
Yosra
Viewed
157
Yosra 2020-01-31 16:35

After some research I found that for poqgresql (unlike oracle) we can not set parameters to anonymous code block

so we can use batch operations

[1] https://github.com/mybatis/mybatis-3/wiki/FAQ#how-do-i-code-a-batch-insert [2] https://stackoverflow.com/a/55518327/

or stored procedure

I hope that will help some one ....