在做一个查询时,出现”Ora-01791 不是Selected表达式“,记录下来以作记念
select distinct button.BT_CODE,
button.MI_CODE,
button.BT_STRUCTURECODE,
button.BT_NAME,
button.BT_VALUE,
button.BT_LABELCODE,
button.BT_TYPE,
button.BT_CLASS,
button.BT_ONCLICK,
button.BT_STATUS
from T_AC_USERROLE ur,
T_AC_ROLEMENUITEM rm,
T_AC_ROLE role,
T_AC_MENUITEM menu,
T_AC_BUTTON button
where role.RL_CODE = ur.RL_CODE
and role.RL_CODE = rm.RL_CODE
and menu.MI_CODE = rm.MI_CODE
and button.BT_CODE = rm.BT_CODE
and button.MI_CODE = menu.MI_CODE
and button.BT_CODE != '0'
and ur.UT_CODE = 'OP'
and ur.USR_CODE = 18
order by menu.MI_STRUCTURECODE
上面的查询语句报Ora-01791 不是Selected错误
原因是在做distinct 时,order by 的字段不要查询结果中,就是说menu.MI_STRUCTURECODE必须出要在select后面。
解决办法,变为order by button.BT_CODE 变可以了。