Oracle+Mybatis query select...in... according to the content in in order to return

Return according to the content in the in statement

The function DECODE in Oracle is used here, the corresponding database statement

Introduction of DECODE function

select * from
    tbl
where
      id in('A7519254DEA575ECE053EB68580A1371','A7519254DEA875ECE053EB68580A1371','A7519254DEA675ECE053EB68580A1371','A7519254DEA775ECE053EB68580A1371')
ORDER BY "DECODE"(id,'A7519254DEA575ECE053EB68580A1371',1,'A7519254DEA875ECE053EB68580A1371',2,'A7519254DEA675ECE053EB68580A1371',3,'A7519254DEA775ECE053EB68580A1371',4);

Numbers are used here for sequential marking;

Docking mapper.xml in Mybatis

<select id="xxx">
select * from
    tbl
where
id in <foreach item="id" index="index" collection="ids"
               open="(" separator="," close=")">
        #{
    
    id,jdbcType=OTHER}
      </foreach>
ORDER BY "DECODE"(id,
    <foreach item="dataId" index="index" collection="dataIds"
             open="" separator="," close="">
      #{
    
    id,jdbcType=OTHER},#{
    
    index}
    </foreach>)
</select>

Guess you like

Origin blog.csdn.net/Bruce_Zhang0828/article/details/106612593