在C#中使用ExecuteStoreQuery方法执行SQL查询时出现ORA-00933错误。
以下是代码:
public IEnumerable<Administrator> FilterEmployees(string name)
{
Context db = new Context();
string query = "SELECT USER_ROLES.USER_ROLES_ID, EMPLOYEES.EMPLOYEE_ID, EMPLOYEES.EMPLOYEE_NAME, EMPLOYEES.SURNAME_1, EMPLOYEES.SURNAME_2, ROLES.NAME FROM USER_ROLES" +
"INNER JOIN EMPLOYEES ON USER_ROLES.USER_ID = EMPLOYEES.EMPLOYEE_ID" +
"INNER JOIN ROLES ON USER_ROLES.ROLE_ID = ROLES.ROLE_ID" +
"WHERE ROLES.IS_INTRANET_ONLY = 'N' AND EMPLOYEES.FULL_EMPLOYEE_NAME LIKE '%Yuriy%'";
List<Administrator> employees;
return db.ExecuteStoreQuery<Administrator>(query, "employees", System.Data.Objects.MergeOption.AppendOnly);
}
查询很好(在Oracle SQL Developer上测试)
答案 0 :(得分:4)
您重新连接字符串,并且在一个字符串的最后一个字和下一个字符串的开头之间没有空格。导致执行此查询:(格式化我的)
SELECT
USER_ROLES.USER_ROLES_ID,
EMPLOYEES.EMPLOYEE_ID,
EMPLOYEES.EMPLOYEE_NAME,
EMPLOYEES.SURNAME_1,
EMPLOYEES.SURNAME_2,
ROLES.NAME FROM USER_ROLESINNER JOIN EMPLOYEES ON USER_ROLES.USER_ID = EMPLOYEES.EMPLOYEE_IDINNER JOIN ROLES ON USER_ROLES.ROLE_ID = ROLES.ROLE_IDWHERE ROLES.IS_INTRANET_ONLY = 'N' AND EMPLOYEES.FULL_EMPLOYEE_NAME LIKE '%Yuriy%'
^ Problem is here ^and here ^and here
在每个字符串的末尾添加一个空格。
答案 1 :(得分:0)
查询不正确 -
在内联编写此类查询时,您必须确保关键字之间应该有正确的空格 -
您应该调试代码并查看查询变量返回
我认为您应该按如下方式修改您的查询(通过在每行的末尾添加空格)
string query = "SELECT USER_ROLES.USER_ROLES_ID, EMPLOYEES.EMPLOYEE_ID, EMPLOYEES.EMPLOYEE_NAME, EMPLOYEES.SURNAME_1, EMPLOYEES.SURNAME_2, ROLES.NAME FROM USER_ROLES " +
"INNER JOIN EMPLOYEES ON USER_ROLES.USER_ID = EMPLOYEES.EMPLOYEE_ID " +
"INNER JOIN ROLES ON USER_ROLES.ROLE_ID = ROLES.ROLE_ID " +
"WHERE ROLES.IS_INTRANET_ONLY = 'N' AND EMPLOYEES.FULL_EMPLOYEE_NAME LIKE '%Yuriy%'";