Dataworks-数据服务之API脚本模式(高级SQL)

 常用的高级SQL示例:

1、通过判断字段值是否为空来控制where查询条件是否保留

<where>
    <if test='PUR_ODR_CODE !=null and PUR_ODR_CODE !=""'>
    AND PUR_ODR_CODE=${PUR_ODR_CODE}
    </if>
    <if test='PUR_ODR_ITEM_CODE !=null and PUR_ODR_ITEM_CODE !=""'>
    AND PUR_ODR_ITEM_CODE=${PUR_ODR_ITEM_CODE}
    </if>
</where>

2、IN  多值遍历

<where>
    <if test='UTC_NUM!=null'>
        and UTC_NUM in
        <foreach collection="UTC_NUM" open="(" close=")" separator="," item="utc_num">
            ${utc_num}
        </foreach>
    </if>
</where>

参数需要选择: STRING_LIST 

3、Like模糊匹配

<where>
    <if test='WBS_CODE !=null and WBS_CODE !=""'>
        AND WBS_CODE like concat('%',${WBS_CODE},'%')
    </if>
    <if test='SUPP_NAME !=null and SUPP_NAME !=""'>
        AND SUPP_NAME like concat('%',${SUPP_NAME},'%')
    </if>
</where>

4、对日期或者数值进行范围查询

<where>
    <if test='ACT_DLV_TIME_START !=null and ACT_DLV_TIME_START !=""'>
        AND ACT_DLV_TIME &gt;= ${ACT_DLV_TIME_START}
    </if>
    <if test='ACT_DLV_TIME_END !=null and ACT_DLV_TIME_END !=""'>
        AND ACT_DLV_TIME &lt;= ${ACT_DLV_TIME_END}
    </if>
</where>

 

posted @ 2024-09-03 12:07  业余砖家  阅读(57)  评论(0)    收藏  举报