sql语句查询报出标识符无效怎么解决?

it2025-08-06  7

昨天出现这个问题,是因为输出的字段都是a.字段名,但是我再sql语句中没有将表名重命名为a,导致sql语句执行时没有识别到a,所以报出标识符无效

一开始我是这样写的,表名没有重命名为a,导致输出字段时没有识别到a

<sql id="fsUnionPosColumns"> a.id AS "id", a.isdisable AS "isdisable", a.create_by AS "createBy.id", a.create_date AS "createDate", a.update_by AS "updateBy.id", a.update_date AS "updateDate", a.remarks AS "remarks", a.del_flag AS "delFlag", a.isverify AS "isverify", a.service_num AS "serviceNum", a.psam AS "psam", a.pos_tradetype AS "posTradetype" </sql> <select id="selectPosFindByPsam" resultType="FsUnionPos"> select <include refid="fsUnionPosColumns"/> from fs_union_pos where psam = #{psam} and isdisable ='1' </select>

将sql语句修改为下面这样:就是表名重命名为a,在执行不会报错

<select id="selectPosFindByPsam" resultType="FsUnionPos"> select <include refid="fsUnionPosColumns"/> from fs_union_pos a where psam = #{psam} and isdisable = '1' </select>

这样的sql查询报错标识符无效只是其中的一种,后续遇到其他会继续修改博客,也欢迎大家遇到的情况在评论区提出,一起讨论!!

最新回复(0)